You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am encountering an error when trying to play around with the OpenQASM3 importer from Qiskit, and seems related to a syntax that is not updated with latest openqasm3 (1.0.0):
`from qiskit import QuantumCircuit
from qiskit.circuit import Parameter, Gate, ParameterVector
from qiskit.qasm3 import Exporter, loads
The export works correctly and yields: OPENQASM 3.0; input float[64] n; input float[64] _θ_3_0_; input float[64] _θ_3_1_; qubit[1] q; for _ in {1, 3, 5} { x q[0]; rx(_θ_3_1_*n) q[0]; my_gate(_θ_3_0_) q[0]; }
But it is when trying to import through loads this generated file that the parser seems not able to cope with the loop parameter defined in the for loop. In fact, when trying to add the extra parameter n as a loop parameter, the same error appears:
line 6:4 no viable alternative at input '_'
When n is set as the loop parameter it displays the same thing but with 'n' at the end.
My guess is that it is because the type of this loop variable is not parametrized a priori and therefore Qiskit exporter is not up to date (I have the latest version of openqasm3), but that could be wrong.
How can we reproduce the issue?
`from qiskit import QuantumCircuit
from qiskit.circuit import Parameter, Gate, ParameterVector
from qiskit.qasm3 import Exporter, loads
Environment
What is happening?
I am encountering an error when trying to play around with the OpenQASM3 importer from Qiskit, and seems related to a syntax that is not updated with latest openqasm3 (1.0.0):
`from qiskit import QuantumCircuit
from qiskit.circuit import Parameter, Gate, ParameterVector
from qiskit.qasm3 import Exporter, loads
qc = QuantumCircuit(1)
theta = Parameter("θ")
theta2 = Parameter("θ_2")
theta3 = ParameterVector("θ_3", 2)
n = Parameter("n")
gate = Gate("my_gate", 1, [theta3[0]])
with qc.for_loop([1, 3, 5]):
qc.x(0)
qc.rx(theta3[1]*n, 0)
qc.append(gate, [0])
Convert Qiskit circuit to OpenQASM3
exporter = Exporter(includes=(), basis_gates=("my_gate", "rx", "x"),
)
qasm3 = exporter.dumps(qc)
print(qasm3)
loads(qasm3)`
The export works correctly and yields:
OPENQASM 3.0; input float[64] n; input float[64] _θ_3_0_; input float[64] _θ_3_1_; qubit[1] q; for _ in {1, 3, 5} { x q[0]; rx(_θ_3_1_*n) q[0]; my_gate(_θ_3_0_) q[0]; }
But it is when trying to import through loads this generated file that the parser seems not able to cope with the loop parameter defined in the for loop. In fact, when trying to add the extra parameter n as a loop parameter, the same error appears:
line 6:4 no viable alternative at input '_'
When n is set as the loop parameter it displays the same thing but with 'n' at the end.
My guess is that it is because the type of this loop variable is not parametrized a priori and therefore Qiskit exporter is not up to date (I have the latest version of openqasm3), but that could be wrong.
How can we reproduce the issue?
`from qiskit import QuantumCircuit
from qiskit.circuit import Parameter, Gate, ParameterVector
from qiskit.qasm3 import Exporter, loads
qc = QuantumCircuit(1)
theta = Parameter("θ")
theta2 = Parameter("θ_2")
theta3 = ParameterVector("θ_3", 2)
n = Parameter("n")
gate = Gate("my_gate", 1, [theta3[0]])
with qc.for_loop([1, 3, 5]):
qc.x(0)
qc.rx(theta3[1]*n, 0)
qc.append(gate, [0])
Convert Qiskit circuit to OpenQASM3
exporter = Exporter(includes=(), basis_gates=("my_gate", "rx", "x"),
)
qasm3 = exporter.dumps(qc)
print(qasm3)
loads(qasm3)`
What should happen?
The exporter should either be conforming itself with latest OpenQASM3 AST syntax for the for loop, or the importer should be fixed somewhere.
Any suggestions?
No response
The text was updated successfully, but these errors were encountered: