tensorflow / quantum

Hybrid Quantum-Classical Machine Learning in TensorFlow
https://www.tensorflow.org/quantum
Apache License 2.0
1.78k stars 571 forks source link

Support for Projectors in Expectation Calculations #357

Open MichaelBroughton opened 4 years ago

MichaelBroughton commented 4 years ago

Right now Cirq does not allow such things as:

a = cirq.Z(q0) * cirq.Z(q0) + projector(0111011001)
a.expectation_from_wavefunction(a, ...)

One must manually write out the projection operators like:

a = (1 - cirq.Z(q)) / 2 * (1 + cirq.Z(q2)) / 2 . . .

Storing such a large paulisum can quickly grow to be prohibitive despite the matrix having just one entry in the end and the post-processing step being very simple to implement on a real device. It would be nice if we could have this feature put into Cirq and then relayed up and supported in TFQ. What do people think ? @zaqqwerty .

MichaelBroughton commented 3 years ago

With the additions of https://github.com/quantumlib/Cirq/pull/4364 in the latest release of Cirq. We are now able to work on this issue.

  1. Upgrade to the latest version of Cirq.
  2. Implement serialization logic for ProjectorSums.
  3. Gradually incroporate ProjectorSum functionality in C++ ops incl. gradients.
  4. Add Projector sums to fuzz tests for ops.
tonybruguier commented 3 years ago

I am interested but I don't want to over-commit and under-deliver. Let me take a look at it and get back to you all.

For context these are the PRs: https://github.com/quantumlib/Cirq/pull/4331 (ProjectorString) https://github.com/quantumlib/Cirq/pull/4364 (ProjectorSum)

Only the first PR has made it to the current latest release: https://github.com/quantumlib/Cirq/releases/tag/v0.12.0