qilisdk.digital.circuit

Classes

Circuit

Mixin for objects that expose tunable parameters and constraints.

Module Contents

class Circuit(nqubits: int)[source]

Bases: qilisdk.core.parameterizable.Parameterizable

Mixin for objects that expose tunable parameters and constraints.

Initialize a Circuit instance with a specified number of qubits.

Parameters:

nqubits (int) – The number of qubits in the circuit.

property nqubits: int[source]

Retrieve the number of qubits in the circuit.

Returns:

The total number of qubits.

Return type:

int

property nparameters: int[source]

Retrieve the total number of parameters required by all parameterized gates in the circuit.

Returns:

The total count of parameters from all parameterized gates.

Return type:

int

property gates: list[qilisdk.digital.gates.Gate][source]

Retrieve the list of gates in the circuit.

Returns:

A list of gates that have been added to the circuit.

Return type:

list[Gate]

get_parameter_values() list[float][source]

Retrieve the parameter values from all parameterized gates in the circuit.

Returns:

A list of parameter values from each parameterized gate.

Return type:

list[float]

get_parameter_names() list[str][source]

Retrieve the parameter values from all parameterized gates in the circuit.

Returns:

A list of parameter values from each parameterized gate.

Return type:

list[float]

get_parameters() dict[str, float][source]

Retrieve the parameter names and values from all parameterized gates in the circuit.

Returns:

A dictionary of the parameters with their current values.

Return type:

dict[str, float]

set_parameter_values(values: list[float]) None[source]

Set new parameter values for all parameterized gates in the circuit.

Parameters:

values (list[float]) – A list containing new parameter values to assign to the parameterized gates.

Raises:

ParametersNotEqualError – If the number of provided values does not match the expected number of parameters.

set_parameters(parameters: dict[str, qilisdk.core.types.RealNumber]) None[source]

Set the parameter values by their label. No need to provide the full list of parameters.

Parameters:

parameters (dict[str, float]) – A dictionary with the labels of the parameters to be modified and their new value.

Raises:

ValueError – if the label provided doesn’t correspond to a parameter defined in this circuit.

get_parameter_bounds() dict[str, tuple[float, float]][source]

Return the (lower, upper) bounds associated with each parameter.

set_parameter_bounds(ranges: dict[str, tuple[float, float]]) None[source]

Update the allowable ranges for the specified parameters.

Parameters:

ranges (dict[str, tuple[float, float]]) – Mapping from parameter label to (lower, upper) bounds.

Raises:

ValueError – If an unknown parameter label is provided.

add(gates: qilisdk.digital.gates.Gate | Iterable[qilisdk.digital.gates.Gate]) None[source]

Add a quantum gate to the circuit.

Parameters:

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 = -1) None[source]

Insert a quantum gate to the circuit at a given index.

Parameters:
  • gates (Gate | list[Gate]) – The gate or list of gates to be inserted.

  • index (int, optional) – The index at which the gate is inserted. Defaults to -1.

append(circuit: Circuit) None[source]

Append circuit elements at the end of the current circuit.

Parameters:

circuit (Circuit) – The circuit to be appended.

Raises:

QubitOutOfRangeError – If the appended circuit acts on more qubits than the current circuit.

prepend(circuit: Circuit) None[source]

Prepend circuit elements to the beginning of the current circuit.

Parameters:

circuit (Circuit) – The circuit to be prepended.

Raises:

QubitOutOfRangeError – If the circuit to be prepended acts on more qubits than the current circuit.

draw(style: qilisdk.utils.visualization.CircuitStyle = CircuitStyle(), filepath: str | None = None) None[source]

Render this circuit with Matplotlib and optionally save it to a file.

The circuit is rendered using the provided style configuration. If filepath is given, the resulting figure is saved to disk (the output format is inferred from the file extension, e.g. .png, .pdf, .svg).

Parameters:
  • style (CircuitStyle) – Visual style configuration applied to the plot. If not provided, the default CircuitStyle is used.

  • filepath (str | None) – Destination file path for the rendered figure. If None, 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) typing_extensions.Self[source]

Generate a random quantum circuit from a given set of gates.

Parameters:
  • 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.

Returns:

A randomly generated quantum circuit.

Return type:

Circuit

Raises:

ValueError – If it is not possible to generate a full random circuit with the provided parameters