Skip to content

Commit e283ae1

Browse files
authored
Replace cirq.ops.op_tree.OpTree with cirq.OP_TREE (#1724)
- Replace `cirq.ops.op_tree.OpTree` with `cirq.OP_TREE` - Fix flagged coefficient type for GlobalPhase Towards #1708
1 parent 1fdee48 commit e283ae1

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

qualtran/bloqs/mcmt/and_bloq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def _decompose_via_tree(
312312
control_values: Tuple[SymbolicInt, ...],
313313
ancillas: NDArray[cirq.Qid],
314314
target: cirq.Qid,
315-
) -> cirq.ops.op_tree.OpTree:
315+
) -> Iterator[cirq.OP_TREE]:
316316
"""Decomposes multi-controlled `And` in-terms of an `And` ladder of size #controls- 2."""
317317

318318
if len(controls) == 2:

qualtran/bloqs/swap_network/cswap_approx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def decompose_from_registers(
7272
) -> Iterator[cirq.OP_TREE]:
7373
ctrl, target_x, target_y = quregs['ctrl'], quregs['x'], quregs['y']
7474

75-
def g(q: cirq.Qid, adjoint=False) -> cirq.ops.op_tree.OpTree:
75+
def g(q: cirq.Qid, adjoint=False) -> Iterator[cirq.OP_TREE]:
7676
yield [cirq.S(q), cirq.H(q)]
7777
yield cirq.T(q) ** (1 - 2 * adjoint)
7878
yield [cirq.H(q), cirq.S(q) ** -1]

qualtran/cirq_interop/_cirq_to_bloq.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
"""Cirq gates/circuits to Qualtran Bloqs conversion."""
1616
import abc
1717
import itertools
18-
import numbers
1918
import warnings
2019
from functools import cached_property
2120
from typing import Any, Dict, List, Optional, Sequence, Tuple, TYPE_CHECKING, TypeVar, Union
2221

2322
import cirq
2423
import numpy as np
24+
import sympy
2525
from attrs import field, frozen
2626
from numpy.typing import NDArray
2727

@@ -434,9 +434,9 @@ def cirq_gate_to_bloq(gate: cirq.Gate) -> Bloq:
434434
return CIRQ_TYPE_TO_BLOQ_MAP[gate.__class__](exponent=gate.exponent)
435435

436436
if isinstance(gate, cirq.GlobalPhaseGate):
437-
if isinstance(gate.coefficient, numbers.Complex):
438-
return GlobalPhase.from_coefficient(coefficient=complex(gate.coefficient))
439-
return GlobalPhase.from_coefficient(coefficient=gate.coefficient)
437+
if isinstance(gate.coefficient, sympy.Expr):
438+
return GlobalPhase.from_coefficient(coefficient=gate.coefficient)
439+
return GlobalPhase.from_coefficient(coefficient=complex(gate.coefficient))
440440

441441
# No known basic gate, wrap the cirq gate in a CirqGateAsBloq wrapper.
442442
return CirqGateAsBloq(gate)

0 commit comments

Comments
 (0)