Controlled#
qualtran.Controlled
View source on GitHub
|
A controlled version of subbloq.
Inherits From: GateWithRegisters, Bloq
qualtran.Controlled(
subbloq, ctrl_spec
)
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.
Args
Attributes
ctrl_reg_namesThe 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_regsctrl_specThe specification of how the
subbloqis controlled.signaturesubbloqThe bloq being controlled.
Methods#
make_ctrl_system
@classmethodmake_ctrl_system( bloq: 'Bloq', ctrl_spec: 'CtrlSpec' ) -> Tuple['_ControlledBase', 'AddControlledT']
A factory method for creating both the Controlled and the adder function.
See Bloq.get_ctrl_system.
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. 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 aBloqBuilderbuilder class to construct theCompositeBloqdirectly.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 acirq.OPTREE. Bloqs will be wrapped inBloqAsCirqGateas needed.bloq.decompose_bloq(): This will return aCompositeBloq. Cirq gates will be be wrapped inCirqGateAsBloqas needed.
Thus, GateWithRegisters class provides a convenient way of defining objects that can be used
interchangeably with both Cirq and Bloq constructs.
Returns
Raises
DecomposeNotImplementedErrorIf there is no decomposition defined; namely if both:
build_composite_bloqraises aDecomposeNotImplementedErroranddecompose_from_registersraises aDecomposeNotImplementedError.
build_composite_bloq
build_composite_bloq(
bb: 'BloqBuilder', **initial_soqs
) -> Dict[str, 'SoquetT']
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
bbA
BloqBuilderto append sub-Bloq to.**soqsThe initial soquets corresponding to the inputs to the Bloq.
Returns
build_call_graph
build_call_graph(
ssa: 'SympySymbolAllocator'
) -> 'BloqCountDictT'
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
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.
num_qubits
num_qubits() -> int
The number of qubits this gate acts on.
__ne__
__ne__(
other
)
Check equality and either forward a NotImplemented or return the result negated.
__eq__
__eq__(
other
)
Method generated by attrs for class Controlled.
View source on GitHub