From 1b8e4390cbeafcd8690972fa6235bae6e63e1384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Rist=C3=A8?= <10402430+dieris@users.noreply.github.com> Date: Tue, 1 Aug 2023 10:40:10 -0400 Subject: [PATCH 1/4] Don't wrap parameterized global phase --- .../transpiler/passes/scheduling/dynamical_decoupling.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/qiskit_ibm_provider/transpiler/passes/scheduling/dynamical_decoupling.py b/qiskit_ibm_provider/transpiler/passes/scheduling/dynamical_decoupling.py index 51ebc76fe..fb1f35d58 100644 --- a/qiskit_ibm_provider/transpiler/passes/scheduling/dynamical_decoupling.py +++ b/qiskit_ibm_provider/transpiler/passes/scheduling/dynamical_decoupling.py @@ -28,6 +28,7 @@ from qiskit.transpiler.instruction_durations import InstructionDurations from qiskit.transpiler.passes.optimization import Optimize1qGates from qiskit.transpiler import CouplingMap +from qiskit.circuit.parameterexpression import ParameterExpression from .block_base_padder import BlockBasePadder @@ -555,9 +556,13 @@ def _constrained_length(values: np.array) -> np.array: idle_after += gate_length dd_ind += 1 - self._block_dag.global_phase = self._mod_2pi( + self._block_dag.global_phase = ( self._block_dag.global_phase + sequence_gphase ) + if not isinstance(self._block_dag.global_phase, ParameterExpression): + self._block_dag.global_phase = self._mod_2pi( + self.block_dag._global_phase + ) return # DD could not be applied, delay instead From b6a96c17526fbc6fd3a2616a3c0ae1a759d7ba20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Rist=C3=A8?= <10402430+dieris@users.noreply.github.com> Date: Tue, 1 Aug 2023 11:45:56 -0400 Subject: [PATCH 2/4] Just use dag_circuit.global_phase setter Already wrapping phase --- .../passes/scheduling/dynamical_decoupling.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/qiskit_ibm_provider/transpiler/passes/scheduling/dynamical_decoupling.py b/qiskit_ibm_provider/transpiler/passes/scheduling/dynamical_decoupling.py index fb1f35d58..3dfc5db2e 100644 --- a/qiskit_ibm_provider/transpiler/passes/scheduling/dynamical_decoupling.py +++ b/qiskit_ibm_provider/transpiler/passes/scheduling/dynamical_decoupling.py @@ -28,7 +28,6 @@ from qiskit.transpiler.instruction_durations import InstructionDurations from qiskit.transpiler.passes.optimization import Optimize1qGates from qiskit.transpiler import CouplingMap -from qiskit.circuit.parameterexpression import ParameterExpression from .block_base_padder import BlockBasePadder @@ -559,22 +558,10 @@ def _constrained_length(values: np.array) -> np.array: self._block_dag.global_phase = ( self._block_dag.global_phase + sequence_gphase ) - if not isinstance(self._block_dag.global_phase, ParameterExpression): - self._block_dag.global_phase = self._mod_2pi( - self.block_dag._global_phase - ) return # DD could not be applied, delay instead self._apply_scheduled_op( block_idx, t_start, Delay(time_interval, self._block_dag.unit), qubit ) - return - - @staticmethod - def _mod_2pi(angle: float, atol: float = 0) -> float: - """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 + return \ No newline at end of file From 4c8ac304f75561eb5c2694a156aea18596e0f80e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Rist=C3=A8?= <10402430+dieris@users.noreply.github.com> Date: Tue, 1 Aug 2023 12:00:36 -0400 Subject: [PATCH 3/4] Release note --- .../notes/fix-param-global-phase-d81185e19cb2763d.yaml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 releasenotes/notes/fix-param-global-phase-d81185e19cb2763d.yaml diff --git a/releasenotes/notes/fix-param-global-phase-d81185e19cb2763d.yaml b/releasenotes/notes/fix-param-global-phase-d81185e19cb2763d.yaml new file mode 100644 index 000000000..61065fb71 --- /dev/null +++ b/releasenotes/notes/fix-param-global-phase-d81185e19cb2763d.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + 2pi wrapping cannot be applied on a parameterized global phase. Use the DAGCircuit global_phase setter to wrap the phase for floats only. From 1c0c940e642805fa00ac843ca9cecfc0d0520407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Rist=C3=A8?= <10402430+dieris@users.noreply.github.com> Date: Tue, 1 Aug 2023 12:09:45 -0400 Subject: [PATCH 4/4] Restore final line --- .../transpiler/passes/scheduling/dynamical_decoupling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit_ibm_provider/transpiler/passes/scheduling/dynamical_decoupling.py b/qiskit_ibm_provider/transpiler/passes/scheduling/dynamical_decoupling.py index 3dfc5db2e..88463d982 100644 --- a/qiskit_ibm_provider/transpiler/passes/scheduling/dynamical_decoupling.py +++ b/qiskit_ibm_provider/transpiler/passes/scheduling/dynamical_decoupling.py @@ -564,4 +564,4 @@ def _constrained_length(values: np.array) -> np.array: self._apply_scheduled_op( block_idx, t_start, Delay(time_interval, self._block_dag.unit), qubit ) - return \ No newline at end of file + return