6.7. utils#

bin2num(c)[source]#

Convert binary list to decimal number.

Parameters:

c (list([0|1])) – A list of 0 and 1 values.

Returns:

result – The integer value corresponding to the binary list.

Return type:

int

cupyWarmup()[source]#

Warm up the GPU. It’s a good practice to run this function before simulating a large circuit for the first time, as the initial CUDA API call might take some time to process. For more information please refer to: https://docs.cupy.dev/en/stable/user_guide/performance.html

embedSequences(seq)[source]#

This function scans through the operations in a `Sequence` object and replaces all occurences of `Sequence` objects in it by the corresponding operations in it. This function only replaces `Sequence` objects on the first level, i.e. it does not replace recursively all `Sequence` objects within other `Sequence` objects.

Parameters:

seq (geqo.core.quantum_circuit.Sequence) – A `Sequence` object.

Returns:

res – A `Sequence` object with all occurences of ``Sequence`` objects on the first level replaced by the corresponding operators.

Return type:

geqo.core.quantum_circuit.Sequence

getQFTCuPy(n, inverse)[source]#

Return CuPy matrix for QFT.

getRXCupy(angle)[source]#

Return CuPy matrix for Rx gate with given angle.

getRYCupy(angle)[source]#

Return CuPy matrix for Ry gate with given angle.

getSingleQubitOperationOnRegister(u: ndarray[tuple[Any, ...], dtype[_ScalarT]], numberQubits: int, targets: list[int]) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]#

Apply single-qubit operation to specific qubits in register. This function embeds the given matrix into the matrix corresponding to the whole system.

Parameters:
  • u (NDArray) – The unitary matrix, which is applied to a part of the whole quantum register.

  • numberQubits (int) – The size of the quantum register.

  • targets (list[int]) – The list of qubits, on which the operation is applied to.

Returns:

A matrix on the whole register, which is the embedding of the provided operation.

Return type:

NDArray

multiQubitsUnitary(u, qubits, targets)[source]#

Construct multi-qubit unitary matrix without permuting the qubits

multiQubitsUnitaryCupy(u, qubits, targets)[source]#

compute the whole-system unitary U given the target qubits and the target unitary u.

newPartialTrace(rho, qubits, dropTargets)[source]#

Compute partial trace of density matrix faster.

num2bin(num, digits)[source]#

Convert a decimal number to a binary representation in list form.

Parameters:

num (int) – An integer.

Returns:

btstr – A list of 0 and 1, which is the binary representation of the given number.

Return type:

list([0|1])

partialTrace(rho: ndarray[tuple[Any, ...], dtype[_ScalarT]], qubits: list[int], dropTargets: list[int]) tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]], ndarray[tuple[Any, ...], dtype[_ScalarT]]][source]#

Compute the partial trace of a density matrix. The density matrix is reduced to the remaining qubits. The new density matrix is obtained by tracing out the dropped qubit. In general, this leads to mixed states.

Parameters:
  • rho (NDArray) – The density matrix before dropping qubits.

  • qubits (list[int]) – The list of all qubits of a quantum register.

  • dropTargets (list[int]) – The list of qubits, which are dropped.

Returns:

The first result matrix is the reduced density matrix. The second result matrix is the permutation matrix, which moves the remaining entries of the original density matrix to the front.

Return type:

tuple[NDArray, NDArray]

partialTraceCupy(rho, qubits, dropTargets)[source]#

Fully vectorized partial trace implementation without any loops.

partial_diag(rho, qubits, dropTargets)[source]#

Compute the partial trace (trace out the dropTargets) and extract the non-zero diagonal element of the reduced density matrix.

Parameters:
  • rho (numpy.ndarry | sympy.Matrix) – A density matrix.

  • qubits (list(int|String)) – A list of qubits of a register.

  • dropTargets (list(int|String)) – The qubits that are discarded.

Returns:

nonzero – A list of pairs. The first component of a pair is a binary representation of the index of a diagonal element of the density matrix. The second component is the corresponding entry.

Return type:

list((list([0|1]), numpy.float64 | sympy.core ))

partial_diag_cupy(rho, qubits, dropTargets)[source]#

Compute partial trace over dropTargets and return non-zero diagonal values with bitstring indices.

permutationMatrixCupy(perm: list)[source]#

Return cupy permutation matrix for given qubit permutation.

permutationMatrixQubitsNumPy(perm: list[int]) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]#

Return permutation matrix for given qubit permutation.

Parameters:

perm (list[int]) – The permutation of qubits in list form. The elements are indexed starting with 0. For instance, [0,2,1] denotes the permutation of 3 qubits, where the last 2 qubits are flipped.

Returns:

A permutation matrix on the state space of the qubits. The matrix corresponds to the permutation of the qubits.

Return type:

NDArray

permutationMatrixQubitsSymPy(perm: list[int]) MutableDenseMatrix[source]#

Return a permutation matrix for given qubit permutation.

6.7. Params#

perm: list[int]

The permutation of qubits in list form. Each entry is the index after the permutation.

6.7. Results#

sym.Matrix

The permutation matrix corresponding to the provided permutation of qubits.

projection(densityMatrix, num_qubits, targets, basis)[source]#

Construct the projector of a given basis state and compute the projected density matrix.

projection_cupy(densityMatrix, num_qubits, targets, basis)[source]#

Construct the projector of a given basis state and compute the projected density matrix.