CirqGateAsBloqBase#
qualtran.cirq_interop.CirqGateAsBloqBase
View source on GitHub
|
A base class to bootstrap a bloq from a cirq.Gate.
Inherits From: Bloq
Bloq authors can inherit from this abstract class and override the cirq_gate property
to get a bloq adapted from the cirq gate. Authors can continue to customize the bloq
by overriding methods (like costs, string representations, …).
Otherwise, this class fulfils the Bloq API by delegating to cirq.Gate methods.
This is the base class that provides the functionality for the CirqGateAsBloq adapter.
The adapter lets you use any cirq.Gate as a bloq immediately (without defining a new class
that inherits from CirqGateAsBloqBase), and is used as a fallback in the interoperability
functionality.
Attributes
Methods#
decompose_bloq
decompose_bloq() -> 'CompositeBloq'
Decompose this Bloq into its constituent parts contained in a CompositeBloq.
Bloq users can call this function to delve into the definition of a Bloq. If you’re
trying to define a bloq’s decomposition, consider overriding build_composite_bloq
which provides helpful arguments for implementers.
Returns
Raises
NotImplementedErrorIf there is no decomposition defined; namely: if
build_composite_bloqreturnsNotImplemented.
decompose_from_registers
decompose_from_registers(
*, context: cirq.DecompositionContext, **quregs
) -> cirq.OP_TREE
my_tensors
my_tensors(
incoming: Dict[str, 'ConnectionT'], outgoing: Dict[str, 'ConnectionT']
) -> List['qtn.Tensor']
Override this method to support native quimb simulation of this Bloq.
This method is responsible for returning tensors corresponding to the unitary, state, or effect of the bloq. Often, this method will return one tensor for a given Bloq, but some bloqs can be represented in a factorized form using more than one tensor.
By default, calls to Bloq.tensor_contract() will first decompose and flatten the bloq
before initiating the conversion to a tensor network. This has two consequences:
Overriding this method is only necessary if this bloq does not define a decomposition or if the fully-decomposed form contains a bloq that does not define its tensors.
Even if you override this method to provide custom tensors, they may not be used (by default) because we prefer the flat-decomposed version. This is usually desirable for contraction performance; but for finer-grained control see
qualtran.simulation.tensor.cbloq_to_quimb.
Quimb defines a connection between two tensors by a shared index. The returned tensors from this method must use the Qualtran-Quimb index convention:
Each tensor index is a tuple
(cxn, j)The
cxn: qualtran.Connectionentry identifies the connection between bloq instances.The second integer
jis the bit index within high-bitsize registers, which is necessary due to technical restrictions.
Args
incomingA mapping from register name to Connection (or an array thereof) to use as left indices for the tensor network. The shape of the array matches the register’s shape.
outgoingA mapping from register name to Connection (or an array thereof) to use as right indices for the tensor network.
as_cirq_op
as_cirq_op(
qubit_manager: 'cirq.QubitManager', **in_quregs
) -> Tuple[Union['cirq.Operation', None], Dict[str, 'CirqQuregT']]
Override this method to support conversion to a Cirq operation.
If this method is not overriden, the default implementation will wrap this bloq
in a BloqAsCirqGate shim.
Args
qubit_managerA
cirq.QubitManagerfor allocatingcirq.Qids.**cirq_quregskwargs mapping from this bloq’s left register names to an ndarray of
cirq.Qid. The final dimension of this array corresponds to the registersbitsizesize. Any additional dimensions come first and correspond to the registershapesizes.
Returns
opA cirq operation corresponding to this bloq acting on the provided cirq qubits or None. This method should return None if and only if the bloq instance truly should not be included in the Cirq circuit (e.g. for reshaping bloqs). A bloq with no cirq equivalent should raise an exception instead.
cirq_quregsA mapping from this bloq’s right register of the same format as the
cirq_quregsargument. The returned dictionary corresponds to the output qubits.
__pow__
__pow__(
power
)
adjoint
adjoint() -> 'Bloq'
The adjoint of this bloq.
Bloq authors can override this method in certain circumstances. Otherwise, the default
fallback wraps this bloq in Adjoint.
Please see the documentation for Adjoint and the Adjoint.ipynb notebook for full
details.
View source on GitHub