Skip to content

Simplifcation of classses and functions related to sampling#420

Merged
quaquel merged 16 commits intomasterfrom
sampling_simplification
Oct 2, 2025
Merged

Simplifcation of classses and functions related to sampling#420
quaquel merged 16 commits intomasterfrom
sampling_simplification

Conversation

@quaquel
Copy link
Copy Markdown
Owner

@quaquel quaquel commented Sep 24, 2025

The current structure of classes and functions used for representing points in a parameter space is rather convoluted and not easy to understand. This PR involves a substantial simplification of the code base, the removal of redundant code, and a renaming of various classes and functions to make the code a bit easier to comprehend.

  1. It removes the Policy and Scenario class. Behaviourally, there was no difference between them, so from a coding pov there is no reason for them to exist.
  2. Renames DesignIterator to SampleCollection. This better reflects what the class does
  3. Rename Point to Sample; this ties logically into the SampleCollection
  4. Removal of all sample_{} functions because this functionality has been moved into BaseSampler.generate_samples, which now returns a SampleCollection instead of the numpy array with the samples.
  5. Removal of the deterimine_parameters function, because this was a one liner around determine_objects

@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@coveralls
Copy link
Copy Markdown

coveralls commented Sep 24, 2025

Coverage Status

coverage: 88.664% (+0.5%) from 88.199%
when pulling 7dbfe6c on sampling_simplification
into 1ef4854 on master.

@EwoutH
Copy link
Copy Markdown
Collaborator

EwoutH commented Sep 24, 2025

  1. It removes the Policy and Scenario class. Behaviourally, there was no difference between them, so from a coding pov there is no reason for them to exist.

So Policy and Scenario are both replaced by Sample?

Are these often used by users? I'm thinking a bit about how Sample is a more abstract name than Policy and Scenario, which have a clear meaning. Also a Policy is always a set of policy levers, while a scenario is a set of uncertainties, right? Having that clear separation for a user might beneficial, one way or the other.

@EwoutH
Copy link
Copy Markdown
Collaborator

EwoutH commented Sep 24, 2025

Also I think if you have one Policy and one Scenario there are never duplicate variables (levers/uncertainties). That's something you could check for. With only Sample that might be different.

Maybe it doesn't need to be different classes, but it could have a type or label, which could be "policy", "scenario" or "mixed".

@quaquel
Copy link
Copy Markdown
Owner Author

quaquel commented Sep 24, 2025

So Policy and Scenario are both replaced by Sample?

Yes

Are these often used by users? I'm thinking a bit about how Sample is a more abstract name than Policy and Scenario, which have a clear meaning.

I agree that this is a drawback of this change.

Also a Policy is always a set of policy levers, while a scenario is a set of uncertainties, right? Having that clear separation for a user might beneficial, one way or the other.

Currently, there is no difference between Point, Policy, and Scenario other than the class name. Also, whether a given parameter is a lever or uncertainty is defined at the model level, but Point, Policy, and Scenario are not tied to a model and so cannot do any check of this kind.

Also I think if you have one Policy and one Scenario there are never duplicate variables (levers/uncertainties). That's something you could check for.

See above, there is currently already no way to do this within any of these classes. It might be something to check in Experiment, but I am not sure about the value of this.

reimplentation and move from samplers to points
valueerrror if in combine parameter(s) exist in both collections

add a concat method to combine to samples for the same set of parameters
make c1 + c2 work as shorthand for c1.concat(c2)
…nction

with removal of Policy and Scenario, we can further simplify this code as well
bug fix in _setup
@quaquel quaquel merged commit 592d0cd into master Oct 2, 2025
22 of 24 checks passed
@quaquel quaquel deleted the sampling_simplification branch October 2, 2025 13:27
@quaquel quaquel added the feature label Nov 4, 2025
@EwoutH
Copy link
Copy Markdown
Collaborator

EwoutH commented Dec 26, 2025

Would it be useful to add deprecation warnings, at least for the much used Scenario and Policy?

# ema_workbench/em_framework/points.py
class Scenario(Sample):
    def __init__(self, *args, **kwargs):
        warnings.warn(
            "The `Scenario` class has been removed. Use `Sample` instead. See https://github.com/quaquel/EMAworkbench/pull/420",
            DeprecationWarning,
            stacklevel=2,
        )
        super().__init__(*args, **kwargs)

class Policy(Sample):
    def __init__(self, *args, **kwargs):
        warnings.warn(
            "The `Policy` class has been removed. Use `Sample` instead. See https://github.com/quaquel/EMAworkbench/pull/420",
            DeprecationWarning,
            stacklevel=2,
        )
        super().__init__(*args, **kwargs)

__all__ = ["Sample", "Scenario", "Policy"]
# ema_workbench/__init__.py
from .em_framework.points import Sample, Scenario, Policy
__all__ = ["Sample", "Scenario", "Policy"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants