Skip to content

Commit

Permalink
Remove Context.set_config to avoid confusion from Config.required_par…
Browse files Browse the repository at this point in the history
…ameter
  • Loading branch information
dachengx committed Nov 11, 2023
1 parent dd55b72 commit f08acf0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 33 deletions.
8 changes: 5 additions & 3 deletions appletree/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,14 @@ def dependencies_simplify(self, dependencies):
"""Simplify the dependencies."""
already_seen = []
self.worksheet = []
# Reinitialize needed_parameters
# because sometimes user will deduce(& compile) after changing configs
self.needed_parameters: Set[str] = set()
# Add rate_name to needed_parameters only when it's not empty
self.needed_parameters = set()
if self.rate_name != "":
self.needed_parameters.add(self.rate_name)
for plugin in dependencies[::-1]:
plugin = plugin["plugin"]
for _plugin in dependencies[::-1]:
plugin = _plugin["plugin"]
if plugin.__name__ in already_seen:
continue
self.worksheet.append([plugin.__name__, plugin.provides, plugin.depends_on])
Expand Down
33 changes: 3 additions & 30 deletions appletree/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def __init__(self, instruct, par_config=None):
if "url_base" in instruct.keys():
self.update_url_base(instruct["url_base"])

self.set_instruct(instruct)
if "configs" in instruct.keys():
self.set_config(instruct["configs"])
self.instruct = instruct
self.config = instruct.get("configs", {})
set_global_config(self.config)

self.backend_h5 = instruct.get("backend_h5", None)

Expand Down Expand Up @@ -358,33 +358,6 @@ def update_parameter_config(self, likelihoods):
self.par_config.pop(p)
return needed_parameters

def set_instruct(self, instructs):
"""Set instruction.
:param instructs: dict, instruction file name or dictionary
"""
if not hasattr(self, "instruct"):
self.instruct = dict()

# update instructuration only in this Context
self.instruct.update(instructs)

def set_config(self, configs):
"""Set new configuration options.
:param configs: dict, configuration file name or dictionary
"""
if not hasattr(self, "config"):
self.config = dict()

# update configuration only in this Context
self.config.update(configs)

# also store required configurations to appletree.share
set_global_config(configs)

def lineage(self, data_name: str = "cs2"):
"""Return lineage of plugins."""
assert isinstance(data_name, str)
Expand Down

0 comments on commit f08acf0

Please sign in to comment.