Kraysent / OMTool

Modeling N-Body problem in galactic evolution application.
https://omtool.readthedocs.io/en/latest/
Apache License 2.0
0 stars 0 forks source link

Decouple tasks from the main program #115

Closed Kraysent closed 2 years ago

Kraysent commented 2 years ago

Problem: If user wants to create new task, they need to create it and change list of tasks in actual code Desire: Completely decouple tasks from the program and initialize them at runtime Possible approach: create import directive in all configration files. It would describe list of tasks and directories with them as follows:

import: 
  - tasks/scatter_task.py
  - tasks/time_evolution_task.py
  - tasks/subdirectory/*

These tasks would be imported in runtime and then could be used in given configuration file.

Each file with the task should have following variables inside:

# Name of the task. Spaces are possible as well as any other symbols.
task_name: str = "ExampleTask"

# Function that would be called during initialization. It is optional. If your task need some inout parameters they would be passed here from the `args` section of the config.
initialize: Callable[[Any, ...], None] = lambda: None

# Function that takes snapshot and outputs dictionary with data. It will be called on eaxh iteration of analysis or integration.
run: Callable[[Snapshot], DataType] = lambda snapshot: {"length": len(snapshot.particles) }
Kraysent commented 2 years ago

Sticked with following tasks as classes and program now read task: Type field