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

Exponent should be drawn on target qubit in CX and CCX gates #4462

Merged
merged 3 commits into from Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cirq-core/cirq/ops/common_gates.py
Expand Up @@ -1271,7 +1271,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]:
Expand Down
14 changes: 8 additions & 6 deletions cirq-core/cirq/ops/common_gates_test.py
Expand Up @@ -720,6 +720,8 @@ def test_text_diagrams():
cirq.CZ(a, b),
cirq.CNOT(a, b),
cirq.CNOT(b, a),
(cirq.CNOT ** 0.5)(a, b),
(cirq.CNOT ** 0.5)(b, a),
tanujkhattar marked this conversation as resolved.
Show resolved Hide resolved
cirq.H(a) ** 0.5,
cirq.I(a),
cirq.IdentityGate(2)(a, b),
Expand All @@ -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,
)
Expand Down
4 changes: 3 additions & 1 deletion cirq-core/cirq/ops/three_qubit_gates.py
Expand Up @@ -394,7 +394,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:
Expand Down
29 changes: 15 additions & 14 deletions cirq-core/cirq/ops/three_qubit_gates_test.py
Expand Up @@ -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,
Expand All @@ -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,
)
Expand Down