CtrlSpec#
qualtran.CtrlSpec
View source on GitHub
|
A specification for how to control a bloq.
qualtran.CtrlSpec(
qdtypes=attr_dict['qdtypes'].default,
cvs=attr_dict['cvs'].default
)
This class can be used by controlled bloqs to specify the condition under which the bloq is active.
In the simplest form, a controlled gate is active when the control input is one qubit of data, and it’s in the |1> state. Otherwise, the gate is not performed. This corresponds to the following two equivalent CtrlSpecs:
CtrlSpec()
CtrlSpec(qdtypes=QBit(), cvs=1)
This class supports additional control specifications:
‘negative’ controls where the bloq is active if the input is |0>.
integer-equality controls where a QInt input must match an integer control value.
ndarrays of control values, where the bloq is active if all inputs are active.
Multiple control registers, control values for each of which can be specified using 1-3 above.
For example:#
CtrlSpec(qdtypes=QUInt(4), cvs=0b0110): Ctrl for a single register, of typeQUInt(4)and shape(), is active when the soquet of the input register takes value 6.CtrlSpec(cvs=[0, 1, 1, 0]): Ctrl for a single register, of typeQBit()and shape(4,), is active when soquets of input register take values[0, 1, 1, 0].CtrlSpec(qdtypes=[QBit(), QBit()], cvs=[[0, 1], [1, 0]]).is_active([0, 1], [1, 0]): Ctrl for 2 registers, each of typeQBit()and shape(2,), is active when the soquet for each register takes values[0, 1]and[1, 0]respectively.
CtrlSpec uses logical AND among all control register clauses. If you need a different boolean function, open a GitHub issue.
Args
qdtypesA tuple of quantum data types, one per ctrl register.
cvsA tuple of control value(s), one per ctrl register. For each element in the tuple, if more than one ctrl value is provided, they must all be compatible with
qdtypeand the bloq is implied to be active if all inputs are active (i.e. the “shape” of the ctrl register is implied to becv.shape).
Attributes
Methods#
is_symbolic
is_symbolic()
activation_function_dtypes
activation_function_dtypes() -> Sequence[Tuple[QCDType, Tuple[SymbolicInt, ...]]]
The data types that serve as input to the ‘activation function’.
The activation function takes in (quantum) inputs of these types and shapes and determines whether the bloq should be active. This method is useful for setting up appropriate control registers for a ControlledBloq.
Returns
is_active
is_active(
*vals
) -> bool
A classical implementation of the ‘activation function’.
The activation function takes in (quantum) data and determines whether the bloq should be active. This method captures the same behavior on specific classical values representing computational basis states.
This implementation evaluates to True if all the values match self.cvs.
Args
*valsThe classical values (that fit within the types given by
activation_function_dtypes) on which we evaluate whether the spec is active.
Returns
wire_symbol
wire_symbol(
i: int,
reg: qualtran.Register,
idx: Tuple[int, ...] = tuple()
) -> 'WireSymbol'
__eq__
__eq__(
other: Any
) -> bool
Return self==value.
to_cirq_cv
to_cirq_cv() -> 'cirq.SumOfProducts'
Convert CtrlSpec to cirq.SumOfProducts representation of control values.
from_cirq_cv
@classmethodfrom_cirq_cv( cirq_cv: 'cirq.ops.AbstractControlValues', *, qdtypes: Optional[Sequence[QCDType]] = None, shapes: Optional[Sequence[Tuple[int, ...]]] = None ) -> 'CtrlSpec'
Construct a CtrlSpec from cirq.SumOfProducts representation of control values.
get_single_ctrl_val
get_single_ctrl_val() -> ControlBit
If controlled by a single qubit, return the control bit, otherwise raise
View source on GitHub