Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust-space TwoQubitBasisDecomposer fails if KAK gate is not Rust-space standard #12998

Closed
jakelishman opened this issue Aug 20, 2024 · 0 comments · Fixed by #13014
Closed

Rust-space TwoQubitBasisDecomposer fails if KAK gate is not Rust-space standard #12998

jakelishman opened this issue Aug 20, 2024 · 0 comments · Fixed by #13014
Labels
bug Something isn't working mod: transpiler Issues and PRs related to Transpiler Rust This PR or issue is related to Rust code in the repository
Milestone

Comments

@jakelishman
Copy link
Member

Environment

  • Qiskit version: 1.2.0
  • Python version: 3.10
  • Operating system: macOS

What is happening?

Since moving to Rust space, the TwoQubitBasisDecomposer has encoded an assumption that the given KAK gate is a Rust-space StandardGate. This is true in most uses within Qiskit, but not necessarily user-defined targets.

How can we reproduce the issue?

from qiskit.circuit import library as std
from qiskit.synthesis import TwoQubitBasisDecomposer

# note that `CXGate(ctrl_state=0)` is not handled as a "standard" gate.
TwoQubitBasisDecomposer(std.CXGate(ctrl_state=0))(std.CXGate())
thread '<unnamed>' panicked at /Users/runner/work/qiskit/qiskit/crates/circuit/src/packed_instruction.rs:168:14:
the caller is responsible for knowing the correct type
stack backtrace:

[ ... snip ... ]
  10:        0x10f2b719a - core::option::expect_failed::ha3671a0dd3229d4c
  11:        0x10f1570ba - qiskit_accelerate::two_qubit_decompose::TwoQubitBasisDecomposer::__pymethod_to_circuit__::h78b6cbefd6ac2cc6
  12:        0x10f0c6488 - pyo3::impl_::trampoline::trampoline::hb8b7fc9b34400178
  13:        0x10f137668 - qiskit_accelerate::two_qubit_decompose::<impl pyo3::impl_::pyclass::PyMethods<qiskit_accelerate::two_qubit_decompose::TwoQubitBasisDecomposer> for pyo3::impl_::pyclass::PyClassImplCollector<qiskit_accelerate::two_qubit_decompose::TwoQubitBasisDecomposer>>::py_methods::ITEMS::trampoline::h3e5e5843f2694fc9
[ ... snip ...]
---------------------------------------------------------------------------
PanicException                            Traceback (most recent call last)
Cell In[1], line 4
      1 from qiskit.circuit import library as std
      2 from qiskit.synthesis import TwoQubitBasisDecomposer
----> 4 TwoQubitBasisDecomposer(std.CXGate(ctrl_state=0))(std.CXGate())

File ~/code/qiskit/venv310-other/lib/python3.10/site-packages/qiskit/synthesis/two_qubit/two_qubit_decompose.py:667, in TwoQubitBasisDecomposer.__call__(self, unitary, basis_fidelity, approximate, use_dag, _num_basis_uses)
    665 else:
    666     if getattr(self.gate, "_standard_gate", None):
--> 667         circ_data = self._inner_decomposer.to_circuit(
    668             np.asarray(unitary, dtype=complex),
    669             self.gate,
    670             basis_fidelity,
    671             approximate,
    672             _num_basis_uses=_num_basis_uses,
    673         )
    674         return QuantumCircuit._from_circuit_data(circ_data)
    675     else:

PanicException: the caller is responsible for knowing the correct type

What should happen?

We should be able to output the circuit in that case.

Any suggestions?

The decomposition is actually internally successful, the problem is just the assumption that after let kak_gate = kak_gate.extract::<OperationFromPython>()?;, then kak_gate.operation internally stores a StandardGate.

We should actually check whether that's the case, and if not, avoid using the CircuitData::from_standard_gates fast-path constructor an instead use a general-purpose one.

@jakelishman jakelishman added bug Something isn't working Rust This PR or issue is related to Rust code in the repository mod: transpiler Issues and PRs related to Transpiler labels Aug 20, 2024
@jakelishman jakelishman added this to the 1.2.1 milestone Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mod: transpiler Issues and PRs related to Transpiler Rust This PR or issue is related to Rust code in the repository
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant