CirqGateAsBloqBase#

qualtran.cirq_interop.CirqGateAsBloqBase

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.

cirq_gate

The cirq.Gate to use as the source of truth.

signature

 

Methods#

decompose_bloq

View source

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

NotImplementedError

If there is no decomposition defined; namely: if build_composite_bloq returns NotImplemented.

decompose_from_registers

View source

my_tensors

View source

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:

  1. 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.

  2. 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.Connection entry identifies the connection between bloq instances.

  • The second integer j is the bit index within high-bitsize registers, which is necessary due to technical restrictions.

Args

incoming

A 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.

outgoing

A mapping from register name to Connection (or an array thereof) to use as right indices for the tensor network.

as_cirq_op

View source

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_manager

A cirq.QubitManager for allocating cirq.Qids.

**cirq_quregs

kwargs mapping from this bloq’s left register names to an ndarray of cirq.Qid. The final dimension of this array corresponds to the registers bitsize size. Any additional dimensions come first and correspond to the register shape sizes.

Returns

op

A 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_quregs

A mapping from this bloq’s right register of the same format as the cirq_quregs argument. The returned dictionary corresponds to the output qubits.

__pow__

View source

adjoint

View source

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.