qilisdk.digital.circuit
Classes
Mixin for objects that expose tunable parameters and constraints. |
Module Contents
- class Circuit(nqubits: int)[fuente]
Bases:
qilisdk.core.parameterizable.ParameterizableMixin for objects that expose tunable parameters and constraints.
Subclasses can compose parameter interfaces by yielding child
Parameterizableinstances from_iter_parameter_children().Initialize a Circuit instance with a specified number of qubits.
- Parámetros:
nqubits (
int) – The number of qubits in the circuit.
- property nqubits: int[fuente]
Retrieve the number of qubits in the circuit.
- Devuelve:
The total number of qubits.
- Tipo del valor devuelto:
int
- property nparameters: int[fuente]
Retrieve the total number of parameters required by all parameterized gates in the circuit.
- Devuelve:
The total count of parameters from all parameterized gates.
- Tipo del valor devuelto:
int
- property gates: list[qilisdk.digital.gates.Gate][fuente]
Retrieve the list of gates in the circuit.
- Devuelve:
A list of gates that have been added to the circuit.
- Tipo del valor devuelto:
list[Gate]
- set_parameters(parameters: dict[str, qilisdk.core.types.RealNumber]) None[fuente]
Set the parameter values by their label. No need to provide the full list of parameters.
- Parámetros:
parameters (
dict[str,float]) – A dictionary with the labels of the parameters to be modified and their new value.- Muestra:
ValueError – if the label provided doesn’t correspond to a parameter defined in this circuit.
- set_parameter_bounds(ranges: dict[str, tuple[float, float]]) None[fuente]
Update the allowable ranges for the specified parameters.
- Parámetros:
ranges (
dict[str,tuple[float,float]]) – Mapping from parameter label to(lower, upper)bounds.- Muestra:
ValueError – If an unknown parameter label is provided.
- set_prefix(prefix: str, where: Callable[[qilisdk.core.Parameter], bool] | None = None) None[fuente]
Set a prefix on parameter labels.
- Parámetros:
prefix (
str) – Prefix to prepend to selected parameter labels.where (
Callable[[Parameter],bool] | None) – Optional predicate selecting local parameters.
Notas
The
wherepredicate is applied to local parameters only. Child parameterizable objects always receive the same prefix operation recursively.
- add(gates: qilisdk.digital.gates.Gate | Iterable[qilisdk.digital.gates.Gate]) None[fuente]
Add a quantum gate to the circuit.
- Parámetros:
gates (
Gate | list[Gate]) – The quantum gate or a list of quantum gates to be added to the circuit.
- insert(gates: qilisdk.digital.gates.Gate | Iterable[qilisdk.digital.gates.Gate], index: int | None = None) None[fuente]
Insert one or more quantum gates into the circuit at a given index.
The gates are inserted consecutively, so their relative order is preserved.
- Parámetros:
gates (
Gate | Iterable[Gate]) – The gate or gates to be inserted.index (
int | None, optional) – The index at which the first gate is inserted, following the usual list indexing rules, so a negative value counts from the end of the circuit. Defaults to None, which appends the gates at the end of the circuit.
- Muestra:
QubitOutOfRangeError – If any qubit index used by a gate is not within the circuit’s qubit range.
- append(circuit: Circuit) None[fuente]
Append circuit elements at the end of the current circuit.
- Parámetros:
circuit (
Circuit) – The circuit to be appended.- Muestra:
QubitOutOfRangeError – If the appended circuit acts on more qubits than the current circuit.
- prepend(circuit: Circuit) None[fuente]
Prepend circuit elements to the beginning of the current circuit.
- Parámetros:
circuit (
Circuit) – The circuit to be prepended.- Muestra:
QubitOutOfRangeError – If the circuit to be prepended acts on more qubits than the current circuit.
- copy() Self[fuente]
Return an independent deep copy of this circuit.
Every gate and parameter is duplicated, so setting parameters, adding gates or otherwise modifying the returned circuit never affects this one. Parameters shared between several gates of this circuit stay shared between the corresponding gates of the copy.
- Devuelve:
A new circuit equal to this one but sharing no state with it.
- Tipo del valor devuelto:
- to_matrix() numpy.ndarray[fuente]
Return the full unitary matrix representation of the circuit.
- Muestra:
GateHasNoMatrixError – if any gate does not define a matrix (e.g., measurement).
- to_qtensor() qilisdk.core.QTensor[fuente]
- draw(style: qilisdk.utils.visualization.CircuitStyle = CircuitStyle(), filepath: str | None = None) None[fuente]
Render this circuit with Matplotlib and optionally save it to a file.
The circuit is rendered using the provided style configuration. If
filepathis given, the resulting figure is saved to disk (the output format is inferred from the file extension, e.g..png,.pdf,.svg).- Parámetros:
style (
CircuitStyle) – Visual style configuration applied to the plot. If not provided, the defaultCircuitStyleis used.filepath (
str | None) – Destination file path for the rendered figure. IfNone, the figure is not saved.
- classmethod random(nqubits: int, single_qubit_gates: set[type[qilisdk.digital.gates.BasicGate]], two_qubit_gates: set[type[qilisdk.digital.gates.BasicGate]], ngates: int, seed: int | None = None) Self[fuente]
Generate a random quantum circuit from a given set of gates.
- Parámetros:
nqubits (
int) – The number of qubits in the circuit.single_qubit_gates (
set[Gate]) – A set of single-qubit gate classes to choose from.two_qubit_gates (
set[Gate]) – A set of two-qubit gate classes to choose from.ngates (
int) – The number of gates to include in the circuit.seed (
int | None) – Optional seed for the local random number generator, for reproducible circuits. The globalrandomstate is never used or modified.
- Devuelve:
A randomly generated quantum circuit.
- Tipo del valor devuelto:
- Muestra:
ValueError – If it is not possible to generate a full random circuit with the provided parameters