Read classical registers while keeping the wavefunction
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 358
- Avg merge
- 1d 58m
- Merged PRs (30d)
- 4
Description
In pyQuil < 2.0, it was possible to simulate postselection when simulating wavefunctions, with codes of this style:
from pyquil import Program
from pyquil.api import QVMConnection
from pyquil.gates import *
state_prep = Program(H(0))
state_prep += I(1)
state_prep.measure(0, 0)
conditional_bit = 0
qvm = QVMConnection()
finished = False
while not finished:
wf = qvm.wavefunction(program.if_then(conditional_bit, I(0)), [conditional_bit])
finished = wf.classical_memory[conditional_bit]
# Here would come other operations with wf, which is now postselected on the first qubit being |1>.
I have not managed to reproduce this type of program with pyQuil 2.3. The most similar solution (that is quite specific) that I have found is the following:
from pyquil import Program
from pyquil.api import QVMConnection
from pyquil.gates import *
conditional_bit = 0
state_prep = Program(H(0))
c = cr.declare('ro', 'BIT', 1)
state_prep += MEASURE(0, c[conditional_bit])
qvm = QVMConnection()
finished = False
while not finished:
wf = qvm.wavefunction(program.if_then(('ro', conditional_bit), I(0)))
finished = (abs(wf.amplitudes[0]) < 1e-10)
# Here would come other operations with wf, which is now postselected on the first qubit being |1>
So, ultimately my question is, is there a standard way to access classical registers from outside a Quil program?
Thank you
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with QVMConnection.wavefunction and the Program, MEASURE, and classical_memory usage shown in the issue. Trace how classical registers are handled outside a Quil program and determine what standard access should look like; done requires a decided API behavior and corresponding documentation or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100