Skip to content
Pasqal Documentation

QuantumCircuit

The abstract QuantumCircuit is the key object in Qadence, as it is what can be executed.

QuantumCircuit(support, *blocks) dataclass

Section titled “ QuantumCircuit(support, *blocks) dataclass ”

Am abstract QuantumCircuit instance.

It needs to be passed to a quantum backend for execution.

Arguments:

support: `Register` or number of qubits. If an integer is provided, a register is
constructed with `Register.all_to_all(x)`
*blocks: (Possibly multiple) blocks to construct the circuit from.
Source code in qadence/circuit.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48def __init__(self, support: int | Register, *blocks: AbstractBlock):
"""
Arguments:
support: `Register` or number of qubits. If an integer is provided, a register is
constructed with `Register.all_to_all(x)`
*blocks: (Possibly multiple) blocks to construct the circuit from.
"""
self.block = chain(*blocks) if len(blocks) != 1 else blocks[0]
self.register = Register(support) if isinstance(support, int) else support
global_block = isinstance(self.block, AnalogBlock) and self.block.qubit_support.is_global
if not global_block and len(self.block) and self.block.n_qubits > self.register.n_qubits:
raise ValueError(
f"Register with {self.register.n_qubits} qubits is too small for the "
f"given block with {self.block.n_qubits} qubits"
)

Return the unique parameters in the circuit.

These parameters are the actual user-facing parameters which can be assigned by the user. Multiple gates can contain the same unique parameter

RETURNS DESCRIPTION
list[Parameter]

list[Parameter]: List of unique parameters in the circuit

Reverse the QuantumCircuit by calling dagger on the block.

Source code in qadence/circuit.py
117
118
119def dagger(self) -> QuantumCircuit:
"""Reverse the QuantumCircuit by calling dagger on the block."""
return QuantumCircuit(self.n_qubits, self.block.dagger())

Extract one or more blocks using the human-readable tag.

This function recursively explores all composite blocks to find all the occurrences of a certain tag in the blocks.

PARAMETER DESCRIPTION
tag

the tag to look for

TYPE: str

RETURNS DESCRIPTION
list[AbstractBlock]

list[AbstractBlock]: The block(s) corresponding to the given tag

Source code in qadence/circuit.py
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142def get_blocks_by_tag(self, tag: str) -> list[AbstractBlock]:
"""Extract one or more blocks using the human-readable tag.
This function recursively explores all composite blocks to find
all the occurrences of a certain tag in the blocks.
Args:
tag (str): the tag to look for
Returns:
list[AbstractBlock]: The block(s) corresponding to the given tag
"""
def _get_block(block: AbstractBlock) -> list[AbstractBlock]:
blocks = []
if block.tag == tag:
blocks += [block]
if isinstance(block, CompositeBlock):
blocks += flatten(*[_get_block(b) for b in block.blocks])
return blocks
return _get_block(self.block)

Extract all parameters for primitive blocks in the circuit.

Notice that this function returns all the unique Parameters used in the quantum circuit. These can correspond to constants too.

RETURNS DESCRIPTION
list[Parameter | Basic] | list[tuple[Parameter | Basic, ...]]

List[tuple[Parameter]]: A list of tuples containing the Parameter

list[Parameter | Basic] | list[tuple[Parameter | Basic, ...]]

instance of each of the primitive blocks in the circuit or, if the flatten

list[Parameter | Basic] | list[tuple[Parameter | Basic, ...]]

flag is set to True, a flattened list of all circuit parameters

Source code in qadence/circuit.py
104
105
106
107
108
109
110
111
112
113
114
115def parameters(self) -> list[Parameter | Basic] | list[tuple[Parameter | Basic, ...]]:
"""Extract all parameters for primitive blocks in the circuit.
Notice that this function returns all the unique Parameters used
in the quantum circuit. These can correspond to constants too.
Returns:
List[tuple[Parameter]]: A list of tuples containing the Parameter
instance of each of the primitive blocks in the circuit or, if the `flatten`
flag is set to True, a flattened list of all circuit parameters
"""
return parameters(self.block)