qiskit
qiskit copied to clipboard
QASM3 and global phase when using dumps() and loads()
OpenQASM3 does not seem to support global phase It looks like when performing a qasm3 dump() then load() of a U gate, the resulting circuit is loosing the global phase.
matrix = np.array([[0,1], [1,0]])
circuit = QuantumCircuit(1)
circuit.unitary(matrix, 0)
circuit_qasm3_str = dumps(circuit.decompose())
circuit3 = qiskit.qasm3.loads(circuit_qasm3_str)
print(circuit_qasm3_str)
print(circuit3.global_phase)
OPENQASM 3;
include "stdgates.inc";
qubit[1] q;
U(pi, -pi, 0) q[0];
0.0
If you manually add a gphase() , to the U instruction then we get the Global phase.
qasm3_string = '''
OPENQASM 3;
include "stdgates.inc";
qubit[1] q;
U(pi, -pi, 0) q; gphase(pi) ;
'''
circuit3 = qiskit.qasm3.loads(qasm3_string)
print(circuit_qasm3_str)
print(circuit3.global_phase)
OPENQASM 3;
include "stdgates.inc";
qubit[1] q;
U(pi, -pi, 0) q[0];
3.141592653589793
Thanks for this - looks like the immediate problem is in the OpenQASM 3 exporter not writing out a gphase statement, since the importer seems to be interpreting gphase correctly if it's present.