Skip to content

Density matrix utility functions for simulator

numqi.sim.dm

numqi.sim.dm.new_base(num_qubit, dtype=np.complex128)

return the base density matrix of the qubit quantum system

Parameters:

Name Type Description Default
num_qubit int

the number of qubits

required
dtype dtype

the data type of the base state

complex128

Returns:

Name Type Description
ret ndarray

the base state, ret.shape==(2**num_qubit,2**num_qubit)

numqi.sim.dm.apply_gate(dm, op, index)

apply a gate to the density matrix

Parameters:

Name Type Description Default
dm ndarray

the density matrix, dm.shape==(2**num_qubit,2**num_qubit)

required
op ndarray

the gate, op.shape==(2**N0,2**N0)

required
index int | tuple[int]

the qubit index to apply the gate, 0<=index<num_qubit, count from left to right |0123>

required

Returns:

Name Type Description
ret ndarray

the density matrix after applying the gate

numqi.sim.dm.operator_expectation(dm0, op, index)

calculate the expectation value of an operator

TODO multiple operators

Parameters:

Name Type Description Default
dm0 ndarray

the density matrix, dm0.shape==(2**num_qubit,2**num_qubit)

required
op ndarray

the operator, op.shape==(2**N0,2**N0)

required
index int | tuple[int]

the qubit index to apply the operator

required

Returns:

Name Type Description
ret ndarray

the expectation value