pyquil icon indicating copy to clipboard operation
pyquil copied to clipboard

Wavefunction simulator should support control of read-out map

Open mhodson-rigetti opened this issue 5 years ago • 0 comments

Pre-Request Checklist

  • [x] I am running the latest versions of pyQuil and the Forest SDK
  • [x] I checked to make sure that this feature has not already been requested

Issue Description

When using the wavefunction simulator, it is normal to omit MEASURE instructions that collapse the wavefunction. However, this means the mapping from qubit index to the bit position in the output vector (for wavefunction amplitudes and probabilities, as well as for sampled bit-strings) is determined implicitly by first use. For real circuits, especially on the Aspen-8 topology, this is seldom the correct ordering.

To date, I have worked around this by explicitly constructing a new "wavefunction simulator version" of the program that re-maps all qubit indices to new zero-based indices consistent with the index in the ro[] register. This way, the result of a QPU/QVM run becomes consistent with the wavefunction simulator (notwithstanding the bit reversal issue of https://github.com/rigetti/pyquil/issues/1258).

Proposed Solution

At the interface, I recommend the wavefunction() method (and any other affected method) be grown to support an optional readout parameter, perhaps of type List[int]. When omitted (None), the current behavior would continue, providing backward compatibility. When provided, readout[0] would identify the qubit index to be treated as if it should occupy the 0th bit position in the readout (least significant bit in the wavefunction), and so on.

Some thought may be required for the case that not all qubits present in the program are present in readout (which overlaps the feature request of tracing out subsystems of the simulation).

Additional References

Provided (attached) a notebook demonstrating the symptoms of this problem in a typical workflow.

wavefunction_simulator_mapping_issue.zip

mhodson-rigetti avatar Nov 26 '20 05:11 mhodson-rigetti