cutqc2.core package

Submodules

cutqc2.core.cut_circuit module

class cutqc2.core.cut_circuit.CutCircuit(circuit, add_labels=True)[source]

Bases: object

add_cut(label, wire_index, gate_index)[source]

Add a cut to the circuit at the position of the instruction with the specified label. :type label: str :param label: The label of the instruction after which the cut should be made. :type wire_index: int :param wire_index: The index of the wire where the cut should be made.

add_cut_at_position(wire_index, gate_index)[source]
add_cuts(cut_edges)[source]
add_cuts_and_generate_subcircuits(cut_edges, subcircuits)[source]
static check_valid(circuit)[source]
compute_probabilities(mem_limit=None, recursion_depth=1)[source]
compute_probabilities_new()[source]
cut(max_subcircuit_width, max_cuts, num_subcircuits, max_subcircuit_cuts, subcircuit_size_imbalance, generate_subcircuits=True)[source]
find_cuts(max_subcircuit_width, max_cuts, num_subcircuits, max_subcircuit_cuts, subcircuit_size_imbalance)[source]
static from_file(filepath, *args, **kwargs)[source]
Return type:

Self

get_all_subcircuit_packed_probs()[source]
get_counter()[source]
static get_dag_metadata(dag)[source]
Return type:

dict

get_ground_truth(backend)[source]
Return type:

ndarray

static get_initializations(paulis, legacy=True)[source]

Get coefficients and kets used for each term in the expansion of the trace operators for each of the Pauli bases (eq. 2 in paper). :rtype: list[tuple[int, tuple[str]]]

0 1 + i

0 1 I 1 1 X -1 -1 2 Y -1 -1 2 Z 1 -1

static get_inter_wire_dag(circuit)[source]

Get the dag for the stripped version of a circuit where we only preserve gates that span two wires.

Return type:

DAGCircuit

static get_labeled_circuit(circuit)[source]

Get a labeled version of the circuit where each instruction is labeled

Return type:

QuantumCircuit

get_packed_probabilities(subcircuit_i, qubit_mask=None)[source]
Return type:

ndarray

property num_cuts: int
populate_compute_graph()[source]

Generate the connection graph among subcircuits

populate_subcircuit_entries()[source]
postprocess(new=True)[source]
Return type:

array

property reconstruction_qubit_order: dict[int, list[int]]
run_subcircuits(subcircuits=None, backend='statevector_simulator')[source]
to_file(filepath, *args, **kwargs)[source]
Return type:

None

verify(reconstructed_probabilities=None, backend='statevector_simulator', atol=1e-10, new=True)[source]
class cutqc2.core.cut_circuit.Instruction(op, qarg0=None, qarg1=None)[source]

Bases: object

max_qarg()[source]

Get the maximum qarg index used in this instruction.

Return type:

int

op: Operation
qarg0: int | None = None
qarg1: int | None = None
class cutqc2.core.cut_circuit.WireCutGate[source]

Bases: UnitaryGate

Custom gate to represent a wire cut in a quantum circuit.

cutqc2.core.dag module

class cutqc2.core.dag.DAGEdge(first, second)[source]

Bases: object

Represents an edge in a quantum circuit DAG, connecting two DagNodes.

source

The source node of the edge.

Type:

DagNode

dest

The destination node of the edge.

Type:

DagNode

classmethod from_string(edge_str)[source]

Create a DAGEdge from a string representation.

Parameters:

edge_str (str) – The string representation of the edge in the format ‘source dest’.

Returns:

The created DAGEdge instance.

Return type:

DAGEdge

weight()[source]
Return type:

int

class cutqc2.core.dag.DagNode(wire_index, gate_index, name='q')[source]

Bases: object

Represents a node in a quantum circuit DAG (Directed Acyclic Graph), corresponding to a specific gate on a specific wire (qubit/register).

Since only inter-wire gates are important for the cut algorithm, any mention of gate_index refers to the index wrt inter-wire gates only.

wire_index

The index of the wire (qubit/register).

Type:

int

gate_index

The index of the gate on the wire. Note: gate_index assumes that only inter-wire gates are considered.

Type:

int

name

The name of the node (default ‘q’).

Type:

str

classmethod from_string(s)[source]

Create a DagNode from a string representation.

Parameters:

s (str) – The string representation of the node in the format ‘name[wire_index]gate_index’.

Returns:

The created DagNode instance.

Return type:

DagNode

locate(dag_circuit)[source]

Locate the position of the DagNode in the DAGCircuit. :type dag_circuit: DAGCircuit :param dag_circuit: The DAGCircuit containing the node. :type dag_circuit: DAGCircuit

Returns:

A tuple containing the Qubit and the index of the gate on that wire.

Return type:

tuple[Qubit, int]

Raises:

ValueError – If the node cannot be found in the DAGCircuit.

cutqc2.core.utils module

cutqc2.core.utils.distribute_load(load, capacity=None)[source]
Return type:

dict[int, int]

cutqc2.core.utils.merge_prob_vector(unmerged_prob_vector, qubit_mask)[source]

Compress quantum probability vector by merging specified qubits.

Parameters:
  • unmerged_prob_vector (numpy.ndarray) – Original probability vector (2^num_qubits,)

  • qubit_mask (mask specifying which qubits are active (1) and which) – need to get merged (0).

Returns:

Compressed vector (2^num_active,) preserving active qubit states while summing over merged qubit states.

Return type:

numpy.ndarray

Module contents