-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Structures for F3 circuit optimizations #303
Conversation
Hi Praveen, |
Hey Jakob, |
Amazing. Looks like you figured it out. I will merge for now as I think the changes work as intended. The Measurement optimization methods are currently not using the standard quantum chemistry library from tequila, were we have mol1 = tq.Molecule(geometry, transformation="JordanWigner") # default
mol2 = tq.Molecule(geometry, transformation="ReversedJordanWigner")
H1 = mol1.make_hamiltonian() # in std JW
H2 = mol2.make_hamiltonian() # in Reversed order JW with corresponding changes, the current changes (and also more of the functionality currently implemented for the grouping exclusively) could be introduced in the quantum chemistry classes, like this U1 = mol1.make_orbital_rotation_circuit(matrix) # default of method is "naive"
U2 = mol2.make_givens_rotation_circuit(matrix) # default of method is "short"
U3 = mol1.make_orbital_rotation_circuit(matrix, method="short") # will raise Exception (not supported for standard JW, same for Molecules with BravyiKitaev) The base class for the QuantumChemistry structures is here (probably useful to see: I think an initial integration would look like class QuantumChemistryBase:
...
...
def make_orbital_rotation_circuit(self, matrix, method=None, *args, **kwargs):
if method is None:
method="naive"
if self.transformation.up_then_down:
method="short"
if "jordan-wigner" in self.transformation.name.lower():
return get_orb_rot(matrix, method = method, *args, **kwargs):
else:
raise NotImplementedError("orbital rotation circuit not implemented for {}\n assemble yourself with mol.make_UR(...)".format(self.transformation) )
In a second step one would need to step-by-step absorb the fermionic functionality from the grouping techniques into the QuantumChemistryBase class, and then use an object for this class for the grouping functionality. @schoi839 flagging you here, since some of the changes might impact some of your work. |
Let me know if that makes sense (comment above) or if you have questions |
Hey Jakob, apologies I forgot to get back to this earlier. Your suggestions make sense. The depth option "short" is only a reordering of the rotations and can be used as such. I had a conversation with Seonghoon and we believe it's best left as it is at the moment as it's very specific to user implementation and best not tamper with the spin-orderings. We can leave it to the user to modify as required. |
No worries, there wasn’t any hurry. I merged already, in that case we leave it like this, and I keep it in mind, in case anyone ever asks about this functionality. The necessary tools are now there thanks to you :-) |
Currently the F3 circuit has O(N^2) depth and circuit gate count. Added in this commit:
Further reduction can be achieved as follows:$N(N-1)/2$ such eliminations/Givens rotations for a N orbital system. Each givens rotation is between adjacent qubits only and are efficient in terms of gates.
A general mean-field unitary U is decomposed into givens rotations, determined by eliminating off-diagonal elements in the matrix representation of U. For N orbitals, we have
For Hamiltonians over 2N spin-orbitals, the Unitaries U constructed for F3 fragments, except the first one body fragment currently are spin-restricted by default. This means that the matrix representation of U has a block-diagonal form, i.e.,$U = U_u * U_d$ can be written as a product of mean-field unitaries over spin up/down sectors separately. But in order to implement $U_u$ and $U_d$ efficiently by givens rotations over adjacent qubits, we would require either the fermion ordering to be uudd and not udud (default) (or) a different modified jordan-wigner. The F3 routines currently can be directly adapted by simply relabelling the final outputted tensors and unitaries, but this reordering would require the user to use state-preparation with a different qubit ordering/mapping, and start with the Hamiltonian with fermions/spins reordered.
I'm not sure how to proceed with adding this as tequila mostly uses spin udud as in openfermion and might mean changes up-stream (it's not clear what parts of the workflow would this affect).