We are going to build our universal quantum computer in a slightly different way.
Suppose I have my simulator and it's storing my state like this:
myState=[
(numpy.sqrt(0.1), '00'),
(numpy.sqrt(0.4), '01') ,
(-numpy.sqrt(0.5), '11' )
]
Go ahead and implement some functions that eat your state, apply a gate, and give out a new state
1 2 3 |
|
To accomplish this, just go ahead and loop through you old state and apply the gate to every element of your old state:
1 2 3 |
|
(it's actually faster if you do this by loop comprehensions [newState(element) for element in inputState]
Don't worry if you end up having some duplicate states (like below)
myState=[
(-numpy.sqrt(0.25), '11' )
(numpy.sqrt(0.1), '00'),
(numpy.sqrt(0.4), '01') ,
(-numpy.sqrt(0.25), '11' )
]
Now just write some code which takes the state and removes duplicates (i.e. myState=RemoveDuplicates(myState)
should give
myState=[
(numpy.sqrt(0.1), '00'),
(numpy.sqrt(0.4), '01') ,
(-numpy.sqrt(0.5), '11' )
]
Make sure you remove any term which has an amplitude zero.
Now you have a simulator where you can start with some state, apply a gate, remove duplicates, apply a state, etc.
Grading | |
---|---|
Run this new simulator on the typical suite of tests and paste the results into the document. |