CtrlSpec#

qualtran.CtrlSpec

A specification for how to control a bloq.

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:

  1. ‘negative’ controls where the bloq is active if the input is |0>.

  2. integer-equality controls where a QInt input must match an integer control value.

  3. ndarrays of control values, where the bloq is active if all inputs are active.

  4. Multiple control registers, control values for each of which can be specified using 1-3 above.

For example:#

  1. CtrlSpec(qdtypes=QUInt(4), cvs=0b0110): Ctrl for a single register, of type QUInt(4) and shape (), is active when the soquet of the input register takes value 6.

  2. CtrlSpec(cvs=[0, 1, 1, 0]): Ctrl for a single register, of type QBit() and shape (4,), is active when soquets of input register take values [0, 1, 1, 0].

  3. CtrlSpec(qdtypes=[QBit(), QBit()], cvs=[[0, 1], [1, 0]]).is_active([0, 1], [1, 0]): Ctrl for 2 registers, each of type QBit() 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.

qdtypes

A tuple of quantum data types, one per ctrl register.

cvs

A 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 qdtype and the bloq is implied to be active if all inputs are active (i.e. the “shape” of the ctrl register is implied to be cv.shape).

concrete_shapes

 

cvs

 

num_bits

 

num_cbits

 

num_ctrl_reg

 

num_qubits

 

qdtypes

 

shapes

 

Methods#

is_symbolic

View source

activation_function_dtypes

View source

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

View source

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

*vals

The classical values (that fit within the types given by activation_function_dtypes) on which we evaluate whether the spec is active.

Returns

wire_symbol

View source

__eq__

View source

Return self==value.

to_cirq_cv

View source

Convert CtrlSpec to cirq.SumOfProducts representation of control values.

from_cirq_cv

View source

Construct a CtrlSpec from cirq.SumOfProducts representation of control values.

get_single_ctrl_val

View source

If controlled by a single qubit, return the control bit, otherwise raise