Skip to content

Commit

Permalink
Fix redispatch bug (#1511)
Browse files Browse the repository at this point in the history
* Add functional test

* add changelog entry

* change copy_nodes to copy_nodes_from
  • Loading branch information
FyzHsn authored Feb 10, 2023
1 parent ea53944 commit 749295d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [UNRELEASED]

### Fixed

- Redispatch bug.

### Changed

- Location of function to load result from the database now moved to load module in covalent_dispatcher/_db folde.
Expand Down
2 changes: 1 addition & 1 deletion covalent_dispatcher/_core/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def _get_result_object_from_new_lattice(
tg = result_object.lattice.transport_graph
tg_old = old_result_object.lattice.transport_graph
reusable_nodes = TransportGraphOps(tg_old).get_reusable_nodes(tg)
TransportGraphOps(tg_old).copy_nodes(tg, reusable_nodes)
TransportGraphOps(tg_old).copy_nodes_from(tg, reusable_nodes)

return result_object

Expand Down
4 changes: 2 additions & 2 deletions tests/covalent_dispatcher_tests/_core/data_manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@ def test_get_result_object_from_new_lattice(mocker, reuse):
transport_graph_ops_mock().get_reusable_nodes.assert_called_with(
result_object_mock().lattice.transport_graph
)
transport_graph_ops_mock().copy_nodes.assert_called_once_with(
transport_graph_ops_mock().copy_nodes_from.assert_called_once_with(
result_object_mock().lattice.transport_graph,
transport_graph_ops_mock().get_reusable_nodes.return_value,
)

else:
transport_graph_ops_mock().get_reusable_nodes.assert_not_called()
transport_graph_ops_mock().copy_nodes.assert_not_called()
transport_graph_ops_mock().copy_nodes_from.assert_not_called()


@pytest.mark.parametrize("reuse", [True, False])
Expand Down
2 changes: 1 addition & 1 deletion tests/covalent_tests/workflow/transport_graph_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def test_is_same_edge_attributes_false(tg, tg_ops):
assert tg_ops.is_same_edge_attributes(tg._graph, tg_2._graph, 0, 1) is False


def test_copy_nodes(tg_ops):
def test_copy_nodes_from(tg_ops):
"""Test the node copying method."""

def replacement(x):
Expand Down
27 changes: 27 additions & 0 deletions tests/functional_tests/workflow_stack_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,3 +931,30 @@ def workflow(x, y):
assert (
res_obj_3.get_node_result(i)["start_time"] == res_obj_3.get_node_result(i)["end_time"]
)


def test_redispatch_reusing_previous_results_and_new_args():
"""Test reusing previous results for redispatching and using new args."""

@ct.electron
def task_1(x):
return x

@ct.electron
def failing_task(x, y):
return x / y

@ct.lattice
def failing_workflow(x, y):
res_1 = task_1(x)
return failing_task(res_1, y)

dispatch_id = ct.dispatch(failing_workflow)(1, 0)
result = ct.get_result(dispatch_id, wait=True)
assert result.result is None
assert str(result.status) == "FAILED"

redispatch_id = ct.redispatch(dispatch_id=dispatch_id, reuse_previous_results=True)(1, 1)
result = ct.get_result(redispatch_id, wait=True)
assert int(result.result) == 1
assert str(result.status) == "COMPLETED"

0 comments on commit 749295d

Please sign in to comment.