qpp
qpp copied to clipboard
Generate an arbitrary quantum state
The regetti / grove API has this very convenient and useful function:
create_arbitrary_state()
I used to think it would be difficult to achieve that, but I am amazed a function of about a hundred lines of Python code based on a 5 page paper could transform 0 to any states with only pow(2, n+2) - 4n - 4
CNOT gates and pow(2, n+2) - 5
one-qubit elementary rotation gates.
I cannot find a similar function in the Quantum++. If it doesn't exist, I think it would be nice to implement it.
qpp
has qpp::randket()
for preparing random pure states (uniformly distributed according to the Haar measure). Are you thinking of a function that prepares random states with a low-depth/count circuit? I see now what you mean by looking at the grove API, I'll consider implementing one if time allows. But in that case the effective output of such a function should be a QCircuit
, and not really the state, as the latter is specified as input.
I am thinking of a function that prepares a desired state, preferably with a low-depth/count circuit, of course.
For example, I was trying to use QASM to present the QFT techniques for the period finding algorithm. Usually, people would have to use an oracle (a periodic function) and measurement concepts to produce an input to the function, then start from there to do the actual interesting things offered by the QFT. That seems to be an unnecessary distraction for the students.
I want to just give them an initial state as if it were an input for that periodic function. That would focus their attention on the actual period finding. It is something like this:
[1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]
(The grove
won't bother me to worry about the probability amplitudes. They will be normalized to 0.4082482905+0j
automatically.)
The grove Program
(similar to QCircuit
in Quantum++, I think) will print out the necessary info that can be processed easily to produce a QASM script that can drive the engine from 0 to the desired state described above.
OPENQASM 2.0; include "qelib1.inc";
qreg q[4]; rz(0) q[3]; h q[3]; h q[2]; h q[1]; h q[0]; swap q[3],q[0]; cx q[0],q[3]; ry(-0.339837) q[3]; cx q[0],q[3]; swap q[3],q[1]; cx q[0],q[3]; ry(0.785398) q[3]; cx q[1],q[3]; cx q[0],q[3]; ry(-0.785398) q[3]; cx q[1],q[3]; cx q[0],q[3]; cx q[1],q[3]; cx q[0],q[3]; cx q[1],q[3]; swap q[3],q[2]; cx q[0],q[3]; ry(-0.392699) q[3]; cx q[2],q[3]; ry(-0) q[3]; cx q[1],q[3]; ry(-1.1781) q[3]; cx q[2],q[3]; cx q[0],q[3]; ry(0.392699) q[3]; cx q[2],q[3]; cx q[1],q[3]; ry(-0.392699) q[3]; cx q[2],q[3]; cx q[0],q[3]; cx q[2],q[3]; cx q[1],q[3]; cx q[2],q[3]; cx q[0],q[3]; cx q[2],q[3]; cx q[1],q[3]; cx q[2],q[3];
But in that case the effective output of such a function should be a
QCircuit
, and not really the state, as the latter is specified as input.
That would be awesome, and it would be also very similar to the grove
output.
@DevelopDaily Looks useful indeed. I'll implement when I get the time :)
Could I contribute to this issue ? I should note that I'm fairly new to open source contributions and it looks like a pretty big feature, but I would be happy to try and give it all I've got and learn something myself too! :)