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

Remove reference cycles between MockFactory and ModelFactory. #918

Merged
merged 7 commits into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions halotools/empirical_models/factories/mock_factory_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .mock_helpers import three_dim_pos_bundle, infer_mask_from_kwargs

from .. import model_helpers, model_defaults
import weakref

try:
from ... import mock_observables
Expand Down Expand Up @@ -76,6 +77,7 @@ def __init__(self, **kwargs):
except:
pass


# Create a list of halo properties that will be inherited by the mock galaxies
self.additional_haloprops = copy(model_defaults.default_haloprop_list_inherited_by_mock)

Expand All @@ -86,6 +88,15 @@ def __init__(self, **kwargs):

self.galaxy_table = Table()

@property
def model(self):
""" model, a weak reference to the model because mock is always a member of model """
return self._model()

@model.setter
def model(self, value):
self._model = weakref.ref(value)

@abstractmethod
def populate(self, **kwargs):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,12 @@ def update_param_dict_decorator(self, component_model, func_name):
:ref:`param_dict_mechanism`
"""

def decorated_func(*args, **kwargs):
def decorated_func(*args, __param_dict__=self.param_dict, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

@rainwoodman - this line seems to be causing problems for a few builds. Any idea why? See https://travis-ci.org/astropy/halotools/jobs/399786150.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's incompatible with Python 2.7. I pushed a fix.


# Update the param_dict as necessary
for key in list(self.param_dict.keys()):
for key in list(__param_dict__.keys()):
if key in component_model.param_dict:
component_model.param_dict[key] = self.param_dict[key]
component_model.param_dict[key] = __param_dict__[key]

func = getattr(component_model, func_name)
return func(*args, **kwargs)
Expand Down