Add Readout Error Mitigation (REM)#2985
Open
volodymyr-hq wants to merge 8 commits into
Open
Conversation
…trices when calibration is omitted
Author
|
See also unitaryfoundation/pennylane-qrack#40 for a PR into |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context:
Readout Error Mitigation (REM) is a probabilistic QEM technique aimed at mitigating the readout/measurement noise (not to be confused with quantum noise). This is achieved by running two additional calibration circuits: all-zeroes (an empty circuit) and all-ones (a circuit with a Pauli-X gate on each qubit), then using the resulting bitstring distribution after measurement to calculate per-qubit confusion matrices. Finally, these confusion matrices and the resulting bitstring distribution after measurement for the mitigatee circuit are used to solve a linear system and obtain mitigated bitstring distribution. Haiqu's aim as part of the CODE project is to add REM support to the Catalyst compiler.
Description of the Change:
Frontend
We introduced the public
mitigate_with_remwrapper. This function hooks into the Catalyst compilation pipeline by wrapping target QNodes, binding a newrem_pJAX primitive, and routing the resulting user and calibration samples through JAX-compiled post-processing functions. We tried to follow the format/naming conventions established the existing ZNE Mitigation implementation where possible.JAX-Compilable Post-Processing
Top-level JAX-compilable post-processing functions were added to calculate per-qubit confusion matrices and to solve the linear system to correct noisy samples. A trace-time path dispatch switches from full histograms (bounded by
2^n_qubits x 2^n_qubits) to a sort-based encoding proposed by Nation et al., which is bounded bynum_shots x num_shots, when2^n_qubitsexceeds shot count. This optimization allows the program to scale past 25 qubits. Currently, theSampleMP,CountsMPandProbsMPare supported.Mitigation Dialect and Lowering Pass
New
RemOp(mitigation.rem) operation was added to theMitigationdialect. The lowering pass rewrites a single calling operation into the original callee alongside two inlined calibration circuits (all-zeros and all-ones states). Thequantum.deviceattributes are forwarded to the calibration circuits, automatically propagating the noise probability to both calibration circuits.Calibration Caching Support
A boolean
runCalibrationattribute in themitigation.remoperation that turns on or off the emission of operations for calibration circuits. When set to False, the lowering pass skips generating calibration circuits, which is useful for per-device confusion matrix caching.Benefits:
2^num_qubitsforSampleMP), which is beneficial for on-hardware execution and large scale simulation.Possible Drawbacks:
SampleMP+ classical post-processing. This was however out of scope for this project.qrack.simulatorC++ backend to support simulated readout noise, work is being done to get it merged intopennylane-qrackupstream. For now it is possible to test with our forked version available here: https://github.com/volodymyr-hq/pennylane-qrack/tree/readout_noise_channel. Addingpennylane-qrackas a dependency for the tests seems unreasonable.lower-mitigationpass that replacesmitigation.rem. This breaks the abstraction to some extent, and it would be better if these functions were inserted into the program as part of the lowering pass. However, we did not find a reasonably simple way to implement this, since the post-processing functions rely on linear algebra functions (best represented in StableHLO), which is lowered at an earlier point in the pipeline. We are open to suggestions if there is a better way to do this.SampleMPis not a tensor of all sampled bitstrings, but a tuple of two tensors: one with a sorted list of unique sampled bitstrings, and another with their respective counts. This differs from what is usually expected from a kernel with aSampleMPmeasurement process, but makes sense for mitigation purposes. Unrolling the counts into samples is not optimal, since that would require probabilistic re-sampling of shots.mlir/lib/Mitigation/Transforms/CMakeLists.txtto set"-Wno-deprecated-declarations"sinceRem.cppstill uses the legacyrewriter.create<OpTy>(...)builder, while upstream MLIR has deprecated it in favour ofOpTy::create(rewriter, ...). This can be corrected andRem.cppcan be ported to the new interface if needed.