Open rafaeleb opened 1 year ago
Hi rafaelb. To clarify your question, are you asking if there is a way to build a circuit unitary
U = exp(-itH)
where H is some Hamiltonian of interest (e.g., the Ising model Hamiltonian)?
Hi Taylor, thanks for the reply.
That's correct, where your t would not be time but some optimisable parameter.
I believe it could be done by breaking up the Hamiltonian into a bunch of other gates, but I am wondering if there is an easier way to go about it.
Rafael
Hi Rafael,
Great, we do have such a gate class. It's called InvolutoryGeneratorUnitary
. So the signature would be:
InvolutoryGeneratorUnitary(nqubits, ncontraq, involutory_generator)
where involutory_generator
is a list of the different Pauli words in tensor form that you'd like to include. For instance, if the term that you want is ZZXZ then you would set
involutory_generator = [tlq.pauli_z(), tlq.pauli_z(), tlq.pauli_x(), tlq.pauli_z()
The one stipulation is that the terms indeed be involutory (their own inverse), but this will hold for many quantum operators used in such protocols (i.e., the Pauli strings).
Hi Taylor,
Thank you, I missed that class in the source files!
So I understand that, for the Ising Hamiltonian, it will create a ZZ term using something like
involutory_generator = [tlq.pauli_z(), tlq.pauli_z(), tlq.identity(), tlq.identity()]
where I am assuming a 4 qubit circuit. However, for each of these layers I will have an automatically generated parameter with the InvolutoryGeneratorUnitary
class. Do you have any tip on how to get the full Hamiltonian (all ZZ terms) with the same optimisable parameter? Is there an obvious way of doing that?
Hi Rafael,
Yep, you are correct, that is how you would write such a single ZZ term.
To verify that we are on the same page about your next question, what you would like to do is to write a four-qubit Hamiltonian H with all two-qubit Pauli strings in the z-basis and arbitrary coefficients such that
H = aZ0Z1 + bZ0Z2 + cZ0Z3 + dZ1Z2 + eZ1Z3 + fZ2Z3
and you would like to have a single optimization parameter gamma such that your unitary reads
U = exp(igammaH)
Is this correct?
Hi Taylor,
That's right! Ideally it would generalize it to more qubits of course, but in this simple example that is precisely the case. It seems I could get a single parameter gamma for many layers by modifying the InvolutoryGenerator class, but there might be a more natural way for it.
Appreciate the help!
Rafael
Hi Rafael,
In that case, yes, exactly, you would want to use the same parameter across the different InvolutoryGeneratorUnitaries. The reason being that we cannot add the operators and keep them involutory (their own inverse) in general, as while Z0Z1 and Z2Z3 are themselves involutory, (Z0Z1+Z2Z3)(Z0Z1+Z2Z3) != I.
A way that you might prefer would be to do the Taylor Expansion up to some power of your choosing, then using tensor sum to add the terms. We have at least one TLQ user who is doing this.
Also, for small angled rotations, you can indeed push your entire H to InvolutoryGeneratorUnitary, as the error only comes in the 2nd order terms and above and if your time evolution is small enough you can neglect these.
Hi Taylor,
Thanks for the reply! Regarding this:
that case, yes, exactly, you would want to use the same parameter across the different InvolutoryGeneratorUnitaries
The best way to do this would be through adapting the InvolutoryGenerator class to deal with several layers of unitaries? That seems like the best option to me (shouldn't be too complex, I think), but any insight here is appreciated.
Best wishes,
Rafael
Hi Rafael,
Yes, agreed, you could write a version of InvolutoryGenerator to apply several terms with the same parameter. If it's working well in your private repo and you write some test functions for it, I'd be happy to merge it to TensorLy-Quantum as well.
There may also be a method of directly feeding in the same parameter (not the data nor the clone but literally the same pointer) into the other InvolutoryGenerator instances...... this road pose some PyTorch issues though, definitely something to test.
Hi Taylor,
Thanks again for the tips! I will try to work out some solution for this and I will get back if I find something.
Rafael
Hi,
I feel confused about the API. How do I implement a general QAOA using Tensorly-Quantum? I guess I need to use TTCircuit.forward_expectation_value, but the second parameter needs to be a (matrix) hamiltonian instead of a parameterized (problem) unitary. How should I use InvolutoryGeneratorUnitary? Could you please give me an example? Thank you!
Hi nadpb,
If your Hamiltonian can be written as a sum of involutory terms, you can adapt the InvolutoryGenerator and InvolutoryGeneratorUnitary classes to include an optimizable parameter, which is what I assume you want to do with QAOA.
I have added the following classes to the tt_gates.py module to implement my version of it, see below. Hope it helps!
Hello all,
I was wondering if there is a way in TensorLy Quantum to build a parametrised unitary based on a binary Hamiltonian, such as the Ising model given in the examples, for use in the circuits.
I mean to use it in an application like a QAOA, for instance. Is there a way to adapt from the binary_hamiltonian function, or something like that?
Thanks!