qrunch.quantum.circuits
Module implementing quantum circuits.
Classes
Circuit class for representing quantum circuits. |
- class Circuit
Bases:
HasCustomEncodingCircuit class for representing quantum circuits.
Quantum circuit consisting of a number of gates acting on a number of qubits.
print can be used to print a diagram of the circuit which preserves the appending order and indices of the gates.
- __init__(**kwds)
Helper for @overload to raise when called.
- append(gate: Gate) None
Append gate to the end of the circuit.
- Parameters:
gate (Gate) – The gate to be appended to the end of the circuit.
- Raises:
IndexError – When the gate acts on qubits which are not included in the circuit.
ValueError – When the name of a gate parameter is already taken by a different parameter in the circuit.
- Return type:
None
- as_gate(name: str) GateFactory
Return the circuit as a single gate.
Creates a gate function that will apply the circuit as a single gate. The function takes qubit indices as arguments, maps this circuit’s qubits to the new indices, and creates a gate with the new indices.
- Parameters:
name (str) – Name of the gate.
- Return type:
- count_gates() dict[str, int]
Count the number of all gate types in circuit.
- Returns:
Dictionary between string representing gate, e.g., X or CX and the gate count.
- Return type:
dict[str, int]
- classmethod decode(data: dict[str, Any]) Self
Decode a dictionary.
- Parameters:
data (dict[str, Any]) – The dictionary representation.
- Return type:
Self
- encode() dict[str, Any]
Encode the instance into a dictionary.
- Return type:
dict[str, Any]
- extend(other: Self | Iterable[Gate]) None
Extend self with other by concatenating other to the right of self.
other can be either a circuit or list containing the gates to be appended on self.
- Parameters:
other (Self | Iterable[Gate]) – CircuitBase or list of gates to extend with.
- Raises:
ValueError – If other is a circuit, and the two circuits do not have the same number of qubits.
- Return type:
None
- get_parameters() list[Parameter]
Return all unspecified gate parameters present in the circuit.
- Returns:
List of unspecified parameters.
- Return type:
list[Parameter]
- inactive_qubits() set[int]
Return a set of inactive qubits, that is qubits without any gates.
- Return type:
set[int]
- is_fully_specified() bool
Check if the circuit is fully specified, i.e., whether all parameters have been set.
- Returns:
True if circuit is fully specified.
- Return type:
bool
- property num_gates: int
Number of gates in the circuit.
- property num_parameters: int
Number of unspecified gate parameters.
- property num_qubits: int
Number of qubits for the circuit to operate on.
- sorted_inactive_qubits() tuple[int, ...]
Return the inactive qubits in a sequence of gates, sorted, as a tuple.
- Return type:
tuple[int, …]
- to_string(*, compact: bool = False, max_character_width: int = 120, max_number_of_decimals: int | None = None, qubit_label_prefix: str = 'q') str
Convert the circuit to a nicely formatted string representation which can be printed.
- Parameters:
compact (bool) – If True, gates are allowed change order compared to the original order. Defaults to False.
max_character_width (int) – Maximum number of characters for each line in the circuit print. Must be at least 50.
max_number_of_decimals (int | None) – Maximum number of decimals to use for floats in the circuit. Defaults to None.
qubit_label_prefix (str) – Prefix for the qubit labels. Defaults to “q”.
- Return type:
str
- with_specified_parameters(parameter_value_pairs: dict[Parameter, float] | dict[str, float]) Self
Update the given parameters with the given values in the dictionary.
The parameters can be parsed through the parameter object or the name.
- Parameters:
parameter_value_pairs (dict[Parameter, float] | dict[str, float]) – Dictionary containing the parameters or name of parameters and values to be set.
- Raises:
ValueError – If a parameter or parameter name is not present in the circuit.
- Returns:
New circuit equivalent to the original circuit but with the parameters specified.
- Return type:
CircuitBase
Modules
Module containing compilers that can convert a circuit to a universal gate circuit. |
|
Module containing all circuit synthesis algorithms such as layout synthesis. |
|
Contains translators that can translate Kvantify Qrunch circuits to third party circuit formats. |
|
Module with transpiler that can transpile a Kvantify Qrunch Circuit to universal third party circuits. |
|
Module implementing a circuit that only accepts universal gates. |