-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Specific sequence of gate applications and QASM3 conversion results in "only length-1 arrays can be converted to Python scalars" #11558
Comments
On each of these issues, please can you try updating to the most recent version of Qiskit and seeing which of the problems persist? I don't know if any are fixed, but that's always the first diagnostic step. |
Sorry, I didn't notice I wasn't on the latest version there! I reran each on 0.45.1 and still encountered the same bugs. I'll edit my reports to this version. |
Thanks - it's good to know. This appears to be related to the The problem comes because The bug doesn't appear on For the time being, if OpenQASM 3 export is necessary for you, you might need to set some |
Here's a minimal reproducer that reproduces the complete bug directly on import numpy as np
import qiskit.qasm3
qc = qiskit.QuantumCircuit(1)
qc.unitary(np.eye(2), [0])
qiskit.qasm3.dumps(qc) |
I encountered this exact same bug, but I wasn't using transpilation. You already have the minimal repro case, but for the record I was trying to manually create the Hardy state
I can stick to OpenQASM 2 export for now, but is there a workaround for OpenQASM 3? |
The best workaround I can think of would be to tranpsile the circuit with no coupling map and a basis gates containing stuff in the Qiskit standard library - something like import qiskit.qasm3
from qiskit.circuit.library.standard_gates import get_standard_gate_name_mapping
basis_gates = list(get_standard_gate_name_mapping())
qiskit.qasm3.dumps(qiskit.transpile(qc, basis_gates=basis_gates, optimization_level=0)) It's not ideal, since you'll lose the structure of your circuit, and we're for sure interested in improving the exporter so a) it doesn't choke on gates it should be able to handle and b) it does this kind of gate decomposition automatically to match the header files it's exporting against better. That's on the roadmap, somewhat encompassed by #10737. Fwiw, OpenQASM 3 is mostly an interoperation language for Qiskit, and we can't generally round-trip our circuits losslessly through it. If you're looking for a way to persist circuits to files, you might want to look at |
Environment
What is happening?
I've tried to simplify my circuit as much as I can and this is what I've settled with. I have a circuit with 2 qubits. The circuit has a swap gate followed by a Y gate followed by at least 18 other gates (it doesn't seem to matter what type of gate? but I'm just using Z gates in the provided example) followed by a Y gate. Attempting to convert this circuit to Qasm3 results in the following error:
How can we reproduce the issue?
Run the following:
What should happen?
The circuit should execute normally without error.
Any suggestions?
No response
The text was updated successfully, but these errors were encountered: