question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problems with global phase

See original GitHub issue

Information

  • Qiskit Terra version: 0.18.3
  • Python version: Any
  • Operating system: Any

What is the current behavior?

If the Optimize1qGatesDecomposition optimization pass is applied to the sequence

qc = QuantumCircuit(1)
qc.x(0)
qc.p(np.pi/2, 0)

a global phase is introduced in the circuit. The old Optimize1qGates optimization pass does not introduce such a global phase. Is this intended? If not, then the following problem might rather be a separate issue.

Upon dumping a QASM representation of the circuit via qc.qasm() the information about the global phase is lost. This means once the resulting file is used to create a circuit via QuantumCircuit.from_qasm_str(qasm_str), both circuits are no longer functionally equivalent, but differ by the global phase.

Steps to reproduce the problem

from qiskit import QuantumCircuit, Aer, execute
from qiskit.transpiler import PassManager
from qiskit.transpiler.passes.optimization import Optimize1qGatesDecomposition, Optimize1qGates

backend = Aer.get_backend('aer_simulator')

qc = QuantumCircuit(1)
qc.x(0)
qc.p(np.pi/2, 0)

qc_opt = PassManager(Optimize1qGatesDecomposition(basis=['u1', 'u2', 'u3', 'cx'])).run(qc)
qasm_str = qc_opt.qasm()
print('Optimize1qGatesDecomposition global phase: ', qc_opt.global_phase)

qc_opt2 = PassManager(Optimize1qGates(basis=['u1', 'u2', 'u3', 'cx'])).run(qc)
qasm_str2 = qc_opt2.qasm()
print('Optimize1qGates global phase: ', qc_opt2.global_phase)

qc.save_unitary()
unitary = execute(qc, backend).result().get_unitary(qc)

qc_opt.save_unitary()
unitary_opt = execute(qc_opt, backend).result().get_unitary(qc_opt)

qc_qasm = QuantumCircuit.from_qasm_str(qasm_str)
qc_qasm.save_unitary()
unitary_qasm = execute(qc_qasm, backend).result().get_unitary(qc_qasm)

qc_qasm2 = QuantumCircuit.from_qasm_str(qasm_str2)
qc_qasm2.save_unitary()
unitary_qasm2 = execute(qc_qasm2, backend).result().get_unitary(qc_qasm2)

print(unitary == unitary_opt)
print(unitary == unitary_qasm)
print(unitary == unitary_qasm2)

yields

Optimize1qGatesDecomposition global phase:  5.497787143782138
Optimize1qGates global phase:  0
[[ True  True]
 [ True  True]]
[[False False]
 [False False]]
[[ True  True]
 [ True  True]]

What is the expected behavior?

For once, I would have not expected the optimization pass to introduce a global phase. In addition, dumping the circuit to QASM should not alter the circuit’s functionality.

Suggested solutions

Potentially fix the global phase issue in the Optimize1qGatesDecomposition optimization pass. Factor in global phase in QASM dump.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
mtreinishcommented, Oct 20, 2021

I will add on to @jakelishman’s response here that if you need a lossless serialization format for your circuit for just usage with Qiskit, qpy is a good option: https://qiskit.org/documentation/apidoc/qpy.html

1reaction
levbishopcommented, Oct 20, 2021

I think it would be a useful enhancement for qasm exporter, to optionally emit the global phase gate even in qasm 2 mode. It could be defined using the gate definition @burgholzer suggested above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiplying By A Global Phase Doesn't Make A Difference
Quantum Computation and Quantum InformationLecture 5.5: Multiplying By A Global Phase Doesn't Make A DifferenceCarnegie Mellon Course ...
Read more >
Quantum phase
We now can see why global phases arise, but can always be ignored. They manifest themselves from uniform shifts in energy that do...
Read more >
If global phase doesn't matter why is relative phase important?
In the square of the absolute value of the wavefunction, a global phase just gives you 1. But a relative phase matters, ...
Read more >
A simple proof that the global phase is real - PhilSci-Archive
It is a standard view in quantum mechanics that two wave functions that differ only in the global phase represent the same physical...
Read more >
Phase unwrapping* overview A) The problem and some ...
Global methods that attempt to unwrap all pixels simultaneously. •Local methods that solve along a path. Note that the correlation data allows some...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found