qiskit-nature icon indicating copy to clipboard operation
qiskit-nature copied to clipboard

UCC: `generalized=True` has no effect when `preserve_spin=False`

Open bsenjean opened this issue 2 years ago • 3 comments

I am using the generalized UCCD ansatz and I noticed that I got the same result as without the generalized option. I am sharing a minimal example here, with explanations below.

  • Qiskit version: 0.21.1
  • Qiskit_nature version: 0.4.4
  • Python version: 3.9
  • Operating system: Ubuntu

What is the current behavior?

As far as I can see, the operators generated by the GUCCD ansatz and the UCCD ansatz are the same. They both depends on the number of particles, based on the initial Hartree-Fock state, while GUCCD should ignore those informations.

Steps to reproduce the problem

import qiskit, qiskit_nature
from qiskit import QuantumCircuit
from qiskit_nature.converters.second_quantization import QubitConverter
from qiskit_nature.circuit.library import UCC
from qiskit_nature.mappers.second_quantization import JordanWignerMapper

print(qiskit.__version__)
print(qiskit_nature.__version__)
# System:
n_spinorbs     = 6
n_alpha        = 2
n_beta         = 2
n_particles    = (n_alpha,n_beta)

jw_mapper = JordanWignerMapper()
jw_converter = QubitConverter(jw_mapper)
circuit = UCC(qubit_converter=jw_converter, num_particles=n_particles, num_spin_orbitals=n_spinorbs, excitations='d', alpha_spin=True, beta_spin=True, max_spin_excitation=None, generalized=False, preserve_spin=False, reps=1, initial_state=None)
n_param = circuit.num_parameters
fermionic_operators = circuit.excitation_ops()

print(n_param)
for op in fermionic_operators:
  print(op.to_list(display_format='sparse'))

circuit = UCC(qubit_converter=jw_converter, num_particles=n_particles, num_spin_orbitals=n_spinorbs, excitations='d', alpha_spin=True, beta_spin=True, max_spin_excitation=None, generalized=True, preserve_spin=False, reps=1, initial_state=None)
n_param = circuit.num_parameters
fermionic_operators = circuit.excitation_ops()

print(n_param)
for op in fermionic_operators:
  print(op.to_list(display_format='sparse'))

This results in the following:

0.21.1
0.4.4
6
((0, 1), (2, 5))
((0, 3), (2, 5))
((0, 4), (2, 5))
((1, 3), (2, 5))
((1, 4), (2, 5))
((3, 4), (2, 5))
6
((0, 1), (2, 5))
((0, 3), (2, 5))
((0, 4), (2, 5))
((1, 3), (2, 5))
((1, 4), (2, 5))
((3, 4), (2, 5))

What is the expected behavior?

As one can see, the excitations only goes from spin-orbitals 0,1 and 3,4 to 2 and 5. According to the labelling in qiskit, this means that we have the original state written as follow: | 0_up 1_up 2_up 3_down 4_down 5_down > where 0_up 1_up 3_down 4_down are occupied, and 2_up and 5_down are empty. Which is why we only see those excitations in UCCD. But in GUCCD it should not be the case, we should have excitations/deexcitations on other spin-orbitals, regardless of their occupation.

Is it possible that this option is ignored ?

bsenjean avatar Aug 16 '22 13:08 bsenjean

@mtreinish Can I ask you to xfer this to Qiskit Nature pls.

woodsp-ibm avatar Aug 16 '22 14:08 woodsp-ibm

You are using the non-default setting preserve_spin=False. When using preserve_spin=True, generalized=True is indeed working as expected. However, the combination generalized=True + preserve_spin=False appears to indeed be not working as intended. I will update the title accordingly :+1:

mrossinek avatar Aug 16 '22 17:08 mrossinek

It looks like I had already made a previous attempt at fixing this a while ago (#747) but I realized now, that PR was not implementing things as intended. I opened a new PR which addresses this issue :+1:

mrossinek avatar Aug 16 '22 19:08 mrossinek