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

Added ensemble object #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

daub1
Copy link
Contributor

@daub1 daub1 commented Feb 18, 2021

Added ensemble object, which allows combining multiple samplers into a single object with the same interface as the regular sampler object.

@daub1
Copy link
Contributor Author

daub1 commented Feb 18, 2021

Closes #1

@crkrenn
Copy link
Collaborator

crkrenn commented Feb 20, 2021

@daub1, have you tested the ensemble sampler with a client like codepy?

I like the concept, but I'm a little confused how a client can access it without changes to base_sampler, samplers, and schema.

It would be nice if the extra wiring were not necessary, but I think that it is.

-Chris

$ grep -i -e cross.*product scisample/* tests/*
grep: scisample/__pycache__: Is a directory
scisample/base_sampler.py:        'cross_product': 'CrossProductSampler',
scisample/base_sampler.py:            type: cross_product
scisample/cross_product.py:Module defining the cross product sampler object.
scisample/cross_product.py:class CrossProductSampler(BaseSampler):
scisample/cross_product.py:    Class defining cross-product sampling.
scisample/cross_product.py:            type: cross_product
scisample/cross_product.py:    Entries in the ``parameters`` block will have the cross product taken.
scisample/samplers.py:from scisample.cross_product import CrossProductSampler
scisample/samplers.py:    'cross_product': CrossProductSampler,
scisample/samplers.py:    | * ``cross_product``
scisample/schema.py:CROSS_PRODUCT_SCHEMA = {
scisample/schema.py:    'cross_product': CROSS_PRODUCT_SCHEMA,
grep: tests/__pycache__: Is a directory
tests/test_samplers.py:#. CrossProductSampler,
tests/test_samplers.py:from scisample.cross_product import CrossProductSampler
tests/test_samplers.py:class TestScisampleCrossProduct(unittest.TestCase):
tests/test_samplers.py:    Scenario: normal tests for CrossProductSampler
tests/test_samplers.py:        Given a cross_product specification
tests/test_samplers.py:        Then I should get a CrossProductSampler
tests/test_samplers.py:                type: cross_product
tests/test_samplers.py:        self.assertTrue(isinstance(sampler, CrossProductSampler))

@daub1
Copy link
Contributor Author

daub1 commented Feb 22, 2021

@crkrenn the ensemble simply combines multiple samplers, so changes aren't needed to anything. You would simply pass the data for each sampler into it. Take a look at the test_ensemble.py tests.

@crkrenn
Copy link
Collaborator

crkrenn commented Feb 24, 2021

@daub1 (cc: @FrankD412),

I want to support maestrowf as well as codepy.

For example sample_list.yaml contains the following:

env:
    variables:
        OUTPUT_PATH: ./output
        SAMPLE_DICTIONARY:
            type: list
            constants:
                X1: 20
            parameters:
                X2: [ 5, 10 ]
                X3: [ 5, 10 ]

Ideally, your ensemble sampler would work with the following:

SAMPLE_DICTIONARY:
    - type: list
      parameters:
          X1: [5, 10]
          X2: [5, 10]
   - type: cross_product
     parameters:
          X1: [15, 20, 30]
          X2: [15, 20, 30]

but, it does not.

Can you tweak your implementation so that new_sampler(SAMPLE_DICTIONARY) will work with your proposed syntax?

-Chris

@daub1
Copy link
Contributor Author

daub1 commented Feb 25, 2021

@crkrenn new_sampler cannot yield an Ensemble object, because Ensemble uses new_sampler, so it results in a circular import. Otherwise I have implemented the above.

@crkrenn
Copy link
Collaborator

crkrenn commented Feb 25, 2021

I have some work to do for Alan today, but will try to look at this in detail tonight.

I'm guessing that "recursion" does not work?

def new_sampler(dictionary):
      if list_of_specs(dictionary):
            return ensemble(dictionary)
      else:
            return sampler(dictionary)

I also haven't pulled the thread on working around circular imports...

-Chris

@daub1
Copy link
Contributor Author

daub1 commented Feb 25, 2021

It will raise a circular import error. You can, however, just replace new_sampler with an Ensemble object, since it will call new_sampler for your data.

@crkrenn
Copy link
Collaborator

crkrenn commented Aug 17, 2022

@daub1,

Can you (or someone else) refactor so that "new_sampler" always creates an ensemble object?

Ideally, I'd like the old input format to still work:

SAMPLE_DICTIONARY:
    type: list
    parameters:
        X1: [5, 10]
        X2: [5, 10]

And, I'd like a new input format to generate an ensemble object containing multiple samplers. Ideally, the format of the individual samplers would be as close to the single sampler format as possible.

The following is a simple solution, but it may be fragile:

SAMPLE_DICTIONARY:
    - type: list
      parameters:
          X1: [5, 10]
          X2: [5, 10]
   - type: cross_product
     parameters:
          X1: [15, 20, 30]
          X2: [15, 20, 30]

The following feels more robust and extensible to me, but I'm open to other proposals.

SAMPLE_DICTIONARY:
  type: ensemble
  samplers:
    - type: list
      parameters:
          X1: [5, 10]
          X2: [5, 10]
    - type: cross_product
      parameters:
            X1: [15, 20, 30]
            X2: [15, 20, 30]

V/r,

-Chris

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.

2 participants