From 76989f78499e37e08a4755a130364cbea0b935f9 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Jaskula Date: Tue, 21 Nov 2023 00:09:51 +0100 Subject: [PATCH] simplify ctrl-gphase transform --- src/braket/circuits/gates.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/braket/circuits/gates.py b/src/braket/circuits/gates.py index 151d96cfb..a11b67bf5 100644 --- a/src/braket/circuits/gates.py +++ b/src/braket/circuits/gates.py @@ -310,16 +310,12 @@ def gphase( X.x(control_qubits[-1]), ] - highest_control_qubit = max( - [qubit for qubit, state in zip(control_qubits, control_basis_state) if state] - ) - highest_control_qubit_index = control_qubits.index(highest_control_qubit) - - control_qubits.pop(highest_control_qubit_index) - control_basis_state.pop(highest_control_qubit_index) + rightmost_control_qubit_index = control_basis_state.index(1) + rightmost_control_qubit = control_qubits.pop(rightmost_control_qubit_index) + control_basis_state.pop(rightmost_control_qubit_index) return PhaseShift.phaseshift( - highest_control_qubit, + rightmost_control_qubit, angle, control=control_qubits, control_state=control_basis_state,