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

Removing 2pi wrapping for global phase parameter #10630

Closed
wants to merge 8 commits into from
4 changes: 4 additions & 0 deletions qiskit/qpy/binary_io/circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@ def _read_instruction(file_obj, circuit, registers, custom_operations, version,
"UCRXGate",
"UCRYGate",
"UCRZGate",
<<<<<<< HEAD
"diagonal",
=======
"DiagonalGate",
>>>>>>> 982807e5bc8d7b0b7fa130b4cb2b09064b4224d4
}:
gate = gate_class(params)
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def run(self, dag):
if gate is not None:
new_dag.apply_operation_back(gate, [dag_qubit])

new_dag.global_phase = _mod_2pi(new_dag.global_phase + sequence_gphase)
new_dag.global_phase = new_dag.global_phase + sequence_gphase

return new_dag

Expand All @@ -268,9 +268,3 @@ def __gate_supported(self, gate: Gate, qarg: int) -> bool:
return False


def _mod_2pi(angle: float, atol: float = 0):
"""Wrap angle into interval [-π,π). If within atol of the endpoint, clamp to -π"""
wrapped = (angle + np.pi) % (2 * np.pi) - np.pi
if abs(wrapped - np.pi) < atol:
wrapped = -np.pi
return wrapped
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Fixes initiation of ``DiagonalGate``. Refer to
`#10364 <https://github.com/Qiskit/qiskit-terra/issues/10364>` for more
details.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
fixes:
- |
2pi wrapping cannot be applied on a parameterized global phase.Use the
DAGCircuit global_phase setter to wrap the phase for floats only.Refer to
`#10569 <https://github.com/Qiskit/qiskit-terra/issues/10569>` for more
details.
8 changes: 8 additions & 0 deletions test/qpy_compat/test_qpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,13 @@ def generate_open_controlled_gates():
return circuits


<<<<<<< HEAD
def generate_diagonal_gate_circuit():
"""Generate diagonal gate circuit."""
diagonal_circuit = QuantumCircuit(2, name="diagonal_circuit")
diagonal_circuit.diagonal([1, -1, -1, 1], [0, 1])
return diagonal_circuit
=======
def generate_acquire_instruction_with_kernel_and_discriminator():
"""Test QPY serialization with Acquire instruction with kernel and discriminator."""
from qiskit.pulse import builder, AcquireChannel, MemorySlot, Discriminator, Kernel
Expand Down Expand Up @@ -707,6 +714,7 @@ def generate_control_flow_expr():
qc4.rz(np.pi, 0)

return [qc1, qc2, qc3, qc4]
>>>>>>> 982807e5bc8d7b0b7fa130b4cb2b09064b4224d4


def generate_circuits(version_parts):
Expand Down