Skip to content

Latest commit

 

History

History
executable file
·
114 lines (97 loc) · 3.8 KB

Bases.md

File metadata and controls

executable file
·
114 lines (97 loc) · 3.8 KB

Basis

A basis serves for 2 things:

  • To measure
  • To represents quantum states

Measurement

Measure something means that:

  • the internal state of the measured quantum state changes
  • returns the eigenvalue associated to the eigenstate measured

To measure a quantum state exists 2 way:

  1. Call the measure(basis) method:

    q = qbit(1,2, normalize=True) # +0.44721|0> +0.89443|1>
    r = q.measure(stdbasis) # measure using stdbases
    print(r, q) #probably "(1+0j) +1|1>"
  2. Use the | operator:

    q = qbit(0,1) # |1>
    r = hadamard | q
    print(r, q) #"(1+0j) +0.70711|0> +0.70711|1>" or "(-1+0j) +0.70711|0> -0.70711|1>"

Representation

A representation of a quantum state depends on which basis we use to "watch it"

If you print a quantum state it will be represented in the Bra-ket notation using a basis:

>>> q = qbit(1,0)
>>> q.printAs(stdbasis)
"+1|0>"
>>> q.printAs(hadamard)
"+0.70711|+> +0.70711|->"

Any quantum state have an associated basis that work as a "default" basis to use when you don't specify it:

q = qbit(1,0, basis=hadamard) #from now the default basis of this qubit will be hadamard
q.measure() #measure using the hadamard basis
print(q) # +1|->

This approach gain utility when used with multiple qubit state:

q = qbit(1,0) @ qbit(1,0, basis=hadamard)
print(q) # +0.70711|0+> +0.70711|0->

 

Built-in basis:

  • stdbasis: the default and most used basis {|0>, |1>}
  • hadamard: {|+>, |->} where |+> = 1/√2(|0>+|1>) and |-> = 1/√2(|0>-|1>)
  • bell: {|Φ+>, |Ψ+>, |Ψ->, |Φ->} (first time you see it?)

Basis creation

A basis is described by a set of vectors (or by a matrix but you know thai are the same things) and in logiq you can create your own basis just specifying the vectors you want to use as a basis.

For instance if you want to create a basis that have different eigenvalue (because stdbasis.ew = [1,1]) you can do this:

myBasis = Basis([
    [1,0],
    [0,-1]
])
print(myBasis.ew) # [(1+0j), (-1+0j)]

So with this basis you can measure without cheating

q = Qstate.random(2)
r = q.measure(myBasis)
print(r) # if r = 1 then q = |0> else q = |1>

Be carefully now, i said that if the result of the measurement is -1 it means that the qubit was collapsed in the status |1>, but which basis I use to say that?

Indeed if r = -1 and we print the status of q it will be represent using stdbasis because when we had create this qubit we hadn't specify the "default" basis!

print(q) # -1|1>
print(q.printAs(myBasis)) # +1|1>

But why the qubit "viewed" as myBasis = |1> = -1|1> = the same qubit "viewed" as stdbasis?
Of course because wh hadn't specify the symbols for the states of myBasis!

print(myBasis)
# |0>: |(1+0j); 0j>
# |1>: |0j; (-1+0j)>
print(stdbasis)
# |0>: |(1+0j); 0j>
# |1>: |0j; (1+0j)>

As you can see stdbasis and myBasis use the same symbols for different states.

To avoid this you can use different symbols for the basis you declare:

myBasis = Basis([
    [1,0],
    [0,-1]
], 'ab')
print(myBasis)
# |a>: |(1+0j); 0j>
# |b>: |0j; (-1+0j)>

In this way, you avoid misunderstands when printing the state of a quantum state.

You can also create a basis only to represent quantum states in a different way, for example if you want to "work" with electron spin and you prefer to represent a state not in term of |0> and |1> but with |up> and |down> states, you can easily do that using a CanonBasis:

eBasis = CanonBasis(2, ['up','down']) #basis with 2 eigenstate and their symbols
e = qbit('|up>', basis=eBasis)
print(e) # +1|up> (extra life! 🍄)