diff --git a/cirq-core/cirq/ops/common_gates.py b/cirq-core/cirq/ops/common_gates.py index b42b0de42d1..d6e50418c70 100644 --- a/cirq-core/cirq/ops/common_gates.py +++ b/cirq-core/cirq/ops/common_gates.py @@ -1275,7 +1275,7 @@ def _circuit_diagram_info_( self, args: 'cirq.CircuitDiagramInfoArgs' ) -> 'cirq.CircuitDiagramInfo': return protocols.CircuitDiagramInfo( - wire_symbols=('@', 'X'), exponent=self._diagram_exponent(args) + wire_symbols=('@', 'X'), exponent=self._diagram_exponent(args), exponent_qubit_index=1 ) def _apply_unitary_(self, args: 'protocols.ApplyUnitaryArgs') -> Optional[np.ndarray]: diff --git a/cirq-core/cirq/ops/common_gates_test.py b/cirq-core/cirq/ops/common_gates_test.py index a3475474028..2e64e0d2940 100644 --- a/cirq-core/cirq/ops/common_gates_test.py +++ b/cirq-core/cirq/ops/common_gates_test.py @@ -720,6 +720,8 @@ def test_text_diagrams(): cirq.CZ(a, b), cirq.CNOT(a, b), cirq.CNOT(b, a), + cirq.CNOT(a, b) ** 0.5, + cirq.CNOT(b, a) ** 0.5, cirq.H(a) ** 0.5, cirq.I(a), cirq.IdentityGate(2)(a, b), @@ -729,18 +731,18 @@ def test_text_diagrams(): cirq.testing.assert_has_diagram( circuit, """ -a: ───X───Y───Z───Z^x───Rx(x)───@───@───X───H^0.5───I───I───@───── - │ │ │ │ │ -b: ─────────────────────────────@───X───@───────────────I───@^t─── +a: ───X───Y───Z───Z^x───Rx(x)───@───@───X───@───────X^0.5───H^0.5───I───I───@───── + │ │ │ │ │ │ │ +b: ─────────────────────────────@───X───@───X^0.5───@───────────────────I───@^t─── """, ) cirq.testing.assert_has_diagram( circuit, """ -a: ---X---Y---Z---Z^x---Rx(x)---@---@---X---H^0.5---I---I---@----- - | | | | | -b: -----------------------------@---X---@---------------I---@^t--- +a: ---X---Y---Z---Z^x---Rx(x)---@---@---X---@-------X^0.5---H^0.5---I---I---@----- + | | | | | | | +b: -----------------------------@---X---@---X^0.5---@-------------------I---@^t--- """, use_unicode_characters=False, ) diff --git a/cirq-core/cirq/ops/three_qubit_gates.py b/cirq-core/cirq/ops/three_qubit_gates.py index 72f0c48b48c..12793a636e8 100644 --- a/cirq-core/cirq/ops/three_qubit_gates.py +++ b/cirq-core/cirq/ops/three_qubit_gates.py @@ -397,7 +397,9 @@ def _decompose_(self, qubits): def _circuit_diagram_info_( self, args: 'cirq.CircuitDiagramInfoArgs' ) -> 'cirq.CircuitDiagramInfo': - return protocols.CircuitDiagramInfo(('@', '@', 'X'), exponent=self._diagram_exponent(args)) + return protocols.CircuitDiagramInfo( + ('@', '@', 'X'), exponent=self._diagram_exponent(args), exponent_qubit_index=2 + ) def _qasm_(self, args: 'cirq.QasmArgs', qubits: Tuple['cirq.Qid', ...]) -> Optional[str]: if self._exponent != 1: diff --git a/cirq-core/cirq/ops/three_qubit_gates_test.py b/cirq-core/cirq/ops/three_qubit_gates_test.py index 6e92c54bf35..748bc9d301b 100644 --- a/cirq-core/cirq/ops/three_qubit_gates_test.py +++ b/cirq-core/cirq/ops/three_qubit_gates_test.py @@ -234,6 +234,7 @@ def test_diagram(): circuit = cirq.Circuit( cirq.TOFFOLI(a, b, c), cirq.TOFFOLI(a, b, c) ** 0.5, + cirq.TOFFOLI(c, b, a) ** 0.5, cirq.CCX(a, c, b), cirq.CCZ(a, d, b), cirq.CCZ(a, d, b) ** 0.5, @@ -243,25 +244,25 @@ def test_diagram(): cirq.testing.assert_has_diagram( circuit, """ -0: ───@───@───────@───@───@───────@───@─── - │ │ │ │ │ │ │ -1: ───@───@───────X───@───@───────┼───×─── - │ │ │ │ │ │ │ -2: ───X───X^0.5───@───┼───┼───────×───×─── - │ │ │ -3: ───────────────────@───@^0.5───×─────── +0: ───@───@───────X^0.5───@───@───@───────@───@─── + │ │ │ │ │ │ │ │ +1: ───@───@───────@───────X───@───@───────┼───×─── + │ │ │ │ │ │ │ │ +2: ───X───X^0.5───@───────@───┼───┼───────×───×─── + │ │ │ +3: ───────────────────────────@───@^0.5───×─────── """, ) cirq.testing.assert_has_diagram( circuit, """ -0: ---@---@-------@---@---@-------@------@------ - | | | | | | | -1: ---@---@-------X---@---@-------|------swap--- - | | | | | | | -2: ---X---X^0.5---@---|---|-------swap---swap--- - | | | -3: -------------------@---@^0.5---swap---------- +0: ---@---@-------X^0.5---@---@---@-------@------@------ + | | | | | | | | +1: ---@---@-------@-------X---@---@-------|------swap--- + | | | | | | | | +2: ---X---X^0.5---@-------@---|---|-------swap---swap--- + | | | +3: ---------------------------@---@^0.5---swap---------- """, use_unicode_characters=False, )