cutqc2.core package

Submodules

cutqc2.core.cut_circuit module

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.dynamic_definition module

cutqc2.core.utils module

cutqc2.core.utils.chunked(gen, chunk_size)[source]

Yield lists of length chunk_size from generator gen.

cutqc2.core.utils.distribute(n_qubits, probabilities, capacity)[source]
Return type:

str

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

Compress quantum probability vector by merging specified qubits and conditioning on fixed qubit values.

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

  • qubit_spec (str) – String of length num_qubits, MSB to LSB, with each character indicating: - “A”: qubit is preserved in output - “M”: qubit is summed over - “0”/”1”: qubit is fixed to that value

Returns:

Compressed probability vector (2^num_active,) with marginalization and conditioning applied.

Return type:

np.ndarray

cutqc2.core.utils.permute_bits(n, permutation)[source]
Return type:

int

cutqc2.core.utils.permute_bits_vectorized(arr, permutation, n_bits)[source]
Return type:

ndarray

cutqc2.core.utils.unmerge_prob_vector(merged_prob_vector, qubit_spec, full_states=None)[source]

Expand a merged quantum probability vector back to a full vector by evenly distributing over merged qubits and conditioning on fixed ones.

Parameters:
  • merged_prob_vector (np.ndarray) – Compressed probability vector (2^num_active,)

  • qubit_spec (str) – String of length num_qubits with characters: - “A”: active (preserved) - “M”: merged (marginalized out) - “0”/”1”: fixed bits

  • full_states (np.ndarray or None) – Array of full states to fill in. If None, all 2**|num_qubits| states are filled-in.

Return type:

None

Module contents