Skip to content

Commit

Permalink
Allow component lineage with no binning (#180)
Browse files Browse the repository at this point in the history
* Allow componnet lineage with no binning

* Simplification

* Simplification
  • Loading branch information
dachengx authored Jul 31, 2024
1 parent 6042ee6 commit f77ae6b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 53 deletions.
27 changes: 14 additions & 13 deletions appletree/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,24 +570,25 @@ def new_component(self, llh_name: Optional[str] = None, pass_binning: bool = Tru

@property
def lineage(self):
return {
**{
"rate_name": self.rate_name,
"norm_type": self.norm_type,
bins_dict = dict()
if hasattr(self, "bins") or hasattr(self, "bins_type"):
bins_dict = {
"bins": (
tuple(b.tolist() for b in self.bins) if self.bins is not None else self.bins
),
"bins_type": self.bins_type,
"code": self.code,
},
**{
"instances": dict(
zip(
self.instances,
[_cached_functions[self.llh_name][p].lineage for p in self.instances],
)
}
return {
"rate_name": self.rate_name,
"norm_type": self.norm_type,
"code": self.code,
"instances": dict(
zip(
self.instances,
[_cached_functions[self.llh_name][p].lineage for p in self.instances],
)
},
),
**bins_dict,
}


Expand Down
4 changes: 2 additions & 2 deletions appletree/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,14 +399,14 @@ def update_parameter_config(self, likelihoods):
def lineage(self):
return {
**self.instruct,
**{"par_config": self.par_config},
**{
"par_config": self.par_config,
"likelihoods": dict(
zip(
self.likelihoods.keys(),
[v.lineage for v in self.likelihoods.values()],
)
)
),
},
}

Expand Down
44 changes: 18 additions & 26 deletions appletree/likelihood.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,23 +415,19 @@ def print_likelihood_summary(self, indent: str = " " * 4, short: bool = True):
@property
def lineage(self):
return {
**{
"config": self._config,
"file_path": (
os.path.basename(self._data_file_name)
if not utils.FULL_PATH_LINEAGE
else get_file_path(self._data_file_name)
),
"sha256": calculate_sha256(get_file_path(self._data_file_name)),
},
**{
"components": dict(
zip(
self.components.keys(),
[v.lineage for v in self.components.values()],
)
"config": self._config,
"file_path": (
os.path.basename(self._data_file_name)
if not utils.FULL_PATH_LINEAGE
else get_file_path(self._data_file_name)
),
"sha256": calculate_sha256(get_file_path(self._data_file_name)),
"components": dict(
zip(
self.components.keys(),
[v.lineage for v in self.components.values()],
)
},
),
}

@property
Expand Down Expand Up @@ -591,15 +587,11 @@ def print_likelihood_summary(self, indent: str = " " * 4, short: bool = True):
@property
def lineage(self):
return {
**{
"config": self._config,
},
**{
"components": dict(
zip(
self.components.keys(),
[v.lineage_hash for v in self.components.values()],
)
"config": self._config,
"components": dict(
zip(
self.components.keys(),
[v.lineage_hash for v in self.components.values()],
)
},
),
}
20 changes: 8 additions & 12 deletions appletree/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,15 @@ def sanity_check(self):
@property
def lineage(self):
return {
**{
"depends_on": self.depends_on,
"provides": self.provides,
"parameters": self.parameters,
},
**{
"takes_config": dict(
zip(
self.takes_config.keys(),
[v.lineage for v in self.takes_config.values()],
)
"depends_on": self.depends_on,
"provides": self.provides,
"parameters": self.parameters,
"takes_config": dict(
zip(
self.takes_config.keys(),
[v.lineage for v in self.takes_config.values()],
)
},
),
}

@property
Expand Down

0 comments on commit f77ae6b

Please sign in to comment.