-
Notifications
You must be signed in to change notification settings - Fork 97
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] How do single gates act on Entangled Qubits? #18
Comments
This is an excellent question. Now I get to explain in more detail what the simulator is doing. let Id (qs:Qubits) =
let gate =
Gate.Build("Id",fun () ->
new Gate(
Name = "Identity",
Help = "Identity matrix for "+string(qs.Length)+" qubits",
Mat = (CSMat(pown 2 qs.Length)),
Draw = "\\gate{Id}"
))
gate.Run qs
[<LQD>]
let __UserSample() =
let ket = Ket(2, One) // Create 2 qubits in state |1>
let _ = ket.Single() // Force all qubits into a single Ket vector
// In a state dump, qubits are in PHYSICS order (NOT computer order)
// first qubit is on the left of the Ket:
// 0x0 = |00> magnitude
// 0x1 = |01> magnitude - this is the state after flipping the first qubit with an X
// 0x2 = |10> magnitude
// 0x3 = |11> magnitude - this is the initial state (both qubits are |1>)
let qs = ket.Qubits // Get the qubits in the state vector
let apply (f:Qubits -> unit) = // Execute a gate and output the resulting state
f qs // Apply the gate
let g = !< f qs // Get the gate information
show "====== After %O:" g // Print out the gate
ket.Dump(showInd) // Show the state vector to the console
apply I // Built-in identity gate to just to show the initial state vector
apply X // Flip the first qubit from |1> to |0> (goes from state 0x3 to 0x1)
apply Id // Identity on 2 qubits (system will think they're entangled)
apply X // Flip the first qubit from |0> to |1> (goes from state 0x1 to 0x3)
apply X // Flip the first qubit from |1> to |0> (goes from state 0x3 to 0x1)
apply X // Flip the first qubit from |0> to |1> (goes from state 0x1 to 0x3)
apply H // Let's end with a Hadamard on the leftmost qubit
It's basically the same code you supplied with some extra comments and a little harness to run each gate Let's walk through
First we do
You'll see that the only non-zero entry in the state vector is 0x03 (addresses are in hex) with magnitude 1. From there on, you can see the effect of each gate (Id is a noop, X keeps flipping us from state 0x03 to
Finally, I added a Hadmard to show the difference a little superposition makes:
Now we're in 0x01 and 0x03 with equal magnitude (sqrt(2)/2).
Now we see that the If we now flip the first qubit, we still know they're unentangled:
So, Now you call your 2 qubit Identity gate. Even though you and I know that it doesn't entangle anything, LIQUi|> only knows that you touched 2 qubits with a unitary... so it has to pull the
From here on, everything looks the same as the previous run since we now have a single |
Thanks Dave! So using the hex addresses the states look like they all do exactly what I'd expect. In my code I would check the qubits by using Starting with both qubits in state
But then by applying
While on the other hand if I put in
The hex address works fine as you mentioned, but the state string seems to work differently that I expected and depends on how you apply the gate. Could you elaborate? |
There's a subtle point here (that I used to miss myself all the team (even though I wrote it ;)). Take a look at the first line of each output that says Qubits (High to Low):. This is the order in which to read the qubits from left to right. LIQUi|> shuffles them all the time to be efficient in it's computations. In the second output, you got 0,0,1,0 but the qubits where in "1 0" order. So you have to view hex state 0x02 as being 0x01 (flipping the qubits back to "0 1" order. I know, this can be confusing as hell. One way around this is to use the A better choice might be to output a "fake measurement" for each qubit by doing a let apply (f:Qubits -> unit) = // Execute a gate and output the resulting state
f qs // Apply the gate
let g = !< f qs // Get the gate information
show "====== After %10s: %4.2f %4.2f" g.Name (ket.Prob1 qs.[0]) (ket.Prob1 qs.[1]) This is cheap to do (just makes believe it does a measurement) and does not perturb the system in any way. Here's what the result looks like:
|
That cleared it up, thanks again Dave. |
Saturday Mar 26, 2016 at 00:07 GMT
Originally opened as https://github.com/msr-quarc/Liquid/issues/18
I created an Identity matrix get to force qubits to be entangled, but it interacts very strangely with the built in gates. I am struggling to figure out why, because I can't take a look inside any of the built-gates.
I defined the identity gate as
I started with a 2 qubit ket set to [Zero, One], and then applied the identity gate to it. It entangles fine and shows the entangled state
(0, 1, 0, 0)
. Then I actX
on the gate to get(0, 0, 0, 1)
, again no problems, it flips the first qubit properly. But when I act withX
once more, I get(0, 0, 1, 0)
!What is the reason for this behavior? Is it because I explicitly defined the matrix in
Id
? Here is the code I ran using theId
gate.Repeating this using the CNOT gate or some other entangling gate doesn't give the same problem, so it must have to do with the way I defined the gate.
The text was updated successfully, but these errors were encountered: