QuEST-Kit / QuEST

A multithreaded, distributed, GPU-accelerated simulator of quantum computers
https://quest.qtechtheory.org/
MIT License
401 stars 138 forks source link

New feature: sqrt Pauli gates #102

Open TysonRayJones opened 5 years ago

TysonRayJones commented 5 years ago

E.g. sqrtPauliX = rotateX(pi/2), but avoids using pi or evaluating transcendentals. This might as well be added, since these functions are to exist to implement #97 They're generally useful for a user for changing basis

bmarco82 commented 2 years ago

Hello, I am also interested in using sqrt(X) and sqrt(Y) gates. I am wondering if these have been implemented, even in a non-public version, and/or if it's difficult to patch the code to add them. Thank you!

TysonRayJones commented 2 years ago

Hi Marco,

Explicit sqrt pauli gates were ultimately unnecessary and were not added in the end. They can of course be simply effected using rotations.

// effects exp(i M_PI/4) sqrt(X)
rotateX(qureg, qubit, M_PI/2);

// effects exp(i M_PI/4) sqrt(Y);
rotateY(qureg, qubit, M_PI/2);

Note these also effect an arbitrary phase-factor of exp(i M_PI/4), hence controlled rotations will not effect controlled sqrt-gates.

If you need controlled sqrt gates, you can simply specify them element-wise, and use functions like unitary().

ComplexMatrix2 sqrtX = {
    .real = {{.5, .5}, 
             {.5, .5}},
    .imag = {{.5, -.5}, 
             {-.5, .5}}};

ComplexMatrix2 sqrtY = {
    .real = {{.5, -.5}, 
             {.5, .5}},
    .imag = {{.5, -.5}, 
             {.5, .5}}};

unitary(qureg, qubit, sqrtX);
controlledUnitary(qureg, ctrl, targ, sqrtY); 

I hope this helps in the near-term!

TysonRayJones commented 3 weeks ago

Bespoke gates remain frivolous; however, it may be convenient to provide matrix-getters for things like sqrt. E.g. CompMatr1 b = getCompMatr1Sqrt(a)