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
Sampler and Workflow Refactor #187
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rHorsey It's still kind of rough and doesn't work, but what are your thoughts on the direction of this?
class SimulationExists(Exception): | ||
|
||
def __init__(self, msg, sim_id, sim_dir): | ||
super().__init__(msg) | ||
self.sim_id = sim_id | ||
self.sim_dir = sim_dir | ||
|
||
|
||
class ValidationError(Exception): | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These had to be moved to avoid a circular import.
else: | ||
return os.path.abspath(os.path.join(os.path.dirname(startfile), x)) | ||
def get_sampler_class(sampler_name): | ||
sampler_class_name = ''.join(x.capitalize() for x in sampler_name.strip().split('_')) + 'Sampler' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
residential_quota
➡️ ResidentialQuotaSampler
buildstockbatch/base.py
Outdated
Sampler = self.get_sampler_class(self.cfg['sampler']['type']) | ||
self.sampler = Sampler(self, **self.cfg['sampler'].get('args', {})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much simpler than the logic we used to have. Each sampler will then define its own arguments and have validation for it.
key, value = logic.split('|') | ||
return df[key] == value | ||
|
||
def downselect(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this into its own sampler class.
buildstockbatch/base.py
Outdated
def validate_sampler(project_file): | ||
cfg = BuildStockBatchBase.get_project_configuration(project_file) | ||
sampler_name = cfg['sampler']['type'] | ||
try: | ||
Sampler = BuildStockBatchBase.get_sampler_class(sampler_name) | ||
except AttributeError: | ||
raise ValidationError(f'Sampler class `{sampler_name}` is not available.') | ||
args = cfg['sampler']['args'] | ||
return Sampler.validate_args(project_file, **args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each sampler defines its own validation, which gets called as part of the validation step.
@@ -47,6 +46,8 @@ def get_bool_env_var(varname): | |||
|
|||
class EagleBatch(BuildStockBatchBase): | |||
|
|||
CONTAINER_RUNTIME = ContainerRuntime.SINGULARITY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each Batch
class tells has this enum on it to identify which container runtime it uses. The samplers then read this and call the appropriate method. This allows us to not have separate docker and singularity classes.
self.cfg = cfg | ||
self.buildstock_dir = buildstock_dir | ||
self.project_dir = project_dir | ||
self.parent = weakref.ref(parent) # This removes circular references and allows garbage collection to work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pass the parent object to here and use python's weakref to avoid problems with circular references and garbage collection. This allows the child object to read stuff off the parent, such as which container runtime it uses.
logger = logging.getLogger(__name__) | ||
|
||
|
||
class DownselectSamplerBase(BuildStockSampler): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Subclass from this class to do downselecting for a particular sampler, as long as it takes the n_datapoints
arg. Then you specify the downselect version of the sampler if that's what you want.
class ResidentialQuotaDownselectSampler(DownselectSamplerBase): | ||
SUB_SAMPLER_CLASS = ResidentialQuotaSampler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's one of the downselect versions of a sampler class.
@ejhw @rHorsey @joseph-robertson This represents a pretty major change to the configuration files set up. I'm pretty satisfied that's it's working at this point. I'd appreciate it if you guys read over the docs changes and let me know if it communicates it well enough. You can see the generated docs from CicleCI by clicking on the CircleCI check, Artifacts tab, then docs/index.html. @rHorsey I have not tried this with ComStock. I think it should work. There are gaps in the commercial sobol sampler documentation and tests. If you don't have time to review now we can just merge it and do bugfixes later to get ComStock working again. |
@nmerket: It makes sense to put the |
@afontani, yes it does make it easier to add another sampler. It separates the sampler code into a class that provides a specific interface. If you want to make a new sampler, you just need to create a new class that does sampling according to whatever method you want as long as it matches that interface. The same is true of workflow generators. This will help with allowing for workflow generators for HPXML and eventually Home Energy Score. |
Update yamls:
|
@ejhw Are we still maintaining project_resstock_national_upgrades.yml? |
@ejhw Heads up, I updated project_resstock_national_upgrades.yml to use the new schema version, but it doesn't work because the upgrade options don't match what's in resstock anymore. |
@nmerket Thanks for the heads up. Yes, we should still maintain it; though I'd like to move it to /resstock. Do you think that makes sense? |
buildstockbatch/test/test_inputs/enforce-validate-measures-bad-2.yml
Outdated
Show resolved
Hide resolved
buildstockbatch/test/test_inputs/enforce-validate-measures-bad-2.yml
Outdated
Show resolved
Hide resolved
@joseph-robertson Can you approve? Looks like @nmerket resolved your requested changes. |
Fixes #147.
Pull Request Description
Checklist
Not all may apply