qibotn package#
Subpackages#
Submodules#
qibotn.circuit_convertor module#
- class qibotn.circuit_convertor.QiboCircuitToEinsum(circuit, dtype='complex128')#
Bases:
objectConvert a circuit to a Tensor Network (TN) representation.
The circuit is first processed to an intermediate form by grouping each gate matrix with its corresponding qubit it is acting on to a list. It is then converted to an equivalent TN expression through the class function state_vector_operands() following the Einstein summation convention in the interleave format.
See document for detail of the format: https://docs.nvidia.com/cuda/cuquantum/python/api/generated/cuquantum.contract.html
The output is to be used by cuQuantum’s contract() for computation of the state vectors of the circuit.
- expectation_operands(ham_gates)#
Create the operands for pauli string expectation computation in the interleave format.
- Parameters
ham_gates – A list of gates derived from Qibo hamiltonian object.
- Returns
Operands for the contraction in the interleave format.
- get_pauli_gates(pauli_map, dtype='complex128', backend=cupy)#
Populate the gates for all pauli operators.
- Parameters
pauli_map – A dictionary mapping qubits to pauli operators.
dtype – Data type for the tensor operands.
backend – The package the tensor operands belong to.
- Returns
A sequence of pauli gates.
- init_basis_map(backend, dtype)#
Initialize the basis map for the quantum circuit.
This method initializes a basis map for the quantum circuit, which maps binary strings representing qubit states to their corresponding quantum state vectors.
- Parameters
backend (object) – The backend object providing the array conversion method.
dtype (object) – The data type for the quantum state vectors.
- init_intermediate_circuit(circuit)#
Initialize the intermediate circuit representation.
This method initializes the intermediate circuit representation by extracting gate matrices and qubit IDs from the given quantum circuit.
- Parameters
circuit (object) – The quantum circuit object.
- init_inverse_circuit(circuit)#
Initialize the inverse circuit representation.
This method initializes the inverse circuit representation by extracting gate matrices and qubit IDs from the given quantum circuit.
- Parameters
circuit (object) – The quantum circuit object.
- op_shape_from_qubits(nqubits)#
Modify tensor to cuQuantum shape.
- Parameters
nqubits (int) – The number of qubits in quantum circuit.
- Returns
(qubit_states,input_output) * nqubits
- state_vector_operands()#
Create the operands for dense vector computation in the interleave format.
- Returns
Operands for the contraction in the interleave format.
qibotn.circuit_to_mps module#
- class qibotn.circuit_to_mps.QiboCircuitToMPS(circ_qibo, gate_algo, dtype='complex128', rand_seed=0)#
Bases:
objectA helper class to convert Qibo circuit to MPS.
- Parameters
circ_qibo – The quantum circuit object.
gate_algo (dict) – Dictionary for SVD and QR settings.
datatype (str) – Either single (“complex64”) or double (complex128) precision.
rand_seed (int) – Seed for random number generator.
qibotn.eval module#
qibotn.eval_qu module#
- qibotn.eval_qu.dense_vector_tn_qu(qasm: str, initial_state, mps_opts, backend='numpy')#
Evaluate circuit in QASM format with Quimb.
- Parameters
qasm (str) – QASM program.
initial_state (list) – Initial state in the dense vector form. If
Nonethe default|00...0>state is used.mps_opts (dict) – Parameters to tune the gate_opts for mps settings in
class quimb.tensor.circuit.CircuitMPS.backend (str) – Backend to perform the contraction with, e.g.
numpy,cupy,jax. Passed toopt_einsum.
- Returns
Amplitudes of final state after the simulation of the circuit.
- Return type
list
- qibotn.eval_qu.init_state_tn(nqubits, init_state_sv)#
Create a matrix product state directly from a dense vector.
- Parameters
nqubits (int) – Total number of qubits in the circuit.
init_state_sv (list) – Initial state in the dense vector form.
- Returns
Matrix product state representation of the dense vector.
- Return type
list
qibotn.mps_contraction_helper module#
- class qibotn.mps_contraction_helper.MPSContractionHelper(num_qubits)#
Bases:
objectA helper class to compute various quantities for a given MPS.
Interleaved format is used to construct the input args for cuquantum.contract.
The following compute quantities are supported:
the norm of the MPS.
the equivalent state vector from the MPS.
the expectation value for a given operator.
the equivalent state vector after multiplying an MPO to an MPS.
- Parameters
num_qubits – The number of qubits for the MPS.
- contract_expectation(mps_tensors, operator, qubits, options=None, normalize=False)#
Contract the corresponding tensor network to form the expectation of the MPS.
- Parameters
mps_tensors – A list of rank-3 ndarray-like tensor objects. The indices of the ith tensor are expected to be bonding index to the i-1 tensor, the physical mode, and then the bonding index to the i+1th tensor.
operator – A ndarray-like tensor object. The modes of the operator are expected to be output qubits followed by input qubits, e.g,
A, B, a, bwhere a, b denotes the inputs and A, B’ denotes the outputs.qubits – A sequence of integers specifying the qubits that the operator is acting on.
options – Specify the contract and decompose options.
normalize – Whether to scale the expectation value by the normalization factor.
- Returns
An ndarray-like object as the state vector.
- contract_norm(mps_tensors, options=None)#
Contract the corresponding tensor network to form the norm of the MPS.
- Parameters
mps_tensors – A list of rank-3 ndarray-like tensor objects. The indices of the ith tensor are expected to be bonding index to the i-1 tensor, the physical mode, and then the bonding index to the i+1th tensor.
options – Specify the contract and decompose options.
- Returns
The norm of the MPS.
- contract_state_vector(mps_tensors, options=None)#
Contract the corresponding tensor network to form the state vector representation of the MPS.
- Parameters
mps_tensors – A list of rank-3 ndarray-like tensor objects. The indices of the ith tensor are expected to be bonding index to the i-1 tensor, the physical mode, and then the bonding index to the i+1th tensor.
options – Specify the contract and decompose options.
- Returns
An ndarray-like object as the state vector.
qibotn.mps_utils module#
- qibotn.mps_utils.apply_gate(mps_tensors, gate, qubits, **kwargs)#
Apply the gate operand to the MPS tensors in-place.
# Reference: https://github.com/NVIDIA/cuQuantum/blob/main/python/samples/cutensornet/tn_algorithms/mps_algorithms.ipynb
- Parameters
mps_tensors – A list of rank-3 ndarray-like tensor objects. The indices of the ith tensor are expected to be the bonding index to the i-1 tensor, the physical mode, and then the bonding index to the i+1th tensor.
gate – A ndarray-like tensor object representing the gate operand. The modes of the gate is expected to be output qubits followed by input qubits, e.g,
A, B, a, bwherea, bdenotes the inputs andA, Bdenotes the outputs.qubits – A sequence of integers denoting the qubits that the gate is applied onto.
algorithm – The contract and decompose algorithm to use for gate application. Can be either a dict or a ContractDecomposeAlgorithm.
options – Specify the contract and decompose options.
- Returns
The updated MPS tensors.
- qibotn.mps_utils.initial(num_qubits, dtype)#
Generate the MPS with an initial state of \(\ket{00...00}\)
- Parameters
num_qubits – Number of qubits in the Quantum Circuit.
dtype – Either single (“complex64”) or double (complex128) precision.
- Returns
The initial MPS tensors.
- qibotn.mps_utils.mps_site_right_swap(mps_tensors, i, **kwargs)#
Perform the swap operation between the ith and i+1th MPS tensors.
- Parameters
mps_tensors – Tensors representing MPS
i (int) – index of the tensor to swap
- Returns
The updated MPS tensors.
qibotn.result module#
- class qibotn.result.TensorNetworkResult(nqubits: int, backend: QibotnBackend, measures: dict, measured_probabilities: Union[dict, ndarray], prob_type: str, statevector: ndarray)#
Bases:
objectObject to store and process the output of a Tensor Network simulation of a quantum circuit.
- Parameters
nqubits (int) – number of qubits involved in the simulation;
backend (QibotnBackend) – specific backend on which the simulation has been performed;
measures (dict) – measures (if performed) during the tensor network simulation;
measured_probabilities (Union[dict, ndarray]) – probabilities of the final state according to the simulation;
prob_type (str) – string identifying the method used to compute the probabilities. Especially useful in case the QmatchateaBackend is selected.
statevector (ndarray) – if computed, the reconstructed statevector.
- backend: QibotnBackend#
- frequencies()#
Return frequencies if a certain number of shots has been set.
- measured_probabilities: Union[dict, ndarray]#
- measures: dict#
- nqubits: int#
- prob_type: str#
- probabilities()#
Return calculated probabilities according to the given method.
- state()#
Return the statevector if the number of qubits is less than 20.
- statevector: ndarray#