Skip to content

Commit a9776d0

Browse files
authored
Nicer string representation for InverseCompositeGate (#6262)
Change `cirq.inverse(g)` string representation to `g.__str__()†` instead of `(g.__repr__() ** -1)`.
1 parent 2cfdf1f commit a9776d0

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

cirq-core/cirq/ops/raw_types.py

+3
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,9 @@ def _circuit_diagram_info_(self, args: 'cirq.CircuitDiagramInfoArgs'):
10321032
def __repr__(self) -> str:
10331033
return f'({self._original!r}**-1)'
10341034

1035+
def __str__(self) -> str:
1036+
return f'{self._original!s}†'
1037+
10351038

10361039
def _validate_qid_shape(val: Any, qubits: Sequence['cirq.Qid']) -> None:
10371040
"""Helper function to validate qubits for gates and operations.

cirq-core/cirq/ops/raw_types_test.py

+1
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ def __repr__(self):
759759
assert cirq.parameter_names(g) == {'a'}
760760
assert cirq.resolve_parameters(g, {a: 0}) == Gate(0) ** -1
761761
cirq.testing.assert_implements_consistent_protocols(g, global_vals={'C': Gate, 'a': a})
762+
assert str(g) == 'C(a)†'
762763

763764

764765
def test_tagged_act_on():

0 commit comments

Comments
 (0)