Operators

Quantum operator utilities: Pauli matrices, ladder operators, density matrix operations (partial trace, purity, fidelity), and phase-space operators.

HybridSuperQubits.operators.state_to_density_matrix(state_vector)[source]

Convert a state vector to a density matrix.

Parameters:

state_vector (numpy.ndarray) – The state vector to be converted.

Returns:

The density matrix.

Return type:

numpy.ndarray

HybridSuperQubits.operators.ptrace(rho, dims, subsys)[source]

Compute the partial trace of a density matrix over a specified subsystem.

The partial trace is a method used in quantum mechanics to obtain the reduced density matrix of a subsystem by tracing out the degrees of freedom of the other subsystem.

Parameters:
  • rho (numpy.ndarray) – The density matrix to be traced. It should be a square matrix of shape (dimA * dimB, dimA * dimB).

  • dims (tuple) – A tuple (dimA, dimB) specifying the dimensions of the subsystems A and B.

  • subsys (int) – The subsystem to trace out. Use 0 to trace out subsystem A and 1 to trace out subsystem B.

Returns:

The reduced density matrix after tracing out the specified subsystem.

Return type:

numpy.ndarray

Raises:

ValueError – If the subsys parameter is not 0 or 1.

HybridSuperQubits.operators.purity(density_matrix)[source]

Calculate the purity of a quantum state.

The purity is defined as Tr(rho^2), where rho is the density matrix. For a pure state, the purity is 1. For a mixed state of dimension d, 1/d <= purity < 1.

Parameters:

density_matrix (numpy.ndarray) – The density matrix of the quantum state.

Returns:

The purity of the quantum state.

Return type:

float

HybridSuperQubits.operators.trace_distance(rho1, rho2)[source]

Calculate the trace distance between two density matrices.

The trace distance between two density matrices rho1 and rho2 is defined as: 0.5 * Tr(|rho1 - rho2|), where |A| = sqrt(A^dagger A) is the absolute value of A.

Parameters:
Returns:

The trace distance between the two density matrices.

Return type:

float

HybridSuperQubits.operators.fidelity(rho1, rho2)[source]

Calculate the fidelity between two density matrices.

The fidelity between two density matrices rho1 and rho2 is defined as: |Tr(sqrt(sqrt(rho1) * rho2 * sqrt(rho1)))|^2.

Parameters:
Returns:

The fidelity between the two density matrices.

Return type:

float

HybridSuperQubits.operators.destroy(dimension)[source]

Returns the annihilation (lowering) operator for a given dimension.

Parameters:

dimension (int) – Dimension of the Hilbert space.

Returns:

The annihilation operator.

Return type:

np.ndarray

HybridSuperQubits.operators.creation(dimension)[source]

Returns the creation (raising) operator for a given dimension.

Parameters:

dimension (int) – Dimension of the Hilbert space.

Returns:

The creation operator.

Return type:

np.ndarray

HybridSuperQubits.operators.sigma_x()[source]

Returns the Pauli-X (sigma_x) operator.

Returns:

The Pauli-X operator.

Return type:

np.ndarray

HybridSuperQubits.operators.sigma_y()[source]

Returns the Pauli-Y (sigma_y) operator.

Returns:

The Pauli-Y operator.

Return type:

np.ndarray

HybridSuperQubits.operators.sigma_z()[source]

Returns the Pauli-Z (sigma_z) operator.

Returns:

The Pauli-Z operator.

Return type:

np.ndarray

HybridSuperQubits.operators.cos_phi(N, phi_ext, m=1)[source]

Compute the cosine phi operator matrix in a complex sparse representation.

The operator is calculated based on the given system size N and external phase factor phi_ext.

Parameters:
  • N (int) – The size of the matrix to be created.

  • phi_ext (float) – The external phase factor.

  • m (int, optional) – The diagonal offset. Default is 1.

Returns:

The cosine phi operator as a sparse CSR matrix.

Return type:

sp.csr_matrix

HybridSuperQubits.operators.sin_phi(N, phi_ext, m=1)[source]

Compute the sine phi operator matrix in a complex sparse representation.

The operator is calculated based on the given system size N and external phase factor phi_ext.

Parameters:
  • N (int) – The size of the matrix to be created.

  • phi_ext (float) – The external phase factor.

  • m (int, optional) – The diagonal offset. Default is 1.

Returns:

The sine phi operator as a sparse CSR matrix.

Return type:

sp.csr_matrix