Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion qiskit_experiments/database_service/db_analysis_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def __init__(
device_components: List[Union[DeviceComponent, str]],
experiment_id: str,
result_id: Optional[str] = None,
chisq: Optional[float] = None,
quality: Optional[str] = None,
verified: bool = False,
tags: Optional[List[str]] = None,
Expand All @@ -88,6 +89,7 @@ def __init__(
device_components: Target device components this analysis is for.
experiment_id: ID of the experiment.
result_id: Result ID. If ``None``, one is generated.
chisq: Reduced chi squared of the fit.
quality: Quality of the analysis. Refer to the experiment service
provider for valid values.
verified: Whether the result quality has been verified.
Expand Down Expand Up @@ -116,6 +118,7 @@ def __init__(
comp = to_component(comp)
self._device_components.append(comp)

self._chisq = chisq
self._quality = quality
self._quality_verified = verified
self._tags = tags or []
Expand Down Expand Up @@ -143,7 +146,9 @@ def load(cls, result_id: str, service: DatabaseServiceV1) -> "DbAnalysisResultV1
The loaded analysis result.
"""
# Load data from the service
return cls._from_service_data(service.analysis_result(result_id))
instance = cls._from_service_data(service.analysis_result(result_id))
instance._created_in_db = True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DbExperimentDataV1.load method probably also needs to have this attribute set on the object it returns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c6d0a9f.

return instance

def save(self) -> None:
"""Save this analysis result in the database.
Expand All @@ -169,6 +174,7 @@ def save(self) -> None:
"result_id": self.result_id,
"data": _result_data,
"tags": self.tags(),
"chisq": self._chisq,
"quality": self.quality,
"verified": self.verified,
}
Expand Down Expand Up @@ -262,6 +268,18 @@ def source(self) -> Dict:
"""Return the class name and version."""
return self._source

@property
def chisq(self) -> str:
"""Return the reduced χ² of this analysis."""
return self._chisq

@chisq.setter
def chisq(self, new_chisq: float) -> None:
"""Set the reduced χ² of this analysis."""
self._chisq = new_chisq
if self._auto_save:
self.save()

@property
def quality(self) -> str:
"""Return the quality of this analysis.
Expand Down Expand Up @@ -379,6 +397,8 @@ def __str__(self):
ret += f"\nAnalysis Result ID: {self.result_id}"
ret += f"\nExperiment ID: {self.experiment_id}"
ret += f"\nDevice Components: {self.device_components}"
if self.chisq:
ret += f"\nχ²: {self.chisq}"
ret += f"\nQuality: {self.quality}"
ret += f"\nVerified: {self.verified}"
if self.tags():
Expand Down
2 changes: 2 additions & 0 deletions qiskit_experiments/database_service/db_experiment_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,8 @@ def load(cls, experiment_id: str, service: DatabaseServiceV1) -> "DbExperimentDa
# Maybe this isn't necessary but the repr of the class should
# be updated to show correct number of results including remote ones
expdata._retrieve_analysis_results()
# mark it as existing in the DB
expdata._created_in_db = True
return expdata

def cancel_jobs(self) -> None:
Expand Down
3 changes: 2 additions & 1 deletion qiskit_experiments/framework/base_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ def run(
if "success" not in res:
res["success"] = True
analysis_result = DbAnalysisResultV1(result_data=res, **analysis_result_parameters)
if "chisq" in res:
analysis_result.chisq = res["chisq"]
if "quality" in res:
analysis_result.quality = res["quality"]
analysis_result.verified = True
analysis_results.append(analysis_result)

except AnalysisError as ex:
Expand Down