StationQ / Liquid

The Language-Integrated Quantum Operations (LIQUi|>) Simulator
http://StationQ.github.io/Liquid
Other
440 stars 97 forks source link

Convert qudit type CVec into type Qubits for measurement. #21

Closed ArcaneArrowX closed 8 years ago

ArcaneArrowX commented 8 years ago

Hi there, so my ultimate goal is to apply certain operations on a qudit (d-level quantum states) state. For instance, multiply the amplitude of the state |4> by a scalar. e.g. |4> to -|4>. Below is a simple code to get the equal superposition of 2^n states in a qudit CVec type.

[<LQD>]
let __UserSample(n:int) =

    let k        = Ket(n)

    let qs       = k.Qubits 

    H >< qs 

    let mutable psi = k.Single()

I couldn't see how applying operations on a specific qudit state is possible by applying gates on post-Hadamard qs (type Qubits). Post Hadamard qs for n = 3 looks something like that

image

which can be expanded into

image

So applying any kinds of gate on these qubits before using the Single() command on the k will affect other qudit states that I do not want to touch. That is why I resolved to manipulating psi of CVec type which allows me to operate on a specific qudit states.

After all the operations have been done on psi, is there a pre-defined function/gate in LiQUi|> to convert this CVec type into Qubits type to be measured?

dbwz8 commented 8 years ago

The Ket class is made of two parts:

After a ket.Single(), the CVec you get back is just a pointer to the internal storage for the Ket instance. That means that you can just use the ket.Qubits() at that point to manipulate the qubits in any way you want (e.g., apply gates to any of the qubits in the Ket).