Skip to content

Add evaluate algorithm#145

Merged
mscroggs merged 52 commits into
mainfrom
mscroggs/evaluate
Jun 29, 2026
Merged

Add evaluate algorithm#145
mscroggs merged 52 commits into
mainfrom
mscroggs/evaluate

Conversation

@mscroggs

@mscroggs mscroggs commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator
  • Add evaluate algorithm that uses the evaluate method on each node from the roots down to the outcome node.
  • Add a function to utils that creates the graph for the example model that Ricardo is interested in

Builds on #143.

Resolves #125. Resolves #126.

@mscroggs mscroggs marked this pull request as draft June 26, 2026 07:38
@mscroggs mscroggs marked this pull request as ready for review June 26, 2026 14:16
Comment thread tests/test_utils/test_graphs.py Outdated

@willGraham01 willGraham01 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Main comment is about how evaluate is currently implemented; namely

  • It's not a pure function and
  • We might want to retrieve multiple values from the graph, some of which are "on the way down". Right now we have to do this through multiple calls.

Beyond that, some comments on organising and expanding the tests.

Comment thread src/causalprog/algorithms/evaluate.py Outdated
Comment thread src/causalprog/graph/special.py
Comment thread src/causalprog/graph/special.py
Comment thread src/causalprog/graph/special.py
Comment thread src/causalprog/algorithms/evaluate.py
Comment thread src/causalprog/algorithms/evaluate.py Outdated
Comment thread src/causalprog/algorithms/__init__.py
Comment thread tests/test_utils/test_graphs.py Outdated
Comment thread tests/test_algorithms/test_evaluate.py Outdated
Comment thread tests/test_algorithms/test_evaluate.py Outdated
@mscroggs mscroggs force-pushed the mscroggs/evaluate branch 2 times, most recently from 619a69e to 6cd17c6 Compare June 29, 2026 10:09
Co-authored-by: Will Graham <32364977+willGraham01@users.noreply.github.com>
@mscroggs mscroggs force-pushed the mscroggs/evaluate branch from 6cd17c6 to a512b2d Compare June 29, 2026 10:10
@willGraham01 willGraham01 self-requested a review June 29, 2026 12:34

@willGraham01 willGraham01 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

evaluate_down_to is more general than evaluate so we should adapt the test accordingly (though we can test both in the same test because I'm not a code sadist).

Also we might not want to duplicate the values dictionary entries, so have suggested just returning node-evaluations that are actually computed.

Comment thread src/causalprog/algorithms/evaluate.py Outdated
Comment thread src/causalprog/graph/special.py
Comment thread tests/test_algorithms/test_evaluate.py Outdated
mscroggs and others added 5 commits June 29, 2026 14:02
Comment thread tests/test_algorithms/test_evaluate.py Outdated
evaluate_test_graph: Graph,
outcome_node_label: str,
initial_values: dict[str, Array],
expected_result: Array,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
expected_result: Array,
expected_result: dict[str, float | Array],

(Soz, but otherwise all looks good!)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We should work out why mypy didn't spot that one

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Haven't we just blanket disabled typehint checking in the tests (because a lot of our fixtures have very long types)?

@mscroggs mscroggs merged commit fa43188 into main Jun 29, 2026
5 checks passed
@mscroggs mscroggs deleted the mscroggs/evaluate branch June 29, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Helper function to build graph Ricardo is interested in Add evaluate algorithm

2 participants