Skip to content
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

Adding error message when fitting failed #745

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/qibocal/auto/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import time
from copy import deepcopy
from dataclasses import asdict, dataclass, fields
from dataclasses import asdict, dataclass, field, fields
andrea-pasquale marked this conversation as resolved.
Show resolved Hide resolved
from functools import wraps
from pathlib import Path
from typing import Callable, Generic, NewType, Optional, TypeVar, Union
Expand Down
35 changes: 14 additions & 21 deletions src/qibocal/cli/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@
PLATFORM = "platform.yml"


def generate_figures_and_report(node, target):
"""Returns figures and table for report."""
if node.results is None:
# plot acquisition data
return node.task.operation.report(data=node.data, fit=None, target=target)
if target not in node.results:
# plot acquisition data and message for unsuccessful fit
figures = node.task.operation.report(data=node.data, fit=None, target=target)[0]
return figures, "An error occurred when performing the fit."
Comment on lines +26 to +29
Copy link
Member

Choose a reason for hiding this comment

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

I was unaware we already stored this information somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also had to think about it. We can separate the two cases since only with qq acquire Results is None while in the other case the instance of the class is created and all the dict attributes are filled only if the fit is successful.

# plot acquisition and fit
return node.task.operation.report(data=node.data, fit=node.results, target=target)


def report(path):
"""Report generation

Expand Down Expand Up @@ -74,28 +87,8 @@ def routine_targets(self, task_id: TaskId):
def single_qubit_plot(self, task_id: TaskId, qubit: QubitId):
"""Generate single qubit plot."""
node = self.history[task_id]
fit = node.results if node.results and qubit in node.results else None
# the fit is shown only if fitted parameters for the corresponding
# key are in Results.
figures, fitting_report = node.task.operation.report(
data=node.data, fit=fit, target=qubit
)
with tempfile.NamedTemporaryFile(delete=False) as temp:
html_list = []
for figure in figures:
figure.write_html(temp.name, include_plotlyjs=False, full_html=False)
temp.seek(0)
fightml = temp.read().decode("utf-8")
html_list.append(fightml)

all_html = "".join(html_list)
return all_html, fitting_report

def plot(self, task_id: TaskId):
"""Generate plot when only acquisition data are provided."""
node = self.history[task_id]
data = node.task.data
figures, fitting_report = node.task.operation.report(data)
figures, fitting_report = generate_figures_and_report(node, qubit)
with tempfile.NamedTemporaryFile(delete=False) as temp:
html_list = []
for figure in figures:
Expand Down
Loading