unitaryfund / qrack

Comprehensive, GPU accelerated framework for developing universal virtual quantum processors
https://qrack.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
164 stars 36 forks source link

Extend QCircuit to QInterface #988

Closed WrathfulSpatula closed 1 year ago

WrathfulSpatula commented 1 year ago

QCircuit is our new class specifying and optimizing quantum circuits before running them. It specifies all gates in terms of "uniformly controlled" gates with a single target qubit, at base. A uniformly controlled gate, acting on one qubit target, specifies a different 2x2 complex operator applied for every permutation of control qubits. For example, we can combine the effect of CNOT(0, 1) and AntiCZ(0, 1) into a single uniformly controlled gate on one target qubit: if the control qubit is in a "set" (|1>) state, then we apply a Pauli X "payload"; if the control qubit is in a "reset" (|0>) state, then we apply a Pauli Z "payload"; superposition of the control qubit leads to superposition of the "payloads" on the target qubit, entangled with the control state. (If the uniformly controlled gate is "sparse," with many fewer non-identity payloads than control combinations, then QCircuit will tend to expand the gate into controlled and "anti-controlled" gates, activated for only a single permutation of control qubits.)

This is a universal interface: all possible quantum states can be reached through some combination of these available gates. However, it's currently not easy for the user to take advantage of arithmetic logic unit ("ALU") gate decompositions already defined in QInterface. Viewing the situation from one angle, this is because QCircuit does not inherit from QInterface. If it did inherit the QInterface API, it might be necessary for QCircuit to overload the pure virtual gate methods at base of QInterface decompositions. Alternatively, QCircuit might be better off re-implementing certain decompositions from QInterface without inheriting from it.

The point of this task is to extend QCircuit to cover more of the API of QInterface, (at least ALU methods). It's probably better, for now, if QCircuit does not implement measurement operations, as this would require a mechanism for reporting measurement results from mid-circuit by the end of the circuit execution, for which we have no scaffolding, for now. (It's possible to achieve mid-circuit measurement anyway, by breaking a QCircuit into two smaller QCircuit instances on either side of a mid-circuit measurement round.)

Please, implement at least the ALU methods decomposed in QInterface, in QCircuit. (Not all ALU methods in QAlu have a decomposition in QInterface; these need not be implemented in QCircuit for now.)

stevescia commented 1 year ago

taking a look at this one

WrathfulSpatula commented 1 year ago

I'm here to help if I can, @stevescia!

stevescia commented 1 year ago

great thx! do you prefer questions and comments here on github, or the discord qrack channel? i've looked at a few different ways of addressing this issue and wanted your thoughts on a particular approach before diving too deep into it.

WrathfulSpatula commented 1 year ago

Either is fine! If it's easier, come to the Qrack channel! Otherwise, I'm here watching the repository issues, too.