Skip to content

Commit

Permalink
Merge pull request #281 from ihmeuw/collijk/feature/add-introspection…
Browse files Browse the repository at this point in the history
…-tools-to-interactive-context

Add lifecycle/initializer introspection to InteractiveContext
  • Loading branch information
collijk committed Feb 25, 2023
2 parents 7b71c27 + a6d7c74 commit 1bb26bf
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/vivarium/interface/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,21 @@ def get_component(self, name: str) -> Any:
"""
return self._component_manager.get_component(name)

def print_initializer_order(self):
"""Print the order in which population initializers are called."""
initializers = []
for r in self._resource:
name = r.__name__
if hasattr(r, "__self__"):
obj = r.__self__
initializers.append(f"{obj.__class__.__name__}({obj.name}).{name}")
else:
initializers.append(f"Unbound function {name}")
print("\n".join(initializers))

def print_lifecycle_order(self):
"""Print the order of lifecycle events (including user event handlers)."""
print(self._lifecycle)

def __repr__(self):
return "InteractiveContext()"

0 comments on commit 1bb26bf

Please sign in to comment.