Full tensor network contraction#

Module for conversion from tket primitives to cuQuantum primitives.

class pytket.extensions.cutensornet.CuTensorNetBackend#

A pytket Backend wrapping around the cuTensorNet simulator.

circuit_status(handle: ResultHandle) CircuitStatus#

Returns circuit status object.

Returns:

CircuitStatus object.

Raises:

CircuitNotRunError – if there is no handle object in cache.

default_compilation_pass(optimisation_level: int = 1) BasePass#

Returns a default compilation pass.

A suggested compilation pass that will guarantee the resulting circuit will be suitable to run on this backend with as few preconditions as possible.

Parameters:

optimisation_level – The level of optimisation to perform during compilation. Level 0 just solves the device constraints without optimising. Level 1 additionally performs some light optimisations. Level 2 adds more intensive optimisations that can increase compilation time for large circuits. Defaults to 1.

Returns:

Compilation pass guaranteeing required predicates.

get_circuit_overlap(circuit_ket: Circuit, circuit_bra: Circuit | None = None, valid_check: bool = True) float#

Calculates an overlap of two states represented by two circuits.

Parameters:
  • circuit_bra – Circuit representing the bra state.

  • circuit_ket – Circuit representing the ket state.

  • valid_check – Whether to perform circuit validity check.

Returns:

Overlap value.

get_operator_expectation_value(state_circuit: Circuit, operator: QubitPauliOperator, post_selection: dict[pytket.unit_id.Qubit, int] | None = None, valid_check: bool = True) float#

Calculates expectation value of an operator using cuTensorNet contraction.

Has an option to do post selection on an ancilla register.

Parameters:
  • state_circuit – Circuit representing state.

  • operator – Operator which expectation value is to be calculated.

  • valid_check – Whether to perform circuit validity check.

  • post_selection – Dictionary of qubits to post select where the key is qubit and the value is bit outcome.

Returns:

Expectation value.

process_circuits(circuits: Sequence[Circuit], n_shots: int | Sequence[int] | None = None, valid_check: bool = True, **kwargs: int | float | str | None) List[ResultHandle]#

Submits circuits to the backend for running.

The results will be stored in the backend’s result cache to be retrieved by the corresponding get_<data> method.

Parameters:
  • circuits – List of circuits to be submitted.

  • n_shots – Number of shots in case of shot-based calculation.

  • valid_check – Whether to check for circuit correctness.

Returns:

Results handle objects.

Raises:

TypeError – If global phase is dependent on a symbolic parameter.

rebase_pass() BasePass#

Defines rebasing method.

Returns:

Automatic rebase pass object based on the backend gate set.

property backend_info: BackendInfo | None#

Returns information on the backend.

property required_predicates: List[Predicate]#

Returns the minimum set of predicates that a circuit must satisfy.

Predicates need to be satisfied before the circuit can be successfully run on this backend.

Returns:

List of required predicates.

class pytket.extensions.cutensornet.ExpectationValueTensorNetwork(bra: TensorNetwork, paulis: QubitPauliString, ket: TensorNetwork, loglevel: int = 20)#

Handles a tensor network representing an expectation value.

property cuquantum_interleaved: list#

Returns an interleaved format of the circuit tensor network.

class pytket.extensions.cutensornet.PauliOperatorTensorNetwork(paulis: QubitPauliString, bra: TensorNetwork, ket: TensorNetwork, loglevel: int = 20)#

Handles a tensor network representing a Pauli operator string.

property cuquantum_interleaved: list#

Returns an interleaved format of the circuit tensor network.

class pytket.extensions.cutensornet.TensorNetwork(circuit: Circuit, adj: bool = False, loglevel: int = 20)#

Responsible for converting pytket circuit to a tensor network and handling it.

dagger() TensorNetwork#

Constructs an adjoint of a tensor network object.

Returns:

A new TensorNetwork object, containing an adjoint representation of the input object.

vdot(tn_other: TensorNetwork) list#

Returns a tensor network representing an overlap of two circuits.

An adjoint representation of tn_other is obtained first (with the indices having negative sign). Then the two tensor networks are concatenated, separated by a single layer of unit matrices. The “sticky” indices of the two tensor networks connect with their counterparts via those unit matrices.

Parameters:

tn_other – a TensorNetwork object representing a circuit, an overlap with which is to be calculated.

Returns:

A tensor network in an interleaved form, representing an overlap of two circuits.

property cuquantum_interleaved: list#

Returns an interleaved format of the circuit tensor network.

pytket.extensions.cutensornet.measure_qubits_state(ket: TensorNetwork, measurement_dict: dict[pytket.unit_id.Qubit, int], loglevel: int = 20) TensorNetwork#

Measures a list of qubits in a tensor network.

Does so by appending a measurement gate to the tensor network. The measurment gate is applied via appending a tensor cap of the form: 0: [1, 0] or 1: [0, 1] to the interleaved einsum input. Therefor removing the open indices of the tensor network corresponding to the measured qubits.

Parameters:
  • ket – a TensorNetwork object representing a quantum state.

  • measurement_dict – a dictionary of qubit ids and their corresponding bit values to be assigned to the measured qubits.

  • loglevel – logging level.

Returns:

A TensorNetwork object representing a quantum state after the measurement with a modified interleaved notation containing the extra measurement tensors.

pytket.extensions.cutensornet.tk_to_tensor_network(tkc: Circuit) List[ndarray[Any, dtype[_ScalarType_co]] | List]#

Converts pytket circuit into a tensor network.

Parameters:

tkc – Circuit.

Returns:

A tensor network representing the input circuit in the interleaved format (list).