qibotn package#
Subpackages#
Submodules#
qibotn.circuit_convertor module#
- class qibotn.circuit_convertor.QiboCircuitToEinsum(circuit, dtype='complex128')#
Bases:
object
Convert 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(pauli_string)#
- 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)#
- init_intermediate_circuit(circuit)#
- init_inverse_circuit(circuit)#
- op_shape_from_qubits(nqubits)#
Modify tensor to cuQuantum shape (qubit_states,input_output) * qubits_involved.
- state_vector_operands()#
qibotn.circuit_to_mps module#
- class qibotn.circuit_to_mps.QiboCircuitToMPS(circ_qibo, gate_algo, dtype='complex128', rand_seed=0)#
Bases:
object
qibotn.eval module#
- qibotn.eval.dense_vector_mps(qibo_circ, gate_algo, datatype)#
Convert qibo circuit to matrix product state (MPS) format and perform contraction to dense vector.
- qibotn.eval.dense_vector_tn(qibo_circ, datatype)#
Convert qibo circuit to tensornet (TN) format and perform contraction to dense vector.
- qibotn.eval.dense_vector_tn_MPI(qibo_circ, datatype, n_samples=8)#
Convert qibo circuit to tensornet (TN) format and perform contraction using multi node and multi GPU through MPI.
The conversion is performed by QiboCircuitToEinsum(), after which it goes through 2 steps: pathfinder and execution. The pathfinder looks at user defined number of samples (n_samples) iteratively to select the least costly contraction path. This is sped up with multi thread. After pathfinding the optimal path is used in the actual contraction to give a dense vector representation of the TN.
- qibotn.eval.dense_vector_tn_nccl(qibo_circ, datatype, n_samples=8)#
Convert qibo circuit to tensornet (TN) format and perform contraction using multi node and multi GPU through NCCL.
The conversion is performed by QiboCircuitToEinsum(), after which it goes through 2 steps: pathfinder and execution. The pathfinder looks at user defined number of samples (n_samples) iteratively to select the least costly contraction path. This is sped up with multi thread. After pathfinding the optimal path is used in the actual contraction to give a dense vector representation of the TN.
- qibotn.eval.expectation_pauli_tn(qibo_circ, datatype, pauli_string_pattern)#
Convert qibo circuit to tensornet (TN) format and perform contraction to expectation of given Pauli string.
- qibotn.eval.expectation_pauli_tn_MPI(qibo_circ, datatype, pauli_string_pattern, n_samples=8)#
Convert qibo circuit to tensornet (TN) format and perform contraction to expectation of given Pauli string using multi node and multi GPU through MPI.
The conversion is performed by QiboCircuitToEinsum(), after which it goes through 2 steps: pathfinder and execution. The pauli_string_pattern is used to generate the pauli string corresponding to the number of qubits of the system. The pathfinder looks at user defined number of samples (n_samples) iteratively to select the least costly contraction path. This is sped up with multi thread. After pathfinding the optimal path is used in the actual contraction to give an expectation value.
- qibotn.eval.expectation_pauli_tn_nccl(qibo_circ, datatype, pauli_string_pattern, n_samples=8)#
Convert qibo circuit to tensornet (TN) format and perform contraction to expectation of given Pauli string using multi node and multi GPU through NCCL.
The conversion is performed by QiboCircuitToEinsum(), after which it goes through 2 steps: pathfinder and execution. The pauli_string_pattern is used to generate the pauli string corresponding to the number of qubits of the system. The pathfinder looks at user defined number of samples (n_samples) iteratively to select the least costly contraction path. This is sped up with multi thread. After pathfinding the optimal path is used in the actual contraction to give an expectation value.
- qibotn.eval.pauli_string_gen(nqubits, pauli_string_pattern)#
Used internally to generate the string based on given pattern and number of qubit.
Example: pattern: “XZ”, number of qubit: 7, output = XZXZXZX
qibotn.eval_qu module#
- qibotn.eval_qu.dense_vector_tn_qu(qasm: str, initial_state, mps_opts, backend='numpy')#
Evaluate QASM with Quimb.
backend (quimb): numpy, cupy, jax. Passed to
opt_einsum
.
- qibotn.eval_qu.init_state_tn(nqubits, init_state_sv)#
Create a matrix product state directly from a dense vector.
qibotn.mps_contraction_helper module#
- class qibotn.mps_contraction_helper.MPSContractionHelper(num_qubits)#
Bases:
object
A helper class to compute various quantities for a given MPS.
Interleaved format is used to construct the input args for cuquantum.contract. A concrete example on how the modes are populated for a 7-site MPS is provided below:
0 2 4 6 8 10 12 14 bra -----A-----B-----C-----D-----E-----F-----G----- | | | | | | | 1| 3| 5| 7| 9| 11| 13| | | | | | | | ket -----a-----b-----c-----d-----e-----f-----g----- 15 16 17 18 19 20 21 22
The follwing 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.
Note that for the nth MPS tensor (rank-3), the modes of the tensor are expected to be (i,p,j) where i denotes the bonding mode with the (n-1)th tensor, p denotes the physical mode for the qubit and j denotes the bonding mode with the (n+1)th tensor.
- 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, b
where 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.
- 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, b
wherea, b
denotes the inputs andA, B
denotes 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}\)
- qibotn.mps_utils.mps_site_right_swap(mps_tensors, i, **kwargs)#
Perform the swap operation between the ith and i+1th MPS tensors.