Closed MartinBeseda closed 2 years ago
I think you are confusing $\psi_1$ and $\psi_2$ here. Let me try to show you why:
The following script, is an adaptation of yours, which uses the ExcitedStatesEigensolver
in combination with a NumPyEigensolver
to compute the ground and all excited states of your system. It then uses the obtained Statevector
objects to evaluate all observables (the solver does this already, but I want to print things the way you did).
import numpy as np
from qiskit_nature.algorithms.excited_states_solvers import (
ExcitedStatesEigensolver, NumPyEigensolverFactory)
from qiskit_nature.converters.second_quantization import QubitConverter
from qiskit_nature.drivers import Molecule
from qiskit_nature.drivers.second_quantization import (
ElectronicStructureDriverType, ElectronicStructureMoleculeDriver)
from qiskit_nature.mappers.second_quantization import JordanWignerMapper
from qiskit_nature.problems.second_quantization import \
ElectronicStructureProblem
from qiskit_nature.transformers.second_quantization.electronic import \
ActiveSpaceTransformer
from qiskit_nature.settings import settings
if __name__ == "__main__":
settings.dict_aux_operators = True
geometry = [
("N", [0.000000000000, 0.000000000000, 0.000000000000]),
("C", [0.000000000000, 0.000000000000, 1.498047000000]),
("H", [0.000000000000, -0.938765985000, 2.004775984000]),
("H", [0.000000000000, 0.938765985000, 2.004775984000]),
("H", [-0.744681452, -0.131307432, -0.634501434]),
]
# Obtaining ground state
driver = ElectronicStructureMoleculeDriver(
Molecule(geometry), basis="sto3g", driver_type=ElectronicStructureDriverType.PYSCF
)
as_transformer = ActiveSpaceTransformer(num_electrons=2, num_molecular_orbitals=2)
es_problem = ElectronicStructureProblem(driver, transformers=[as_transformer])
converter = QubitConverter(JordanWignerMapper())
q_ops = {name: converter.convert(op) for name, op in es_problem.second_q_ops().items()}
algo = ExcitedStatesEigensolver(converter, NumPyEigensolverFactory())
res = algo.solve(es_problem)
for val, vec in zip(res.eigenenergies, res.eigenstates):
state = vec.primitive
cleaned_state_dict = {k: v for k, v in state.to_dict().items() if not np.abs(v) < 1e-6}
print(f"State: {cleaned_state_dict}")
for name, q_op in q_ops.items():
mat = q_op.to_matrix().real
res = state.data @ mat @ state.data
print(f"\t<psi|{name}|psi> = {0.0 if np.abs(res.real) < 1e-6 else res.real}")
print()
I will focus on three states:
State: {'0101': (0.943726286909139+0j), '0110': (-0.169197999288364+0j), '1001': (-0.16919799928804474+0j), '
1010': (-0.22830849627297578+0j)}
<psi|ParticleNumber|psi> = 2.000000000000001
<psi|ElectronicEnergy|psi> = -1.1709917394922589
<psi|DipoleMomentX|psi> = 0.0026004017257202448
<psi|DipoleMomentY|psi> = 0.02908727852216155
<psi|DipoleMomentZ|psi> = 1.3957696360113352
<psi|AngularMomentum|psi> = 0.0
<psi|Magnetization|psi> = 0.0
This has angular momentum 0
as expected. Note, its in-phase combination of the states 0110
and 1001
.
State: {'0011': (1+0j)}
<psi|ParticleNumber|psi> = 2.0
<psi|ElectronicEnergy|psi> = -1.169966734319283
<psi|DipoleMomentX|psi> = 0.13275615748360492
<psi|DipoleMomentY|psi> = -0.04702411665523931
<psi|DipoleMomentZ|psi> = 2.0316863985002866
<psi|AngularMomentum|psi> = 2.0
<psi|Magnetization|psi> = 1.0
State: {'1100': (1+0j)}
<psi|ParticleNumber|psi> = 2.0
<psi|ElectronicEnergy|psi> = -1.1699667343192828
<psi|DipoleMomentX|psi> = 0.13275615748360492
<psi|DipoleMomentY|psi> = -0.0470241166552393
<psi|DipoleMomentZ|psi> = 2.0316863985002866
<psi|AngularMomentum|psi> = 2.0
<psi|Magnetization|psi> = -1.0
State: {'0110': (0.7071067811865114+0j), '1001': (-0.7071067811865837+0j)}
<psi|ParticleNumber|psi> = 2.0
<psi|ElectronicEnergy|psi> = -1.1699667343192828
<psi|DipoleMomentX|psi> = 0.13275615748360492
<psi|DipoleMomentY|psi> = -0.047024116655239305
<psi|DipoleMomentZ|psi> = 2.0316863985002866
<psi|AngularMomentum|psi> = 2.0
<psi|Magnetization|psi> = 0.0
All of these have angular momentum 2
and the three magnetization terms 1, -1, 0
. The last one, is your $\psi_1$, since it has the out-of-phase combination of the terms 0110
and 1001
. Given that it is part of this triple-degenerate excited state, I hope this convinces you that the correct angular momentum for $\pi_1$ is in fact 2
.
State: {'0101': (-0.3041607957254038+0j), '0110': (-0.6357045514282725+0j), '1001': (-0.6357045514282771+0j),
'1010': (-0.3150327870721426+0j)}
<psi|ParticleNumber|psi> = 2.0000000000000018
<psi|ElectronicEnergy|psi> = -1.1029846441120226
<psi|DipoleMomentX|psi> = 0.15484054539998238
<psi|DipoleMomentY|psi> = -0.18185168359239984
<psi|DipoleMomentZ|psi> = 1.1233821369006018
<psi|AngularMomentum|psi> = 0.0
<psi|Magnetization|psi> = 0.0
Finally, we have another in-phase combination of 0110
and 1001
in this next excited state, which has again angular momentum 0
. This comes closest to your $\psi_2$.
I hope this clears up any confusion you may have had.
@mrossinek Oh, thank you very much! It is much more clear, as I got puzzled by the plus sign instead of minus one... This one is caused by the qubit ordering adopted by Qiskit, is it right?
In the Jordan-Wigner mapping case, the 4 qubits correspond to:
0101
dcba
where:
a: alpha-spin orbital of MO index 0
b: alpha-spin orbital of MO index 1
c: beta-spin orbital of MO index 0
d: beta-spin orbital of MO index 1
The reason being:
I cannot say with certainty whether this affects the sign compared to a big-endian qubit register but I do find it likely due to the systems parity.
I am closing this issue as answered :+1:
Environment
What is happening?
While testing the expectation values of $S^2$ operator, it seems, that for singlet and triplet states there are expectation values 2 and 0, respectively, while the opposite way would be expected.
The states tested:
$|\psi_1 \rangle = \frac{1}{\sqrt{2}}(|0110\rangle - |1001\rangle)$ $|\psi_2 \rangle = \frac{1}{\sqrt{2}}(|0110\rangle + |1001\rangle)$
How can we reproduce the issue?
Both the cases with their expectation values are demonstrated when running the following code:
Output:
What should happen?
I'd expect for the singlet state, i.e. $|\psi_1\rangle$ to be associated with the expectation value 0 and for $|\psi_2\rangle$ to be associated with 2.
Any suggestions?
No response