rigetti / forest-benchmarking

A library for quantum characterization, verification, validation (QCVV), and benchmarking using pyQuil.
Apache License 2.0
53 stars 22 forks source link

Upgrade to PyQuil v4 #237

Closed jselig-rigetti closed 9 months ago

jselig-rigetti commented 1 year ago

Description

Closes #236

Update pyquil to v4 and refactor for compatibility.

jselig-rigetti commented 1 year ago

The test_estimate_observables_symmetrize_calibrate is failing because calibrate_observable_estimates calls qc.run_symmetrized_readout with an empty program made by get_calibration_program.

Two questions:

  1. Is it expected that get_calibration_program should return an empty program?
  2. Is it expected that qc.run_symmetrized_readout should accept empty programs, or if not, can observables that produce empty programs be ignored?

Running locally, here's an example of observable to program:

{
    "(1+0j)*Z1": "",
    "(1+0j)*Y0*X1": "RX(-1.5707963267948966) 0\nRX(1.5707963267948966) 1\nRZ(1.5707963267948966) 1\nRX(-1.5707963267948966) 1\nRX(1.5707963267948966) 0\nRX(1.5707963267948966) 1\nRZ(-1.5707963267948966) 1\nRX(-1.5707963267948966) 1\n",
    "(1+0j)*Y1": "RX(-1.5707963267948966) 1\nRX(1.5707963267948966) 1\n",
    "(1+0j)*X1": "RX(1.5707963267948966) 1\nRZ(1.5707963267948966) 1\nRX(-1.5707963267948966) 1\nRX(1.5707963267948966) 1\nRZ(-1.5707963267948966) 1\nRX(-1.5707963267948966) 1\n",
    "(1+0j)*I": "",
    "(1+0j)*X0*X1": "RX(1.5707963267948966) 0\nRZ(1.5707963267948966) 0\nRX(-1.5707963267948966) 0\nRX(1.5707963267948966) 1\nRZ(1.5707963267948966) 1\nRX(-1.5707963267948966) 1\nRX(1.5707963267948966) 0\nRZ(-1.5707963267948966) 0\nRX(-1.5707963267948966) 0\nRX(1.5707963267948966) 1\nRZ(-1.5707963267948966) 1\nRX(-1.5707963267948966) 1\n",
    "(1+0j)*X0*Y1": "RX(-1.5707963267948966) 1\nRX(1.5707963267948966) 0\nRZ(1.5707963267948966) 0\nRX(-1.5707963267948966) 0\nRX(1.5707963267948966) 1\nRX(1.5707963267948966) 0\nRZ(-1.5707963267948966) 0\nRX(-1.5707963267948966) 0\n",
    "(1+0j)*X0*Z1": "RX(1.5707963267948966) 0\nRZ(1.5707963267948966) 0\nRX(-1.5707963267948966) 0\nRX(1.5707963267948966) 0\nRZ(-1.5707963267948966) 0\nRX(-1.5707963267948966) 0\n",
    "(1+0j)*Y0": "RX(-1.5707963267948966) 0\nRX(1.5707963267948966) 0\n",
    "(1+0j)*Y0*Y1": "RX(-1.5707963267948966) 0\nRX(-1.5707963267948966) 1\nRX(1.5707963267948966) 0\nRX(1.5707963267948966) 1\n",
    "(1+0j)*Z0*X1": "RX(1.5707963267948966) 1\nRZ(1.5707963267948966) 1\nRX(-1.5707963267948966) 1\nRX(1.5707963267948966) 1\nRZ(-1.5707963267948966) 1\nRX(-1.5707963267948966) 1\n",
    "(1+0j)*Y0*Z1": "RX(-1.5707963267948966) 0\nRX(1.5707963267948966) 0\n",
    "(1+0j)*Z0*Y1": "RX(-1.5707963267948966) 1\nRX(1.5707963267948966) 1\n",
    "(1+0j)*Z0*Z1": "",
    "(1+0j)*X0": "RX(1.5707963267948966) 0\nRZ(1.5707963267948966) 0\nRX(-1.5707963267948966) 0\nRX(1.5707963267948966) 0\nRZ(-1.5707963267948966) 0\nRX(-1.5707963267948966) 0\n",
    "(1+0j)*Z0": ""
}
bramathon commented 1 year ago
  1. get_calibration_program should return an empty program when the observable is simply the ground state. In order to measure this observable, we need not do anything.
  2. I would expect so. However, I'm guessing it runs into the problem that is doesn't know which qubits to run the symmetrized readout on.

A simple solution would be for get_calibration_program to apply RZ(0) for any qubits which are in the observable but don't have an operation in the calibration program.

jselig-rigetti commented 1 year ago

@bramathon thank you for the response - from more digging, it seems there's another (or perhaps the primary issue) that _max_weight_operator() is returning [] for some PauliTerms, which causes the same following error even for non-empty programs

api.QVMError: QVM reported a problem running your program: The value of QVM::SIZE is 0, which is not The SIZE wasn't a multiple of 8..
jselig-rigetti commented 1 year ago

Reviewed. In addition to the comments on the code, the method by which the updates have been made is one of changes not backwards-compatible with pyquil v3. This is a major breaking change that will issue a new major version of forest-benchmarking?

@mhodson-rigetti Yes, that's the case - the version bump from 0.8 to 0.9 in forest/benchmarking/__init__.py should reflect that, given pre-1.0 minor bumps are considered instable.

mhodson-rigetti commented 1 year ago

Reviewed. In addition to the comments on the code, the method by which the updates have been made is one of changes not backwards-compatible with pyquil v3. This is a major breaking change that will issue a new major version of forest-benchmarking?

@mhodson-rigetti Yes, that's the case - the version bump from 0.8 to 0.9 in forest/benchmarking/__init__.py should reflect that, given pre-1.0 minor bumps are considered instable.

Great, I'm good with this.