Skip to content

Model Builder refactoring #119

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

Closed

Conversation

michaelraczycki
Copy link
Collaborator

In order to make the model_builder a template class for other model-related pymc classes we need to restructure its constructor. So far it was assuming presence of build_model function in child class which is not always going to be the case.

changes:
build() function call was moved out of the constructor, and now is called from fit function. This change allows inheritance from ModelBuilder by abstract classes like baseMMM

@michaelraczycki
Copy link
Collaborator Author

@twiecki this is just a starter of final PR, let's not merge it yet as I might find other necessary changes while trying to integrate ModelBuilder with BaseMMM.

@michaelraczycki michaelraczycki changed the title moving build out of constructor Model Builder refactoring Mar 24, 2023
@michaelraczycki
Copy link
Collaborator Author

As recently we've came to a conclusion that for variety of projects it will be unsuitable to have Model Builder as a child of pm.Model, this PR will be used for refactoring tasks that will prepare new structure of ModelBuilder.

General changes will include:
removing the inheritance from pm.Model
adding class attribute containing an pm.Model object
adaptation of existing functions to accommodate the changes
adaptation of tests

@michaelraczycki michaelraczycki marked this pull request as draft March 26, 2023 14:46
def build_model(self, model_config, data=None):

def build_model(self, model_instance, model_config, data=None):
model_instance.model_config = model_config
Copy link
Member

Choose a reason for hiding this comment

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

I think we can just keep the model_config and data in the base class (instance self). The init() method should also take care of that.

@twiecki
Copy link
Member

twiecki commented Mar 30, 2023

If you rebase from main again, #125 should have fixed CI.

@michaelraczycki michaelraczycki self-assigned this Mar 30, 2023
@michaelraczycki michaelraczycki added the enhancements New feature or request label Mar 30, 2023
@@ -37,8 +37,8 @@ class ModelBuilder:
def __init__(
self,
model_config: Dict,
Copy link
Member

Choose a reason for hiding this comment

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

make model_config also optional and move down.

@@ -233,21 +239,26 @@ def fit(
self._data_setter(data)

with self.model:
self.idata = pm.sample(**self.sample_config)
if self.sampler_config is not None:
Copy link
Member

Choose a reason for hiding this comment

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

in init you can just set sampler_config to {} if it's None.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

true, good catch!

@michaelraczycki
Copy link
Collaborator Author

@twiecki it seem that after rebasing the original issue with test is solved, but a lot of not-related tests fail both in ubuntu and windows

@twiecki
Copy link
Member

twiecki commented Mar 30, 2023

Hm, I think something went wrong with the rebasing, those errors should be fixed.

@michaelraczycki
Copy link
Collaborator Author

Ok, tried to do rebase again, hopefully runs good this time

ricardoV94 and others added 4 commits March 30, 2023 14:59
* Update API reference listings
* improve api page+some fixes
* update to pymc theme
* add pymc theme to requirements
* fix indent in docstring
---------

Co-authored-by: Oriol (ZBook) <[email protected]>
@@ -0,0 +1,5 @@
{{ objname | escape | underline }}
Copy link
Member

Choose a reason for hiding this comment

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

I think we made it worse :P, this hsouldn't show up here. Maybe start with a fresh PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, I'll try to just copy the changes to new branch, branched from fresh main and see if it helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancements New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants