moodlezoup / qdb

Breakpoint debugger for pyQuil with inserted tomography
MIT License
3 stars 0 forks source link

[feature request] Ask user to specify path in CFG #4

Open ellishg opened 5 years ago

ellishg commented 5 years ago

I had an idea for a feature that might be useful. Since we are already building the control flow graph, we can display it to the user and ask them to specify a path by listing the order of the basic blocks to execute. We can then change the program to be (almost) linear and the wavefunction should be a pure state. We won't be able to get rid of measurements and so if the measurement gives the wrong outcome we need to restart the program.

Here's an example.

H 0
CNOT 0 1
MEASURE 0
JUMP-WHEN @END 0
X 1
@END 

If the user wants to ignore the if statement, we can change this to

@START
H 0
CNOT 0 1
MEASURE 0
JUMP-WHEN @END 0
# Reset all qubits to 0
JUMP @START
@END 
# Do tomography
ellishg commented 5 years ago

After talking with Will we realized that this method works well except in the case when the desired branch is very unlikely. When that happens the tomography will take a long time since it has to try many times before it finds the right outcome. If the probability we take a branch is p, then the expected number of trials is 1/p. If we know p, maybe we can use this to determine if this is a good idea.