-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #617 from qiboteam/status
Implementing validation using Chi squared
- Loading branch information
Showing
17 changed files
with
272 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,6 @@ your quantum hardware. | |
interface | ||
runcard | ||
autoruncard | ||
validation | ||
protocols | ||
example |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
How to add validation to your protocol? | ||
======================================= | ||
|
||
In Qibocal there is the possibility to add a validation step | ||
during the execution of your protocols. | ||
Here is an example of a runcard which validates the results through | ||
:math:`\chi^2`. | ||
|
||
.. code-block:: yaml | ||
actions: | ||
- id: t1 | ||
priority: 0 | ||
operation: t1 | ||
validator: | ||
scheme: chi2 | ||
parameters: | ||
chi2_max_value: 1 | ||
parameters: | ||
... | ||
The execution will be interrupted in this case if the :math:`\chi^2` exceeds | ||
`chi_max_value`. |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,5 +38,5 @@ class Normal(Status): | |
"""All green.""" | ||
|
||
|
||
class Broken(Status): | ||
class Failure(Status): | ||
"""Unrecoverable.""" |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Validation module.""" | ||
from dataclasses import dataclass | ||
from typing import NewType, Optional, Union | ||
|
||
from qibolab.qubits import QubitId, QubitPairId | ||
|
||
from ..config import log | ||
from .operation import Results | ||
from .status import Status | ||
from .validators import VALIDATORS | ||
|
||
ValidatorId = NewType("ValidatorId", str) | ||
"""Identifier for validator object.""" | ||
|
||
|
||
@dataclass | ||
class Validator: | ||
"""Generic validator object.""" | ||
|
||
scheme: ValidatorId | ||
parameters: Optional[dict] = None | ||
|
||
def __call__( | ||
self, results: Results, qubit: Union[QubitId, QubitPairId, list[QubitId]] | ||
) -> Status: | ||
log.info( | ||
f"Performing validation in qubit {qubit} of {results.__class__.__name__} using {self.scheme} scheme." | ||
) | ||
validator = VALIDATORS[self.scheme] | ||
return validator(results, qubit, **self.parameters) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .chi2 import check_chi2 | ||
|
||
VALIDATORS = {"chi2": check_chi2} | ||
"""Dict with available validators.""" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Chi2 validation""" | ||
from typing import Union | ||
|
||
from qibolab.qubits import QubitId, QubitPairId | ||
|
||
from qibocal.config import raise_error | ||
|
||
from ..operation import Results | ||
from ..status import Failure, Normal | ||
|
||
CHI2_MAX = 0.05 | ||
"""Max value for accepting fit result.""" | ||
|
||
|
||
def check_chi2( | ||
results: Results, | ||
qubit: Union[QubitId, QubitPairId, list[QubitId]], | ||
chi2_max_value=None, | ||
): | ||
"""Performs validation of results using chi2. | ||
It assesses that chi2 is below the chi2_max_value threshold. | ||
""" | ||
|
||
if chi2_max_value is None: | ||
chi2_max_value = CHI2_MAX | ||
try: | ||
chi2 = getattr(results, "chi2")[qubit][0] | ||
if chi2 < chi2_max_value: | ||
return Normal() | ||
else: | ||
return Failure() | ||
except AttributeError: | ||
raise_error( | ||
NotImplementedError, f"Chi2 validation not available for {type(results)}" | ||
) |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.