Closed salperinlea closed 11 months ago
To clarify use case, the reason for initializing in this fashion is due to the necessity of include multiplicity info. An attempt to directly manifest a tq.Molecule object for atoms like lithium will fail due to spin;
tmol=tq.Molecule("Li 0 0 0",basis_set=basis,backend='pyscf')
will fail with relevant traceback
RuntimeError: Electron number 3 and spin 0 are not consistent
Note mol.spin = 2S = Nalpha - Nbeta, not 2S+1
Hi Sumner, thanks for noticing. I forgot that the function exists. Should be fixable, but will take some time.
It is probably more convenient to initialize a charged molecule and construct circuits accordingly in the symmetry sector you aim for. Below this is illustrated of lithium. Setting the charge affects only the standard methods and interface to classical methods (that would not be available no matter what, as they all require closed-shell).
import tequila as tq
import numpy
geom="Li 0.0 0.0 0.0"
dummy = tq.Molecule(geometry=geom, basis_set="sto-6g", charge=1, frozen_core=False)
# not necessary
# switch to orthonormalized atomic orbitals
# will most likely have little to no effect on Li
dummy = dummy.use_native_orbitals()
# charge does not affect 2nd quantized Hamiltonian
H = dummy.make_hamiltonian()
v,vv = numpy.linalg.eigh(H.to_matrix())
print("Li ground state")
print(tq.QubitWaveFunction(vv[:,0]))
# can not use: dummy.prepare_reference (will create the charge+1 reference)
# should not use: dummy.make_ansatz() | all predefined ansatz schemes are taylored for closed-shell
# can still do manual stuff
U = tq.gates.X([0,1,2])
U+= dummy.UC(0,3,angle="a")
U+= dummy.make_excitation_gate(indices=[(0,4),(1,3),(2,6)],angle="b")
print(tq.simulate(U, variables={"a":1.0, "b":1.0, "c":1.0}))
Thanks for the quick reply Jacob. Above example works, but errors out if charge is set to 0, as expected.
My ultimate goal is to get UCC circuits with CCSD amplitudes for a swath of neutral atoms; I think this should be possible by a mix of tequila code and some hand-crafting from pyscf directly.
Yes, that would be the way to go. Get amplitudes from pyscf and circuits from tq. For the circuits it doesn't matter what the charge is, just make sure to create the right initial state.
Thats why charge is set to one in the example above. You create a dummy molecule that is closed shell, but otherwise the same. In the example above, the ground state is the neutral ground state and the circuit creates a 3 electron wavefunction.
I put it on the todo, to allow for general charges and multiplicities, but it will take a while.
Describe the bug attempts to get tequila "molecule" objects via the tq.MoleculeFromOpenFermion fail due to an error essentially related to typing. OpenFermion accepts initialization of MolecularData objects via lists of lists of (string, list) as geometries (that is, xyzfiles can be bypassed), but tequila is expecting a string to be the source of the geometry, leading to an error when the .split method is invoked. Stacktrace below:
To Reproduce Steps to reproduce the behavior: Ideally an executable code snipped like
Expected behavior The above code should run without issue, as should any further uses of the object created thereby.
Computer : OS is Arch Linux, latest kernel.
tequila version: 1.8.9 python version: 3.8.17 | packaged by conda-forge | (default, Jun 16 2023, 07:06:00) [GCC 11.4.0] platform: #1 ZEN SMP PREEMPT_DYNAMIC Thu, 21 Sep 2023 12:54:31 +0000