corbett / QuantumComputing

This is an implementation of IBM's Quantum Experience in simulation; a 5-qubit quantum computer with a limited set of gates. Please cite me if you end up using this academically.
GNU General Public License v3.0
586 stars 141 forks source link

one major on missing some key operator like cz and one minor on readme #19

Open kwccoin opened 1 year ago

kwccoin commented 1 year ago

Minor: On the section about "Working with Individual States and gates", one minor issue is that the qc has to be either "qc.reset()" or redefine "qc = ...". I suspect the other issue can be handled.

Major: try to reproduce the circuit of teleport from quirk to composer. It can be done on the IBM openqasm 2.0 composer but not here. The issue is that there is no cz operator. I suspect one can amend these lines but not sure I am expert enough to try.

                ...
        cnot_re=re.compile('^cx (q\[[0-4]\]), (q\[[0-4]\])$')      # <-- need to change to (x|y|z)
        for l in lines:
            l=l.strip()
            if not l: continue
            # CNOT operates on two qubits so gets special processing
            cnot=cnot_re.match(l)
            if cnot:
                control_qubit=cnot.group(1)  #<-- group(2)
                target_qubit=cnot.group(2)   #<-- group(3)
                                # depends upon group(1) and feed group(1) into the function
                l='self.apply_two_qubit_gate_CNOT(%s,%s'%(control_qubit,target_qubit) #<-- major change needed
            for k,v in translation:
                l=l.replace(k,v)
            l=l+')'
            # Now running the code
            exec(l,globals(),locals())
                        ...

Somehow the cx in the first line need to increase to cover cy and cz and then apply the appropriate logic to it (the line l="..." for the "translation".

The regular expression might be easily fixed by changing into something like

cnot_re=re.compile('^c(x|y|z} (q\[[0-4]\]), (q\[[0-4]\])$')

and some change in logic of the "if cnot" so to use group 2 and 3 not 1 and 2 and use group 1 to handle cx/cy/cz

But the logic under self.apply_two_qubit_gate_CNOT is not that easy as it involved different way to handle cx/cy/cz gate change.

kwccoin commented 1 year ago

I test the change to the code

        cnot_re=re.compile('^(cx|cy|cz) (q\[[0-4]\]), (q\[[0-4]\])$')
        for l in lines:
            l=l.strip()
            if not l: continue
            # CNOT operates on two qubits so gets special processing
            cnot=cnot_re.match(l)
            if cnot:
                control_qubit=cnot.group(2)
                target_qubit=cnot.group(3)

It should be fine of course that means cy and cz now all cx which is not right.

However to do cy and cz require touching the Gate Class. A lot of not sure about this why there is a need to change basis (see wiki CNOT especially the one on 2 bit using H as its own inverse (See (H1 ⊗ H1)−1 . CNOT . (H1 ⊗ H1)) to H2 . CNOT . H2 which is in the logic. But why CNOT 0->1 use simple logic and CNOT 1-> 0 not. Still working on it. Also the whole class is handcrafted; need some programming as said in the "TODO" section but that is 7 years ago.

Possibly above my "pay grade"!