goodchemistryco / Tangelo

A python package for exploring end-to-end chemistry workflows on quantum computers and simulators.
https://goodchemistryco.github.io/Tangelo/
Other
99 stars 27 forks source link

Circuit as reference state in the ansatz definition #384

Closed alexfleury-sb closed 1 month ago

alexfleury-sb commented 1 month ago

Circuit as reference state in the ansatz definition

What problem does this feature request help you overcome?

In our stack of Ansätze, located in toolboxes/ansatz_generator, most of them take a string reference_state as an initialization parameter. This determines the reference state of the ansatze, which is commonly HF for an Hartree-Fock state or zero for an empty circuit. As an example, here is the code that handles the reference_state for the toolboxes.ansatz_generator.uccsd.UCCSD ansatz.

https://github.com/alexfleury/Tangelo/blob/9079cb2e8c4b893027a7ff70101e968548000714/tangelo/toolboxes/ansatz_generator/uccsd.py?plain=1#L136-L153

This is restrictive in situations where non-conventional mapping are used, i.e. where HF has no meaning.

Describe the solution you'd like

A workaround would be to add support for a tangelo.linq.circuit.Circuit objects as a reference state. Logics have to be implemented to handle the right number of qubits in some edge cases, and to consider optimization (or not) if the reference circuit contains variational gates.

For some ansatze, it would remove the need of specifying the mapping and up_then_down parameters, as they are only used for reference state preparation.

As a minimal use-case, exploring combinatorial mapping optimization could be easier if this option is available. For e.g., if the code below could work without error, it would be awesome!

from tangelo.molecule_library import mol_H2_sto3g
from tangelo.toolboxes.qubit_mappings import combinatorial
from tangelo.toolboxes.operators import count_qubits
from tangelo.linq import Circuit, Gate
from tangelo.toolboxes.ansatz_generator import HEA

H = combinatorial(mol_H2_sto3g.fermionic_hamiltonian, mol_H2_sto3g.n_active_mos, mol_H2_sto3g.n_active_electrons)
n_qubits = count_qubits(H)

ref_circ = Circuit([Gate("RY", 0, parameter=0.5), Gate("RY", 1, parameter=-0.5)])
ansatz = HEA(n_qubits=n_qubits, n_layers=2, reference_state=ref_circ)
ansatz.build_circuit()
cburdine commented 1 month ago

Hi @alexfleury-sb and @ValentinS4t1qbit ,

I think this would be a good issue for me to work on, but I am in need of clarification on some of the details for this proposed enhancement. Here are a few questions that come to mind:

I'll keep looking at this issue and let you know if I have any further questions. Thanks! :atom_symbol:

alexfleury-sb commented 1 month ago

Hello @cburdine, here are my thoughts:

I hope I gave you enough information to get started. If not, I am happy to elaborate more!

cburdine commented 1 month ago

Thanks for the clarification @alexfleury-sb! I think I'll start working on this issue. Can you go ahead and assign it to me?

cburdine commented 1 month ago

@alexfleury-sb, I have a question related to the ILC and QCC ansatzes, both of which require a QMF state circuit. Since these ansatzes allow for a user to define a QMF circuit in their constructors (via the argument qmf_circuit), how should these ansatzes behave when a Circuit object is passed as the reference_state argument?

I could simply override the value of qmf_circuit with the reference_state Circuit, however this requires that the variational parameters in qmf_circuit must be retained.

This would differ from the behavior of the other ansatzes, where variational gates in reference_state are converted to non-variational gates. It this acceptable? Or, do you have another idea for how you would like me to handle these ansatzes?

(Edited for clarity)

alexfleury-sb commented 1 month ago

Hello again @cburdine, I think your solution is perfectly reasonable. The only thing I would request is an explanation of this in the docstring and in code comments, as it is different from the common behaviour.

ValentinS4t1qbit commented 1 month ago

Thank you so much for your contribution @cburdine

Please do not hesitate if you're interested in working on this project more, or have any feedback for us now that you're acquainted with 🍊 Tangelo 🍊 . Do not hesitate to mention the project around you if you think students or researchers may benefit from it. The package was designed for chemistry simulations but a lot of content can be readily applied to various topics.