rigetti / pyquil

A Python library for quantum programming using Quil.
http://docs.rigetti.com
Apache License 2.0
1.4k stars 342 forks source link

QVM <-> pyQuil Pain Points #871

Open stylewarning opened 5 years ago

stylewarning commented 5 years ago

This is a general list of issues that can be broken out into smaller issues, but I wanted to get them down.

Props to @ecpeterson for writing these. I'm just the messenger. In general, these center around how easy (or not easy) it is to use the QVM with pyQuil.

  1. QVM in density matrix mode returns density matrices when ‘wavefunction’ is requested. Should have a separate name in pyQuil, should check a different set of normalization conditions.
  2. QVM in density matrix mode offers possibility to return probability distribution. Is this call available in pyQuil? It requires different bit unpacking.
  3. QVM in stateful mode offers ‘apply for effect’. Expose this in pyQuil.
  4. Can bit unpacking be treated uniformly? Robert does ctypes casting and Erik does numpy buffers and pyQuil does struct.unpack.
  5. Where does this density matrix stuff sit relative to the QVM <: QAM vs WavefunctionSimulator split? There’s also a ReferenceDensitySimulator that doesn’t belong to this hierarchy.
  6. The Pauli heatmaps from process tomography is useful. Eric wrote some matplotlib code to generate them; he'd like to polish this for inclusion.
  7. How does one take the results of the forest.benchmarking process tomography code and extract from it data suitable for feeding into a tomograph plotter? Like there are standard methods for generating the data, but it would be nice to also have a standard munger to get it into the right form.
  8. Eric would like to include the “cheater’s process tomography” code that he wrote for use against the density matrix QVM.
  9. Polish and publish Erik’s shared memory mode starter notebook, which is very useful.
  10. Legal density matrices obey a bunch of properties (e.g., Hermitian). Make it easier to edit density matrix shared memory w/o exiting this subspace. Eric wrote something to extract a representation as a PauliSum, which was already useful for me.
  11. Expose density matrix QVM in batch mode.
  12. Eric's first attempt at generating these tomographs was to couple the forest.benchmarking code to my local QVM, and this was very slow: 5-10m for a 1% inaccurate picture of a 2Q operator. He thinks the bulk of the slowdown was in the communications layer; it would be worth profiling this and improving these repeated-call scenarios.
notmgsk commented 5 years ago
qvm = PyQVM(2)
p = Program(H(0), CNOT(0, 1), CNOT(1, 0), CNOT(1, 0), MEASURE(0, 0), CNOT(1, 0), MEASURE(1, 1))
qvm.load(p)
qvm.run()

ValueError: PyQVM can only run run-and-measure style programs: Qubit 0's last operation is a gate

notmgsk commented 5 years ago

There are QVM and QVMConnection objects. Why? When is one preferred over the other? Why does QVM.run() say it returns bitstrings when actually it returns a QVM object.

notmgsk commented 5 years ago

Why doesn't PyQVM use Wavefunction to back its wavefunction amplitudes?

notmgsk commented 5 years ago

Some work on improving pyqvm here: https://github.com/rigetti/pyquil/pull/874/files

ecpeterson commented 5 years ago

Some notes from @joshcombes about connections with forest.benchmarking:

Point 6: There are some visualization routines implemented at https://github.com/rigetti/forest-benchmarking/blob/master/forest/benchmarking/plotting/ . Could be that other visualization routines belong here too.

Point 7: There are some things along these lines: https://github.com/rigetti/forest-benchmarking/blob/superoperator-cleanup/forest/benchmarking/superoperator_conversion.py .

Point 10: Also some related things: https://github.com/rigetti/forest-benchmarking/blob/master/forest/benchmarking/random_operators.py . It would be nice if whatever was envisioned for 10 at least made contact with this.

Point 12: have u considered PyQVM

marcusps commented 5 years ago

Re: Point 6 & Point 7: Plot the Pauli Transfer Matrix representation for processes, using @joshcombes's code @ecpeterson pointed to. States should be plotted in a similar manner using The Real Density Matrix™️ representation (Pauli basis representation of the density matrix put into a matrix format). That is not in forest.benchmarking yet, but should be easy to add.

Re: Point 11: Batch mode for QPUs too, please @stylewarning . Let's make this happen.

joshcombes commented 5 years ago

Point 6: I just noticed there is also plot_pauli_transfer_matrix in https://github.com/rigetti/forest-benchmarking/blob/master/forest/benchmarking/tomography.py . I'm not saying either are great but we should probably make one great :) We should not forget the grove code too.

ecpeterson commented 5 years ago

The one in forest-benchmarking is, I think, superior to mine.

stylewarning commented 5 years ago

Re: Point 11: Batch mode for QPUs too, please @stylewarning . Let's make this happen.

@marcusps What does batch mode mean for a QPU if you can send it jobs as fast as it can process them with no competition?

stevenheidel commented 5 years ago

There are still advantages to this (as evidenced by internal usage):

For example in Python you can do something like this:

results = send_jobs_to_qpu_and_get_iterator_back(jobs)

for result in results:
     # local processing and execution will both be happening here
     process_result(result)