Search code examples
simulationquantum-computing

ProjectQ- In which part of the controlled gate object are the control bits scored


I've been trying to decompose the projectQ objects and I could manage to decompose non controlled gates, and daggered gates. But I noticed that the object of a controlled version of a gate is the exact same as the object of that gate.

The code generating these objects:

  eng = MainEngine()
  q = eng.allocate_qubit()
  p = eng.allocate_qubit()
  c = eng.allocate_qubit()
  X | q
  CNOT | (p,q)

This is the XGate object

{'_control_qubits': [],
 '_engine': <__main__.MainEngine object at 0x7fc323e4d198>,
 '_qubits': ([<projectq.types._qubit.WeakQubitRef object at 0x7fc30b0a3ef0>],),
 'gate': <projectq.ops._gates.XGate object at 0x7fc316778048>,
 'tags': []}

And this is the CNOT gate, which is the same as ControlledGate(XGate)

{'_control_qubits': [],
 '_engine': <__main__.MainEngine object at 0x7fc323e4d198>,
 '_qubits': ([<projectq.types._qubit.WeakQubitRef object at 0x7fc30b0b1080>],),
 'gate': <projectq.ops._gates.XGate object at 0x7fc316778048>,
 'tags': []}

Both have no control qubits and it seems like the control gates lost the control qubit.

Any idea on where the control qubit is stored?


Solution

  • The control qubits are only added to the command after it is received by the ControlEngine further down the chain after the MainEngine. For implementation details see "3.2.1 Implementation of meta instructions" here.

    To implement a testing engine such as this one, that can be used to check that indeed control qubits are added right after the MainEngine, you could do the following:

    test_eng = Testing(BasicEngine) # Or CommandPrinter
    eng = projectq.MainEngine(engine_list=[test_eng])