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

Removed 2pi wrapping for global phase parameter #10631

Merged
merged 9 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions qiskit/transpiler/passes/scheduling/dynamical_decoupling.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def run(self, dag):
if gate is not None:
new_dag.apply_operation_back(gate, [dag_qubit], check=False)

new_dag.global_phase = _mod_2pi(new_dag.global_phase + sequence_gphase)
jakelishman marked this conversation as resolved.
Show resolved Hide resolved
new_dag.global_phase = new_dag.global_phase + sequence_gphase

return new_dag

Expand All @@ -283,11 +283,3 @@ def __gate_supported(self, gate: Gate, qarg: int) -> bool:
if self._target is None or self._target.instruction_supported(gate.name, qargs=(qarg,)):
return True
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
Expand Up @@ -394,8 +394,7 @@ def _constrained_length(values):
gate_length = self._dd_sequence_lengths[qubit][dd_ind]
self._apply_scheduled_op(dag, idle_after, gate, qubit)
idle_after += gate_length

dag.global_phase = self._mod_2pi(dag.global_phase + sequence_gphase)
dag.global_phase = dag.global_phase + sequence_gphase

@staticmethod
def _resolve_params(gate: Gate) -> tuple:
Expand All @@ -407,11 +406,3 @@ def _resolve_params(gate: Gate) -> tuple:
else:
params.append(p)
return tuple(params)

@staticmethod
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,7 @@
---
fixes:
- |
Fixed compatibility of :class:`.DynamicalDecoupling` and
:class:`.PadDynamicalDecoupling` with circuits that have a parameterized
global phase.
Fixed `#10569 <https://github.com/Qiskit/qiskit-terra/issues/10569>`__.
19 changes: 19 additions & 0 deletions test/python/transpiler/test_dynamical_decoupling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,25 @@ def test_respect_target_instruction_constraints(self):
expected.delay(200, [0])
self.assertEqual(expected, scheduled)

def test_paramaterized_global_phase(self):
"""Test paramaterized global phase in DD circuit.
See:https://github.com/Qiskit/qiskit-terra/issues/10569
"""
dd_sequence = [XGate(), YGate()] * 2
qc = QuantumCircuit(1, 1)
qc.h(0)
qc.delay(1700, 0)
qc.y(0)
qc.global_phase = Parameter("a")
pm = PassManager(
[
ALAPScheduleAnalysis(self.durations),
PadDynamicalDecoupling(self.durations, dd_sequence),
]
)

self.assertEqual(qc.global_phase + np.pi, pm.run(qc).global_phase)


if __name__ == "__main__":
unittest.main()