From 1da67200198a692c080b5bd97e5ad60190b630c7 Mon Sep 17 00:00:00 2001 From: Rory Conlin Date: Wed, 24 Jul 2024 13:56:25 -0400 Subject: [PATCH] Add utility for determine tiers in data_index --- desc/compute/__init__.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/desc/compute/__init__.py b/desc/compute/__init__.py index 416825cc55..87f03068bb 100644 --- a/desc/compute/__init__.py +++ b/desc/compute/__init__.py @@ -94,3 +94,30 @@ def _build_data_index(): _build_data_index() + + +def set_tier(name, p): + """Determine how deep in the dependency tree a given name is. + + tier of 0 means no dependencies on other data, + tier of 1 means it depends on only tier 0 stuff, + tier of 2 means it depends on tier 0 and tier 1, etc etc. + + Designed such that if you compute things in the order determined by tiers, + all dependencies will always be computed in the correct order. + """ + if "tier" in data_index[p][name]: + return + if len(data_index[p][name]["full_with_axis_dependencies"]["data"]) == 0: + data_index[p][name]["tier"] = 0 + else: + thistier = 0 + for name1 in data_index[p][name]["full_with_axis_dependencies"]["data"]: + set_tier(name1, p) + thistier = max(thistier, data_index[p][name1]["tier"]) + data_index[p][name]["tier"] = thistier + 1 + + +for par in data_index.keys(): + for name in data_index[par]: + set_tier(name, par)