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

Fix outcomes test and remove incorrect test #58

Merged
merged 1 commit into from
Oct 3, 2024
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
23 changes: 15 additions & 8 deletions qualibrate/qualibration_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,19 @@ def save(self) -> None:

def _post_run(
self,
last_executed_node: "QualibrationNode",
created_at: datetime,
initial_targets: Sequence[TargetType],
parameters: NodeParameters,
run_error: Optional[RunError],
) -> NodeRunSummary:
outcomes = self.outcomes
outcomes = last_executed_node.outcomes
if self.parameters is not None and (targets := self.parameters.targets):
lost_targets_outcomes = set(targets) - set(outcomes.keys())
outcomes.update(
{target: Outcome.SUCCESSFUL for target in lost_targets_outcomes}
)
self.outcomes = {
self.outcomes = last_executed_node.outcomes = {
name: Outcome(outcome) for name, outcome in outcomes.items()
}
self.run_summary = NodeRunSummary(
Expand Down Expand Up @@ -284,15 +285,21 @@ def run(
finally:
run_modes_ctx.reset(run_modes_token)
external_parameters_ctx.reset(external_parameters_token)
last_executed_node = last_executed_node_ctx.get()
if last_executed_node is None:
logger.warning(
f"Last executed node not set after running {self}"
)
last_executed_node = self

run_summary = self._post_run(
created_at, initial_targets, parameters, run_error
last_executed_node,
created_at,
initial_targets,
parameters,
run_error,
)

last_executed_node = last_executed_node_ctx.get()
if last_executed_node is None:
logger.warning(f"Last executed node not set after running {self}")
last_executed_node = self

return last_executed_node, run_summary

def run_node_file(self, node_filepath: Path) -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from typing import ClassVar

from qualibrate import NodeParameters, QualibrationNode
from qualibrate.models.outcome import Outcome


class Parameters(NodeParameters):
targets_name: ClassVar[str] = "qubits"
qubits: list[str] = ["q0", "q1", "q2"]


Expand Down
2 changes: 1 addition & 1 deletion tests/test_qualibration_node/test_node_outcomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_node_outcomes():
nodes,
)
node = nodes["node_part_outcome"]
node.run()
node, _summary = node.run()
assert node.outcomes == {
"q0": Outcome.SUCCESSFUL,
"q1": Outcome.FAILED,
Expand Down
23 changes: 0 additions & 23 deletions tests/test_qualibration_node/test_qualibration_node_singleton.py

This file was deleted.