Skip to content

ModelComparisonSimulator: handle different outputs from individual simulators #452

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

Kucharssim
Copy link
Member

fixes #441

As per #441 (comment), this PR implements

"smarter" concatenation function (for example one that pads with nan if a parameter is not available for a given model).

However, by default the simulator will just drop (with an info warning) keys that are not common for all simulators, since in most situations we would not need those outputs in the first place.

@Kucharssim Kucharssim requested a review from vpratz April 29, 2025 08:07
Copy link

codecov bot commented Apr 29, 2025

Codecov Report

Attention: Patch coverage is 97.56098% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
bayesflow/simulators/model_comparison_simulator.py 97.56% 1 Missing ⚠️
Files with missing lines Coverage Δ
bayesflow/simulators/model_comparison_simulator.py 84.26% <97.56%> (+57.18%) ⬆️

... and 22 files with indirect coverage changes

@vpratz
Copy link
Collaborator

vpratz commented Apr 29, 2025

Thanks for the PR, I skimmed it and like the idea behind the changes. I'll try to conduct a proper review some time this week.

@LarsKue LarsKue self-requested a review April 29, 2025 18:24
Copy link
Contributor

@LarsKue LarsKue left a comment

Choose a reason for hiding this comment

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

Looks good from my side. See individual comments.

Can we also add tests for the (few) missed edge-case lines?

@Kucharssim Kucharssim requested a review from LarsKue April 30, 2025 07:58
add newlines to correctly render lists, make reference to other class a
link
Copy link
Collaborator

@vpratz vpratz left a comment

Choose a reason for hiding this comment

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

See my comment on one edge case, I'm not sure if it is a relevant one. What do you think?
Apart from that, the PR looks good to me, I only added minor formatting fixes to the docstring.

def _determine_key_conflicts(self, sims):
# determine only once
if self._keys is not None:
return self._keys
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this return "wrong" results if some simulators had n=0 in line 120 when the function first runs, and n>0 later on? Is this something we want to safeguard against?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can imagine this function to be quite cheap to compute, would it make sense to run it completely every time (but only logging the info once)?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, will do that

Copy link
Contributor

@LarsKue LarsKue left a comment

Choose a reason for hiding this comment

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

The changes are looking great. Can we address Valentin's comments before we merge? I also left some minor comments, still.

def _determine_key_conflicts(self, sims):
# determine only once
if self._keys is not None:
return self._keys
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree

assert set(samples) == {"x", "model_indices", "c", "w"}
assert np.sum(np.isnan(samples["c"])) + np.sum(np.isnan(samples["w"])) == batch_size
elif multimodel_key_conflicts.key_conflicts == "error":
with pytest.raises(Exception):
Copy link
Contributor

Choose a reason for hiding this comment

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

This is too broad of a check. Use specific exception types.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants