qailab.circuit.base#

ABC structure for circuit building blocks

Summary#

Classes:

CircuitBlock

Base class for any circuit building block

EncodingBlock

Blocks encoding some parameter vector (trainable or not)

EntanglingBlock

Blocks entangling qubits together

NonGateBlock

Blocks that cannot be converted to gates, e.g. measurement.

ParameterizedBlock

Blocks generating parametrized circuits

Reference#

class qailab.circuit.base.CircuitBlock(name: str = 'unknown')[source]#

Bases: ABC

Base class for any circuit building block

name#

Block (and block circuit) name.

Type:

str

to_gate(num_qubits: int) Gate[source]#

Get a gate form of of this block.

Parameters:

num_qubits (int) – Desired width.

Returns:

Block defined circuit as a single gate.

Return type:

Gate

add_to_circuit(circuit: QuantumCircuit, qargs: Sequence[Qubit | QuantumRegister | int | slice | Sequence[Qubit | int]] | None = None) None[source]#

Add this block to a circuit (number of qubits must match)

Parameters:
  • circuit (QuantumCircuit) – The circuit that will receive this block (in place).

  • qargs (list[QubitSpecifier] | None, optional) – Which qubits to apply this circuit to. If None apply to all. Defaults to None.

class qailab.circuit.base.ParameterizedBlock(name: str = 'unknown')[source]#

Bases: CircuitBlock, ABC

Blocks generating parametrized circuits

property parameters: Sequence[Parameter]#

Get this block’s parameter vector

class qailab.circuit.base.EntanglingBlock(name: str = 'unknown')[source]#

Bases: CircuitBlock, ABC

Blocks entangling qubits together

class qailab.circuit.base.EncodingBlock(name: str = 'unknown', block_type: Literal['input', 'weight'] = 'input')[source]#

Bases: ParameterizedBlock, CircuitBlock, ABC

Blocks encoding some parameter vector (trainable or not)

block_type#

Whether this block encodes weights or inputs.

Type:

Literal[‘input’, ‘weight’]

class qailab.circuit.base.NonGateBlock(name: str = 'unknown')[source]#

Bases: CircuitBlock, ABC

Blocks that cannot be converted to gates, e.g. measurement.

to_gate(num_qubits: int) Gate[source]#

Get a gate form of of this block.

Parameters:

num_qubits (int) – Desired width.

Returns:

Block defined circuit as a single gate.

Return type:

Gate

add_to_circuit(circuit: QuantumCircuit, qargs: Sequence[Qubit | QuantumRegister | int | slice | Sequence[Qubit | int]] | None = None) None[source]#

Add this block to a circuit (number of qubits must match)

Parameters:
  • circuit (QuantumCircuit) – The circuit that will receive this block (in place).

  • qargs (list[QubitSpecifier] | None, optional) – Which qubits to apply this circuit to. If None apply to all. Defaults to None.