Skip to content
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

[CLOSED] Hamiltonian Gates #9

Closed
dbwz8 opened this issue Apr 1, 2016 · 5 comments
Closed

[CLOSED] Hamiltonian Gates #9

dbwz8 opened this issue Apr 1, 2016 · 5 comments

Comments

@dbwz8
Copy link

dbwz8 commented Apr 1, 2016

Issue by rumschuettel
Saturday Jan 30, 2016 at 13:42 GMT
Originally opened as https://github.com/msr-quarc/Liquid/issues/9


Hi! Brief question: in Hamiltonian mode, one can use gates such as ZR or ZZR to couple spins. What if I want to use a coupling that's Hermitian but not necessarily unitary, e.g. a projector? I tried creating a projector on |11> for the first 2 qubits out of 4 by defining a custom gate with a diagonal matrix with 1s in the corresponding entry and 0 everywhere, which is not unitary - the simulation somewhat works, but the normalization is now totally off:
0:0000.0/Ket of 4 qubits: 0:0000.0/=== KetPart[ 0]: 0:0000.0/Qubits (High to Low): 0 1 2 3 0:0000.0/0x00000000: 2.1601667977e-05 0:0000.0/0x00000001: 2.1601667977e-05 0:0000.0/0x00000002: 2.1601667977e-05 0:0000.0/0x00000003: 2.1601667977e-05 0:0000.0/0x00000004: 1.14743224743e-05 0:0000.0/0x00000005: 1.14743224743e-05 0:0000.0/0x00000006: 1.14743224743e-05 0:0000.0/0x00000007: 1.14743224743e-05 0:0000.0/0x00000008: 1.14743224743e-05 0:0000.0/0x00000009: 1.14743224743e-05 0:0000.0/0x0000000a: 1.14743224743e-05 0:0000.0/0x0000000b: 1.14743224743e-05 0:0000.0/0x0000000c: 1.48433500775e-10 0:0000.0/0x0000000d: 1.48433500775e-10 0:0000.0/0x0000000e: 1.48433500775e-10 0:0000.0/0x0000000f: 1.48433500775e-10
So one can see that indeed the states with 1100, 1101, 1110 and 1111 have the least amplitude (as expected), but the overall probabilities don't add up to 1.

Any hint would be appreciated.
Thanks!
J.

@dbwz8
Copy link
Author

dbwz8 commented Apr 1, 2016

Comment by dbwz8
Sunday Jan 31, 2016 at 01:00 GMT


This isn't really supported... but if you do a non-unitary gate, you will need to normalize the state vector yourself. First call let vec = ket.Single() which will pull any separate pieces of your state vector (ket) together into a single one and more importantly, will give you a handle to the actual state vector instance (vec). Then you can normalize it with vec.Normalize(). No guarantees, but I'd try this first and see if it gives you what you want.

Note that this will only work in function mode. If you compile to a circuit (Circuit.Compile) you will have no way to do the normalization (not strictly true... but let's first try to get it working the simple way ;)

@dbwz8
Copy link
Author

dbwz8 commented Apr 1, 2016

Comment by dbwz8
Sunday Jan 31, 2016 at 20:11 GMT


Actually, why can't you just use a joint measurement gate (Liquid.chm/Operations/JM)? If you call JM "" "XYZ" qs, this will do a joint measurement where the first qubit is measured in X, the second in Y and the third in Z (any number of qubits and combinations of X,Y and Z). For example:

JMz "3qs" !!(qs,1,3,4)

will do a joint Z basis measurement on qubits 1, 3 and 4. This will do the projection correctly (and keep everything normalized).

As an added bonus... now there's no restriction on building circuits and drawing/optimizing them. The first string can be any tag that you'd like to see in the drawing. The actual gate name for the example above would be JMz_{3qs} (JMz with a subscript of your tag).

@dbwz8
Copy link
Author

dbwz8 commented Apr 1, 2016

Comment by rumschuettel
Sunday Jan 31, 2016 at 20:18 GMT


Good idea, but I don't think that would achieve what I'm trying to do. Assume I'm only simulating one qubit, and the 1-local interaction on it is something like H = | 1 >< 1 |, i.e. a projector on 1. Then the ground state of H as simulated by Spin.Test should be | 0 >.
If I simply measure the qubit in, say, the Z direction, that would force the state to collapse to either | 0 > or | 1 > . I guess that means I'd have to create measurement statistics and throw away the ones with | 1 >?

Thanks for the reply btw!

@dbwz8
Copy link
Author

dbwz8 commented Apr 1, 2016

Comment by dbwz8
Sunday Jan 31, 2016 at 20:25 GMT


I agree. What you're doing (for what you want) is probably the best way. The other thing you could do is to just get the complex state vector (with ket.Single()) and then do whatever math you like on it (since you're probably going to throw it away at that point anyway). One other thing to mention... if you don't want to destroy the state vector (and have it correctly normalized), you can always do a ket.Prob1(qubit), which will return the probability of measuring a 1 if you had done a measurement at this point. If you need all joint probabilities, you can just call the ket.Probs(qubits) routine with up to 10 qubits and then read off the probabilities of all possible measurement results. Both of these are non-destructive.

@dbwz8
Copy link
Author

dbwz8 commented Apr 1, 2016

Comment by rumschuettel
Sunday Jan 31, 2016 at 20:52 GMT


Perfect, thanks a lot Dave! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants