You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The method extract_states() of the Qobj class doesn't preserve the isherm attribute of the operators it truncates. Maybe I'm forgetting an edge case, but it seems to me that taking any subset of states from an Hermitian operator should results in an Hermitian operator.
Code to Reproduce the Bug
# Imports
import qutip as qt
import numpy as np
import scqubits as scq
# Maximum number of transmon states
k_t_max = 201
ncut = int((k_t_max-1)/2)# Number of states to truncate tok_t_trunc = 100# Transmon Hamiltonian from scqubitstransmon = scq.Transmon(EJ=22.975, EC=0.194, ng=0, ncut=ncut)# Form a qutip objectH_t = qt.Qobj(transmon.hamiltonian())# At this stage, the Hamiltonian has the Hermitian attribute
print("Is the Hamiltonian Hermitian? Answer: {}".format(H_t.isherm))
# And the anti-Hermitian part is truly 0
diff = H_t - H_t.dag()
print("The norm of the anti-Hermitian part is {}".format(diff.norm()))
# Calculate the eigenvalues and eigenvectors
evals_t, evecs_t = H_t.eigenstates()
# Diagonalize the Hamiltonian
H_t = H_t.transform(evecs_t)
# At this stage, the Hamiltonian still has the Hermitian attribute
print("Is the Hamiltonian still Hermitian after diagonalization? Answer: {}".format(H_t.isherm))
# However, the transformation gave a residual non-Hermitian part
diff = H_t - H_t.dag()
print("The norm of the anti-Hermitian part after diagonalization is {}".format(diff.norm()))
# Truncate the Hamiltonian
H_t = H_t.extract_states(range(k_t_trunc))
# At this stage, the Hamiltonian has lost the Hermitian attribute
print("Is the Hamiltonian still Hermitian after truncation? Answer: {}".format(H_t.isherm))
# And it still has a non-zero Hermitian part
diff = H_t - H_t.dag()
print("The norm of the anti-Hermitian part after truncation is {}".format(diff.norm()))
Code Output
Is the Hamiltonian Hermitian? Answer: True
The norm of the anti-Hermitian part is 0.0
Is the Hamiltonian still Hermitian after diagonalization? Answer: True
The norm of the anti-Hermitian part after diagonalization is 1.2427378357318259e-11
Is the Hamiltonian still Hermitian after truncation? Answer: False
The norm of the anti-Hermitian part after truncation is 6.2142895453943875e-12
Expected Behaviour
Extracting a state of states from an Hermitian operator should yield an Hermitian operator.
Bug Description
The method extract_states() of the Qobj class doesn't preserve the isherm attribute of the operators it truncates. Maybe I'm forgetting an edge case, but it seems to me that taking any subset of states from an Hermitian operator should results in an Hermitian operator.
Code to Reproduce the Bug
Code Output
Expected Behaviour
Extracting a state of states from an Hermitian operator should yield an Hermitian operator.
Your Environment
Additional Context
No response
The text was updated successfully, but these errors were encountered: