Controlled#

qualtran.Controlled

A controlled version of subbloq.

Inherits From: GateWithRegisters, Bloq

This bloq represents a “total control” strategy of controlling subbloq: the decomposition of Controlled(b) uses the decomposition of b and controls each subbloq in that decomposition.

Users should likely not use this class directly. Prefer using bloq.controlled(ctrl_spec), which may return a natively-controlled Bloq or a more intelligent construction for complex control specs.

subbloq

The bloq we are controlling.

ctrl_spec

The specification for how to control the bloq.

ctrl_reg_names

The name of the control registers.

This is generated on-the-fly to avoid conflicts with existing register names. Users should not rely on the absolute value of this property staying constant.

ctrl_regs

 

ctrl_spec

The specification of how the subbloq is controlled.

signature

 

subbloq

The bloq being controlled.

Methods#

make_ctrl_system

View source

A factory method for creating both the Controlled and the adder function.

See Bloq.get_ctrl_system.

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. The function returns the decomposition of this Bloq represented as an explicit compute graph wrapped in a CompositeBloq object.

Bloq authors can specify the bloq’s decomposition by overriding any of the following two methods:

  • build_composite_bloq: Override this method to define a bloq-style decomposition using a BloqBuilder builder class to construct the CompositeBloq directly.

  • decompose_from_registers: Override this method to define a cirq-style decomposition by yielding cirq style operations applied on qubits.

Irrespective of the bloq author’s choice of backend to implement the decomposition, bloq users will be able to access both the bloq-style and Cirq-style interfaces. For example, users can call:

  • cirq.decompose_once(bloq.on_registers(**cirq_quregs)): This will yield a cirq.OPTREE. Bloqs will be wrapped in BloqAsCirqGate as needed.

  • bloq.decompose_bloq(): This will return a CompositeBloq. Cirq gates will be be wrapped in CirqGateAsBloq as needed.

Thus, GateWithRegisters class provides a convenient way of defining objects that can be used interchangeably with both Cirq and Bloq constructs.

Returns

Raises

DecomposeNotImplementedError

If there is no decomposition defined; namely if both:

  • build_composite_bloq raises a DecomposeNotImplementedError and

  • decompose_from_registers raises a DecomposeNotImplementedError.

build_composite_bloq

View source

Override this method to define a Bloq in terms of its constituent parts.

Bloq authors should override this method. If you already have an instance of a Bloq, consider calling decompose_bloq() which will set up the correct context for calling this function.

Args

bb

A BloqBuilder to append sub-Bloq to.

**soqs

The initial soquets corresponding to the inputs to the Bloq.

Returns

build_call_graph

View source

Override this method to build the bloq call graph.

This method must return a set of (bloq, n) tuples where bloq is called n times in the decomposition. This method defines one level of the call graph, specifically the edges from this bloq to its immediate children. To get the full graph, call Bloq.call_graph().

By default, this method will use self.decompose_bloq() to count the bloqs called in the decomposition. By overriding this method, you can provide explicit call counts. This is appropriate if: 1) you can’t or won’t provide a complete decomposition, 2) you know symbolic expressions for the counts, or 3) you need to “generalize” the subbloqs by overwriting bloq attributes that do not affect its cost with generic sympy symbols using the provided SympySymbolAllocator.

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.

num_qubits

The number of qubits this gate acts on.

__ne__

Check equality and either forward a NotImplemented or return the result negated.

__eq__

Method generated by attrs for class Controlled.