Skip to content

Commit

Permalink
fix TComplexity for cirq.GlobalPhaseGate and `cirq.global_phase_ope…
Browse files Browse the repository at this point in the history
…ration`
  • Loading branch information
anurudhp committed Mar 28, 2024
1 parent 3b1a89b commit 95436a9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion qualtran/bloqs/basic_gates/su2_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def wire_symbol(self, soq: 'Soquet') -> 'WireSymbol':
)

def _t_complexity_(self) -> TComplexity:
return TComplexity(rotations=3, clifford=1)
return TComplexity(rotations=3)

def _is_parameterized_(self) -> bool:
return any(
Expand Down
5 changes: 5 additions & 0 deletions qualtran/cirq_interop/t_complexity_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ def _is_clifford_or_t(stc: Any, fail_quietly: bool) -> Optional[TComplexity]:
if not isinstance(stc, (cirq.Gate, cirq.Operation)):
return None

if isinstance(stc, cirq.GlobalPhaseGate) or (
isinstance(stc, cirq.Operation) and isinstance(stc.gate, cirq.GlobalPhaseGate)
):
return TComplexity()

if isinstance(stc, cirq.ClassicallyControlledOperation):
stc = stc.without_classical_controls()

Expand Down
5 changes: 5 additions & 0 deletions qualtran/cirq_interop/t_complexity_protocol_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ def test_gates():

assert t_complexity(cirq.FREDKIN) == TComplexity(t=7, clifford=14)

# Global phase
assert t_complexity(cirq.GlobalPhaseGate(1j)) == TComplexity()


def test_operations():
q = cirq.NamedQubit('q')
Expand All @@ -145,6 +148,8 @@ def test_operations():
op = gate.on_registers(**get_named_qubits(gate.signature))
assert t_complexity(op) == TComplexity(clifford=4)

assert t_complexity(cirq.global_phase_operation(1j)) == TComplexity()


def test_circuits():
q = cirq.NamedQubit('q')
Expand Down
12 changes: 11 additions & 1 deletion qualtran/resource_counting/t_counts_from_sigma_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Rx,
Ry,
Rz,
SU2RotationGate,
TGate,
Toffoli,
XPowGate,
Expand All @@ -33,7 +34,16 @@


def test_all_rotation_types():
assert set(_get_all_rotation_types()) == {CZPowGate, Rx, Ry, Rz, XPowGate, YPowGate, ZPowGate}
assert set(_get_all_rotation_types()) == {
CZPowGate,
Rx,
Ry,
Rz,
XPowGate,
YPowGate,
ZPowGate,
SU2RotationGate,
}


def test_t_counts_from_sigma():
Expand Down

0 comments on commit 95436a9

Please sign in to comment.