Skip to content

Commit

Permalink
rename _2 ->
Browse files Browse the repository at this point in the history
  • Loading branch information
mpharrigan committed Jun 19, 2024
1 parent 9b2475e commit 0bf245a
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions qualtran/_infra/controlled_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from qualtran.cirq_interop.testing import GateHelper
from qualtran.drawing import get_musical_score_data
from qualtran.drawing.musical_score import Circle, SoqData, TextBox
from qualtran.simulation.tensor import cbloq_to_quimb_2, get_right_and_left_inds
from qualtran.simulation.tensor import cbloq_to_quimb, get_right_and_left_inds

if TYPE_CHECKING:
from qualtran import SoquetT
Expand Down Expand Up @@ -371,7 +371,7 @@ def test_controlled_tensor_without_decompose():
cbloq = Controlled(bloq, ctrl_spec)
cgate = cirq.ControlledGate(cirq.CSWAP, control_values=ctrl_spec.to_cirq_cv())

tn = cbloq_to_quimb_2(cbloq.as_composite_bloq())
tn = cbloq_to_quimb(cbloq.as_composite_bloq())
# pylint: disable=unbalanced-tuple-unpacking
right, left = get_right_and_left_inds(tn, cbloq.signature)
# pylint: enable=unbalanced-tuple-unpacking
Expand Down
4 changes: 2 additions & 2 deletions qualtran/bloqs/bookkeeping/cast_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from qualtran.bloqs.bookkeeping import Cast
from qualtran.bloqs.bookkeeping.cast import _cast
from qualtran.bloqs.for_testing import TestCastToFrom
from qualtran.simulation.tensor import cbloq_to_quimb_2
from qualtran.simulation.tensor import cbloq_to_quimb


def test_cast(bloq_autotester):
Expand All @@ -26,7 +26,7 @@ def test_cast(bloq_autotester):

def test_cast_tensor_contraction():
bloq = TestCastToFrom()
tn = cbloq_to_quimb_2(bloq.as_composite_bloq().flatten())
tn = cbloq_to_quimb(bloq.as_composite_bloq().flatten())
assert tn.shape == (2,) * 4 * 4


Expand Down
4 changes: 2 additions & 2 deletions qualtran/bloqs/bookkeeping/partition_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from qualtran.bloqs.bookkeeping import Partition
from qualtran.bloqs.bookkeeping.partition import _partition
from qualtran.bloqs.for_testing import TestMultiRegister
from qualtran.simulation.tensor import bloq_to_dense, cbloq_to_quimb_2
from qualtran.simulation.tensor import bloq_to_dense, cbloq_to_quimb
from qualtran.testing import assert_valid_bloq_decomposition


Expand Down Expand Up @@ -66,7 +66,7 @@ def test_partition_wrapper():

def test_partition_wrapper_tensor_contract():
bloq = TestPartition(test_bloq=TestMultiRegister())
tn = cbloq_to_quimb_2(bloq.as_composite_bloq().flatten())
tn = cbloq_to_quimb(bloq.as_composite_bloq().flatten())
assert tn.shape == (2,) * (2 * int(np.log2(4096)))

tn = tn.rank_simplify()
Expand Down
2 changes: 1 addition & 1 deletion qualtran/simulation/tensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


from ._dense import bloq_to_dense, get_right_and_left_inds, quimb_to_dense
from ._quimb import cbloq_to_quimb_2, initialize_from_zero
from ._quimb import cbloq_to_quimb, initialize_from_zero
from ._tensor_data_manipulation import (
active_space_for_ctrl_spec,
eye_tensor_for_signature,
Expand Down
4 changes: 2 additions & 2 deletions qualtran/simulation/tensor/_dense.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from qualtran import Bloq, Connection, ConnectionT, LeftDangle, RightDangle, Signature, Soquet

from ._quimb import cbloq_to_quimb_2
from ._quimb import cbloq_to_quimb

if TYPE_CHECKING:
import quimb.tensor as qtn
Expand Down Expand Up @@ -143,5 +143,5 @@ def bloq_to_dense(bloq: Bloq) -> NDArray:
"""
logging.info("bloq_to_dense() on %s", bloq)
flat_cbloq = bloq.as_composite_bloq().flatten()
tn = cbloq_to_quimb_2(flat_cbloq)
tn = cbloq_to_quimb(flat_cbloq)
return quimb_to_dense(tn, bloq.signature)
11 changes: 10 additions & 1 deletion qualtran/simulation/tensor/_quimb.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@
logger = logging.getLogger(__name__)


def cbloq_to_quimb_2(cbloq: CompositeBloq) -> qtn.TensorNetwork:
def cbloq_to_quimb(cbloq: CompositeBloq) -> qtn.TensorNetwork:
"""Convert a composite bloq into a tensor network.
This function will call `Bloq.my_tensors` on each subbloq in the composite bloq to add
tensors to a quimb tensor network. This method has no default fallback, so you likely want to
call `bloq.as_composite_bloq().flatten()` to decompose-and-flatten all bloqs down to their
smallest form first. The small bloqs that result from a flattening 1) likely already have
their `my_tensors` method implemented; and 2) can enable a more efficient tensor contraction
path.
"""
tn = qtn.TensorNetwork([])

logging.info(
Expand Down
4 changes: 2 additions & 2 deletions qualtran/simulation/tensor/_quimb_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from qualtran import Bloq, BloqBuilder, Connection, ConnectionT, DanglingT, QAny, Signature
from qualtran.bloqs.bookkeeping import Join, Split
from qualtran.simulation.tensor import cbloq_to_quimb_2
from qualtran.simulation.tensor import cbloq_to_quimb


@frozen
Expand All @@ -47,7 +47,7 @@ def test_cbloq_to_quimb():
x = bb.add(TensorAdderSimple(), x=x)
cbloq = bb.finalize(x=x)

tn = cbloq_to_quimb_2(cbloq)
tn = cbloq_to_quimb(cbloq)
assert len(tn.tensors) == 4
for outer_ind in tn.outer_inds():
cxn, j = outer_ind
Expand Down

0 comments on commit 0bf245a

Please sign in to comment.