AllenNeuralDynamics / aind-behavior-curriculum

Starter repository for behavior base primitives.
https://aind-behavior-curriculum.readthedocs.io
MIT License
1 stars 0 forks source link

Implement the dynamic foraging task as an example #10

Closed dyf closed 4 months ago

dyf commented 4 months ago
alexpiet commented 4 months ago
bruno-f-cruz commented 4 months ago

This is the pattern i would suggest using the Vr Foraging task as an example:

# For now it assumes the following dependencies that can be pip installed using:
# pip install git+https://github.com/AllenNeuralDynamics/aind-behavior-curriculum.git@refs/pull/9/merge
# pip install git+https://github.com/AllenNeuralDynamics/Aind.Behavior.VrForaging.git@a1e4a15695a3117d825e3b4f6744ae2e66fe14ed

from typing import Dict, Literal

from aind_behavior_curriculum.behavior import GenericModel, Task
from aind_behavior_vr_foraging.task_logic import (EnvironmentStatistics,
                                                  ForagingSettings,
                                                  NumericalUpdater,
                                                  OperationControl,
                                                  TaskModeSettings)
from pydantic import Field

class VrForagingTaskParameters(GenericModel):
    """Class that represents the parameters necessary to instantiate the task logic of the Vr Foraging task"""

    updaters: Dict[str, NumericalUpdater] = Field(
        default_factory=dict, description="List of numerical updaters"
    )
    environment_statistics: EnvironmentStatistics = Field(
        ..., description="Statistics of the environment"
    )
    task_mode_settings: TaskModeSettings = Field(
        ForagingSettings(),
        description="Settings of the task stage",
        validate_default=True,
    )
    operation_control: OperationControl = Field(
        ..., description="Control of the operation"
    )

class VrForagingTask(Task):
    """Model for a VrForagingTask"""

    name: Literal["VrForaging"] = "VrForaging"
    version: Literal["0.0.1-preview01"] = "0.0.1-preview01"
    description: str = Field(default="This is a task schema for the VR task")
    task_parameters: VrForagingTaskParameters = Field(
        ..., description=VrForagingTaskParameters.__doc__
    )

print(VrForagingTaskParameters.model_json_schema())

Might be obvious, but do not make this repo dependent on any task repo (e.g. VrForaging or DynamicForaging). It would be a nightmare to maintain dependencies and it would also result in a circular dependency between this and the task-specific repo.