Skip to content

Commit

Permalink
UtilBloq -> _BookkeepingBloq, improve docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
anurudhp committed May 16, 2024
1 parent 4a2f68e commit 542e72b
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions qualtran/bloqs/util_bloqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@
from qualtran.simulation.classical_sim import ClassicalValT


class UtilBloq(Bloq, metaclass=abc.ABCMeta):
"""Base class for util bloqs.
class _BookkeepingBloq(Bloq, metaclass=abc.ABCMeta):
"""Base class for utility bloqs used for bookkeeping.
1. Trivial controlled - pass through the control register.
2. Do not affect T complexity.
This bloq:
- has trivial controlled versions, which pass through the control register.
- does not affect T complexity.
"""

def get_ctrl_system(
Expand All @@ -74,7 +75,7 @@ def _t_complexity_(self) -> 'TComplexity':


@frozen
class Split(UtilBloq):
class Split(_BookkeepingBloq):
"""Split a bitsize `n` register into a length-`n` array-register.
Attributes:
Expand Down Expand Up @@ -133,7 +134,7 @@ def wire_symbol(self, reg: Optional[Register], idx: Tuple[int, ...] = tuple()) -


@frozen
class Join(UtilBloq):
class Join(_BookkeepingBloq):
"""Join a length-`n` array-register into one register of bitsize `n`.
Attributes:
Expand Down Expand Up @@ -192,7 +193,7 @@ def wire_symbol(self, reg: Optional[Register], idx: Tuple[int, ...] = tuple()) -


@frozen
class Partition(UtilBloq):
class Partition(_BookkeepingBloq):
"""Partition a generic index into multiple registers.
Args:
Expand Down Expand Up @@ -260,9 +261,7 @@ def add_my_tensors(

tn.add(
qtn.Tensor(
data=np.eye(2**self.n, 2**self.n).reshape(
tuple(unitary_shape) + (2**self.n,)
),
data=np.eye(2**self.n, 2**self.n).reshape(tuple(unitary_shape) + (2**self.n,)),
inds=soquets + [_incoming['x']],
tags=['Partition', tag],
)
Expand Down Expand Up @@ -315,7 +314,7 @@ def wire_symbol(self, reg: Register, idx: Tuple[int, ...] = tuple()) -> 'WireSym


@frozen
class Allocate(UtilBloq):
class Allocate(_BookkeepingBloq):
"""Allocate an `n` bit register.
Attributes:
Expand Down Expand Up @@ -356,7 +355,7 @@ def wire_symbol(self, reg: Register, idx: Tuple[int, ...] = tuple()) -> 'WireSym


@frozen
class Free(UtilBloq):
class Free(_BookkeepingBloq):
"""Free (i.e. de-allocate) an `n` bit register.
The tensor decomposition assumes the `n` bit register is uncomputed and is in the $|0^{n}>$
Expand Down Expand Up @@ -426,7 +425,7 @@ def _t_complexity_(self) -> 'TComplexity':


@frozen
class Cast(UtilBloq):
class Cast(_BookkeepingBloq):
"""Cast a register from one n-bit QDType to another QDType.
Expand Down

0 comments on commit 542e72b

Please sign in to comment.