-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Readout mitigator classes #6485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
qiskit/result/distributions/quasi.py
Outdated
@@ -123,3 +123,11 @@ def hex_probabilities(self): | |||
format ``"0x1a"`` | |||
""" | |||
return {hex(key): value for key, value in self.items()} | |||
|
|||
def stddev(self, shots): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not work here. The runtime mitigation method will soon return the mitigation_overhead
that, together with the number of shots, gives an estimate (usually exact) of this value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @nonhermitian for the feedback! So where should I add the stddev
function?
Should I add it to the ReadoutMitigator class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense but needs to be computed differently.
Here is the basic way M3 works:
|
The M3 code is up here #6748. So thoughts on this PR: I think the mitigation classes should be simpler. Namely, the bare minimum one needs is:
The mitigator itself should in charge of executing the calibration circuits because at some point the backends should just compute this info on a regular basis and cache it at which point Things like plotting the A-matrix should not be here, just simply return an array for the given matrix. Returning the mitigation matrix should not be in the base class as computing it is optional depending on the solution method. I am also not a big fan of having |
This commit migrates the measurement mitigation code from qiskit-ignis into qiskit-terra for use with the QuantumInstance class. The QuantumInstance class's usage of the measurement mitigation from ignis is the one thing blocking us from deprecating qiskit-ignis completely. By embedding the code the quantum instance depends on inside qiskit.utils users of QuantumInstance (and therefore qiskit.algorithms) can construct and use measurement mitigation in it's current form. The use of this migrated module is only supported for use with the QuantumInstance class and is explicitly documented as internal/private except for how it gets used by the QuantumInstance. There is ongoing work to create a standardized mitigation API in Qiskit#6485 and Qiskit#6748, this does not preclude that work, but we should adapt this as part of those efforts to use the standardized interface. Ideally this would have been made a private interface and not exposed it as user facing (in deference to the standardization effort), but unfortunately the QuantumInstance expects classes of these classes as it's public interface for selecting a mitigation technique which means users need to be able to use the classes. However, as only the classes are public interfaces we can adapt this as we come up with a standardized mitigation interface and rewrite the internals of this and how the QuantumInstance leverages mitigators to use the new interface. A good follow-up here would be to adapt the mitigator selection kwarg to deprecate the use of classes and then we can make things explicitly private in the migrated code and wait for Qiskit#6495 and Qiskit#6748 to be ready for our user facing API. I opted to not include that in this PR to minimize changes to just what we migrated from ignis and update usage of old ignis classes to rely on the migrated version.
@nonhermitian @chriseclectic @mtreinish - I updated this PR following your comments and discussions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some initial comments
_HAS_MATPLOTLIB = False | ||
|
||
|
||
class BaseReadoutMitigator(ABC): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to include something in the base class for what physical qubits it is defined on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please elaborate?
|
||
# Compute variance | ||
sq_expval = (coeffs ** 2).dot(probs) | ||
variance = (sq_expval - expval ** 2) / shots |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this method under-estimates error since it doesn't take into account the mitigation overhead from the CTMP paper. In that paper they use an upper bound for the variance based on the A-matrix which comes from uncertainty in the estimates of the true error probabilities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the CTMP mitigation overhead estimator work for all mitigation methods? If so - perhaps we should add mitigation_overhead
to the base class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took the code for the complete mitigator method from the previous code in ignis - does it mean that the code there is not accurate enough?
https://github.com/Qiskit/qiskit-ignis/blob/f0728b6b6785b68693a0d31c54c51f9826ddde34/qiskit/ignis/mitigation/expval/utils.py#L244-#L246
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that there is another function stddev_upper_bound
that relies on gamma
:
https://github.com/Qiskit/qiskit-ignis/blob/f0728b6b6785b68693a0d31c54c51f9826ddde34/qiskit/ignis/mitigation/expval/base_meas_mitigator.py#L155
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so perhaps we could return only gamma
and not the entire expectation_value
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the functions _stddev_upper_bound
and _gamma
|
||
def quasi_probabilities( | ||
self, data: Counts, qubits: Iterable[int] = None, shots: Optional[int] = None | ||
) -> (QuasiDistribution, Dict[str, float]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chriseclectic - Is it better to return the standard deviation also as a QuasiDistribution
object (instead of a Dict
)?
else: | ||
qubits = tuple(sorted(qubits)) | ||
|
||
# Check for cached mitigation matrix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use a built-in Python caching mechanism such as the @lru_cache
decorator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should discuss where we can store the cached mitigation matrix(es)
* Migrate measure mitigation from ignis for QuantumInstance This commit migrates the measurement mitigation code from qiskit-ignis into qiskit-terra for use with the QuantumInstance class. The QuantumInstance class's usage of the measurement mitigation from ignis is the one thing blocking us from deprecating qiskit-ignis completely. By embedding the code the quantum instance depends on inside qiskit.utils users of QuantumInstance (and therefore qiskit.algorithms) can construct and use measurement mitigation in it's current form. The use of this migrated module is only supported for use with the QuantumInstance class and is explicitly documented as internal/private except for how it gets used by the QuantumInstance. There is ongoing work to create a standardized mitigation API in #6485 and #6748, this does not preclude that work, but we should adapt this as part of those efforts to use the standardized interface. Ideally this would have been made a private interface and not exposed it as user facing (in deference to the standardization effort), but unfortunately the QuantumInstance expects classes of these classes as it's public interface for selecting a mitigation technique which means users need to be able to use the classes. However, as only the classes are public interfaces we can adapt this as we come up with a standardized mitigation interface and rewrite the internals of this and how the QuantumInstance leverages mitigators to use the new interface. A good follow-up here would be to adapt the mitigator selection kwarg to deprecate the use of classes and then we can make things explicitly private in the migrated code and wait for #6495 and #6748 to be ready for our user facing API. I opted to not include that in this PR to minimize changes to just what we migrated from ignis and update usage of old ignis classes to rely on the migrated version. * Update releasenotes/notes/ignis-mitigators-70492690cbcf99ca.yaml Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> * Finish release notes * Move API stability warning to the top * Apply suggestions from code review Co-authored-by: Jake Lishman <jake@binhbar.com> * Remove unecessary test subclassing * Fix skip logic in algorithm mitigation tests * Fix exception handling on missing ignis in algorithms * Assert deprecation message for ignis use mentions ignis * Make filters module properly private * Fix lint Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> Co-authored-by: Jake Lishman <jake@binhbar.com>
|
ac638fd
to
6549830
Compare
Attempting to fix cyclic dependancy error
* Migrate measure mitigation from ignis for QuantumInstance This commit migrates the measurement mitigation code from qiskit-ignis into qiskit-terra for use with the QuantumInstance class. The QuantumInstance class's usage of the measurement mitigation from ignis is the one thing blocking us from deprecating qiskit-ignis completely. By embedding the code the quantum instance depends on inside qiskit.utils users of QuantumInstance (and therefore qiskit.algorithms) can construct and use measurement mitigation in it's current form. The use of this migrated module is only supported for use with the QuantumInstance class and is explicitly documented as internal/private except for how it gets used by the QuantumInstance. There is ongoing work to create a standardized mitigation API in Qiskit#6485 and Qiskit#6748, this does not preclude that work, but we should adapt this as part of those efforts to use the standardized interface. Ideally this would have been made a private interface and not exposed it as user facing (in deference to the standardization effort), but unfortunately the QuantumInstance expects classes of these classes as it's public interface for selecting a mitigation technique which means users need to be able to use the classes. However, as only the classes are public interfaces we can adapt this as we come up with a standardized mitigation interface and rewrite the internals of this and how the QuantumInstance leverages mitigators to use the new interface. A good follow-up here would be to adapt the mitigator selection kwarg to deprecate the use of classes and then we can make things explicitly private in the migrated code and wait for Qiskit#6495 and Qiskit#6748 to be ready for our user facing API. I opted to not include that in this PR to minimize changes to just what we migrated from ignis and update usage of old ignis classes to rely on the migrated version. * Update releasenotes/notes/ignis-mitigators-70492690cbcf99ca.yaml Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> * Finish release notes * Move API stability warning to the top * Apply suggestions from code review Co-authored-by: Jake Lishman <jake@binhbar.com> * Remove unecessary test subclassing * Fix skip logic in algorithm mitigation tests * Fix exception handling on missing ignis in algorithms * Assert deprecation message for ignis use mentions ignis * Make filters module properly private * Fix lint Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> Co-authored-by: Jake Lishman <jake@binhbar.com>
…kit#6867) * Migrate measure mitigation from ignis for QuantumInstance This commit migrates the measurement mitigation code from qiskit-ignis into qiskit-terra for use with the QuantumInstance class. The QuantumInstance class's usage of the measurement mitigation from ignis is the one thing blocking us from deprecating qiskit-ignis completely. By embedding the code the quantum instance depends on inside qiskit.utils users of QuantumInstance (and therefore qiskit.algorithms) can construct and use measurement mitigation in it's current form. The use of this migrated module is only supported for use with the QuantumInstance class and is explicitly documented as internal/private except for how it gets used by the QuantumInstance. There is ongoing work to create a standardized mitigation API in Qiskit/qiskit#6485 and Qiskit/qiskit#6748, this does not preclude that work, but we should adapt this as part of those efforts to use the standardized interface. Ideally this would have been made a private interface and not exposed it as user facing (in deference to the standardization effort), but unfortunately the QuantumInstance expects classes of these classes as it's public interface for selecting a mitigation technique which means users need to be able to use the classes. However, as only the classes are public interfaces we can adapt this as we come up with a standardized mitigation interface and rewrite the internals of this and how the QuantumInstance leverages mitigators to use the new interface. A good follow-up here would be to adapt the mitigator selection kwarg to deprecate the use of classes and then we can make things explicitly private in the migrated code and wait for Qiskit/qiskit#6495 and Qiskit/qiskit#6748 to be ready for our user facing API. I opted to not include that in this PR to minimize changes to just what we migrated from ignis and update usage of old ignis classes to rely on the migrated version. * Update releasenotes/notes/ignis-mitigators-70492690cbcf99ca.yaml Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> * Finish release notes * Move API stability warning to the top * Apply suggestions from code review Co-authored-by: Jake Lishman <jake@binhbar.com> * Remove unecessary test subclassing * Fix skip logic in algorithm mitigation tests * Fix exception handling on missing ignis in algorithms * Assert deprecation message for ignis use mentions ignis * Make filters module properly private * Fix lint Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> Co-authored-by: Jake Lishman <jake@binhbar.com>
…kit#6867) * Migrate measure mitigation from ignis for QuantumInstance This commit migrates the measurement mitigation code from qiskit-ignis into qiskit-terra for use with the QuantumInstance class. The QuantumInstance class's usage of the measurement mitigation from ignis is the one thing blocking us from deprecating qiskit-ignis completely. By embedding the code the quantum instance depends on inside qiskit.utils users of QuantumInstance (and therefore qiskit.algorithms) can construct and use measurement mitigation in it's current form. The use of this migrated module is only supported for use with the QuantumInstance class and is explicitly documented as internal/private except for how it gets used by the QuantumInstance. There is ongoing work to create a standardized mitigation API in Qiskit/qiskit#6485 and Qiskit/qiskit#6748, this does not preclude that work, but we should adapt this as part of those efforts to use the standardized interface. Ideally this would have been made a private interface and not exposed it as user facing (in deference to the standardization effort), but unfortunately the QuantumInstance expects classes of these classes as it's public interface for selecting a mitigation technique which means users need to be able to use the classes. However, as only the classes are public interfaces we can adapt this as we come up with a standardized mitigation interface and rewrite the internals of this and how the QuantumInstance leverages mitigators to use the new interface. A good follow-up here would be to adapt the mitigator selection kwarg to deprecate the use of classes and then we can make things explicitly private in the migrated code and wait for Qiskit/qiskit#6495 and Qiskit/qiskit#6748 to be ready for our user facing API. I opted to not include that in this PR to minimize changes to just what we migrated from ignis and update usage of old ignis classes to rely on the migrated version. * Update releasenotes/notes/ignis-mitigators-70492690cbcf99ca.yaml Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> * Finish release notes * Move API stability warning to the top * Apply suggestions from code review Co-authored-by: Jake Lishman <jake@binhbar.com> * Remove unecessary test subclassing * Fix skip logic in algorithm mitigation tests * Fix exception handling on missing ignis in algorithms * Assert deprecation message for ignis use mentions ignis * Make filters module properly private * Fix lint Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> Co-authored-by: Jake Lishman <jake@binhbar.com>
Summary
#6484
Add Readout Mitigator classes bases on the current code in ignis.
Details and comments
BaseReadoutMitgator
CorrelatedReadoutMitigator
LocalReadoutMitigator
qiskit.result
classes only if necessary (Counts
,ProbDitribution
,QuasiDistribution
)co-authored by @gadial