Skip to content

Commit

Permalink
Merge pull request #37 from AllenNeuralDynamics/feat-update-curriculu…
Browse files Browse the repository at this point in the history
…m-dependency

Update curriculum dependencies
  • Loading branch information
bruno-f-cruz authored Jun 17, 2024
2 parents e68cf5e + f0b1098 commit 57a6d9f
Show file tree
Hide file tree
Showing 21 changed files with 300 additions and 112 deletions.
2 changes: 2 additions & 0 deletions examples/aind_manipulator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import os

from aind_behavior_services.base import get_commit_hash
from aind_behavior_services.calibration import aind_manipulator as m
Expand Down Expand Up @@ -41,6 +42,7 @@
)

seed_path = "local/aind_manipulator_{suffix}.json"
os.makedirs(os.path.dirname(seed_path), exist_ok=True)
with open(seed_path.format(suffix="calibration_logic"), "w") as f:
f.write(calibration_logic.model_dump_json(indent=3))
with open(seed_path.format(suffix="session"), "w") as f:
Expand Down
3 changes: 3 additions & 0 deletions examples/load_cells.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import os

from aind_behavior_services.base import get_commit_hash
from aind_behavior_services.calibration import load_cells as lc
Expand Down Expand Up @@ -42,6 +43,8 @@
)

seed_path = "local/load_cells_{suffix}.json"
os.makedirs(os.path.dirname(seed_path), exist_ok=True)

with open(seed_path.format(suffix="calibration_logic"), "w") as f:
f.write(calibration_logic.model_dump_json(indent=3))
with open(seed_path.format(suffix="session"), "w") as f:
Expand Down
3 changes: 3 additions & 0 deletions examples/olfactometer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import os

from aind_behavior_services.base import get_commit_hash
from aind_behavior_services.calibration import olfactometer as olf
Expand Down Expand Up @@ -65,6 +66,8 @@


seed_path = "local/olfactometer_{suffix}.json"
os.makedirs(os.path.dirname(seed_path), exist_ok=True)

with open(seed_path.format(suffix="calibration_logic"), "w") as f:
f.write(calibration_logic.model_dump_json(indent=3))
with open(seed_path.format(suffix="session"), "w") as f:
Expand Down
3 changes: 3 additions & 0 deletions examples/water_valve.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import os

from aind_behavior_services.base import get_commit_hash
from aind_behavior_services.calibration import water_valve as wv
Expand Down Expand Up @@ -55,6 +56,8 @@ def linear_model(time, slope, offset):
rig = wv.CalibrationRig(rig_name="WaterValveRig")

seed_path = "local/water_valve_{suffix}.json"
os.makedirs(os.path.dirname(seed_path), exist_ok=True)

with open(seed_path.format(suffix="calibration_logic"), "w") as f:
f.write(calibration_logic.model_dump_json(indent=3))
with open(seed_path.format(suffix="session"), "w") as f:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies = [
'gitpython>=3.1, <4.0',
'scikit-learn',
'semver',
'aind-behavior-curriculum@git+https://github.com/AllenNeuralDynamics/[email protected].2',
'aind-behavior-curriculum@git+https://github.com/AllenNeuralDynamics/[email protected].27',

]

Expand Down
2 changes: 1 addition & 1 deletion src/DataSchemas/aind_behavior_services/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.7.7"
__version__ = "0.7.8"

from .rig import AindBehaviorRigModel # noqa: F401
from .session import AindBehaviorSessionModel # noqa: F401
Expand Down
103 changes: 59 additions & 44 deletions src/DataSchemas/aind_behavior_services/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ def _print_diagnosis(self) -> None:
"""
Prints the diagnosis information for the launcher.
This method prints the diagnosis information, including the computer name, data directory, and config library directory.
This method prints the diagnosis information,
including the computer name, data directory,
and config library directory.
Parameters:
None
Expand Down Expand Up @@ -171,11 +173,16 @@ def _print_header(self) -> None:
print("-------------------------------")
print(self._HEADER)
print(
f"TaskLogic ({self.task_logic_schema.__name__}) Schema Version: {self.task_logic_schema.model_construct().version}"
f"TaskLogic ({self.task_logic_schema.__name__}) \
Schema Version: {self.task_logic_schema.model_construct().version}"
)
print(f"Rig ({self.rig_schema.__name__}) Schema Version: {self.rig_schema.model_construct().version}")
print(
f"Session ({self.session_schema.__name__}) Schema Version: {self.session_schema.model_construct().version}"
f"Rig ({self.rig_schema.__name__}) \
Schema Version: {self.rig_schema.model_construct().version}"
)
print(
f"Session ({self.session_schema.__name__}) \
Schema Version: {self.session_schema.model_construct().version}"
)
print("-------------------------------")
if self._dev_mode:
Expand All @@ -187,8 +194,9 @@ def save_temp_model(self, model: Union[TRig, TSession, TTaskLogic], folder: Opti
Args:
model (BaseModel): The model to be saved.
folder (Optional[os.PathLike | str]): The folder where the model should be saved. If not provided, the default
temporary folder will be used.
folder (Optional[os.PathLike | str]):
The folder where the model should be saved.
If not provided, the default temporary folder will be used.
Returns:
str: The file path of the saved model.
Expand Down Expand Up @@ -221,7 +229,8 @@ def _validate_dependencies(self) -> None:
raise FileNotFoundError(f"Config library not found! Expected {self.config_library_dir}.")
if not (os.path.isdir(os.path.join(self.config_library_dir, "Rig", self.computer_name))):
raise FileNotFoundError(
f"Rig configuration not found! Expected {os.path.join(self.config_library_dir, self.RIG_DIR, self.computer_name)}."
f"Rig configuration not found! \
Expected {os.path.join(self.config_library_dir, self.RIG_DIR, self.computer_name)}."
)
if not (os.path.isfile(os.path.join(self.default_workflow))):
raise FileNotFoundError(f"Bonsai workflow file not found! Expected {self.default_workflow}.")
Expand Down Expand Up @@ -519,43 +528,8 @@ def __init__(
**launcher_kwargs,
) -> None:

parser = argparse.ArgumentParser()

parser.add_argument("--data_dir", help="Specify the data directory")
parser.add_argument("--remote_data_dir", help="Specify the remote data directory")
parser.add_argument("--repository_dir", help="Specify the repository directory")
parser.add_argument("--config_library_dir", help="Specify the configuration library directory")
parser.add_argument("--workflow", help="Specify the workflow")
parser.add_argument(
"--force_create_directories",
help="Specify whether to force create directories",
action="store_true",
default=False,
)
parser.add_argument("--dev_mode", help="Specify whether to run in dev mode", action="store_true", default=False)
parser.add_argument(
"--bonsai_is_editor_mode",
help="Specify whether to run in Bonsai editor mode",
action="store_false",
default=True,
)
parser.add_argument(
"--bonsai_is_start_flag",
help="Specify whether to start the Bonsai workflow",
action="store_false",
default=True,
)
parser.add_argument(
"--allow_dirty_repo", help="Specify whether to allow a dirty repository", action="store_true", default=False
)
parser.add_argument(
"--skip_hardware_validation",
help="Specify whether to skip hardware validation",
action="store_true",
default=False,
)

args = parser.parse_args()
parser = self._get_default_arg_parser()
args, _ = parser.parse_known_args()

# optional parameters that override the defaults
data_dir = args.data_dir if args.data_dir is not None else data_dir
Expand Down Expand Up @@ -600,3 +574,44 @@ def make_folder_structure(self) -> None:

def _validate_dependencies(self) -> None:
self.launcher._validate_dependencies()

@staticmethod
def _get_default_arg_parser() -> argparse.ArgumentParser:

parser = argparse.ArgumentParser()

parser.add_argument("--data_dir", help="Specify the data directory")
parser.add_argument("--remote_data_dir", help="Specify the remote data directory")
parser.add_argument("--repository_dir", help="Specify the repository directory")
parser.add_argument("--config_library_dir", help="Specify the configuration library directory")
parser.add_argument("--workflow", help="Specify the workflow")
parser.add_argument(
"--force_create_directories",
help="Specify whether to force create directories",
action="store_true",
default=False,
)
parser.add_argument("--dev_mode", help="Specify whether to run in dev mode", action="store_true", default=False)
parser.add_argument(
"--bonsai_is_editor_mode",
help="Specify whether to run in Bonsai editor mode",
action="store_false",
default=True,
)
parser.add_argument(
"--bonsai_is_start_flag",
help="Specify whether to start the Bonsai workflow",
action="store_false",
default=True,
)
parser.add_argument(
"--allow_dirty_repo", help="Specify whether to allow a dirty repository", action="store_true", default=False
)
parser.add_argument(
"--skip_hardware_validation",
help="Specify whether to skip hardware validation",
action="store_true",
default=False,
)

return parser
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class TaskParameters(curriculum_task.TaskParameters):
class AindBehaviorTaskLogicModel(curriculum_task.Task):

task_parameters: TaskParameters = Field(..., description="Parameters of the task logic", validate_default=True)
version: str = Field(..., pattern=curriculum_task.SEMVER_REGEX, description="task schema version")

@field_validator("version", mode="before")
@classmethod
Expand Down
15 changes: 11 additions & 4 deletions src/DataSchemas/aind_behavior_services/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,17 @@ def bonsai_sgen(
CompletedProcess: The result of running the command.
Args:
schema_path (PathLike): Target Json Schema file
output_path (PathLike): Specifies the name of the file containing the generated code.
namespace (Optional[str], optional): Specifies the namespace to use for all generated serialization classes. Defaults to DataSchema.
root_element (Optional[str], optional): Specifies the name of the class used to represent the schema root element. If None, it will use the json schema root element. Defaults to None.
serializer (Optional[List[BonsaiSgenSerializers]], optional): Specifies the serializer data annotations to include in the generated classes. Defaults to None.
output_path (PathLike): Specifies the name of the
file containing the generated code.
namespace (Optional[str], optional): Specifies the
namespace to use for all generated serialization
classes. Defaults to DataSchema.
root_element (Optional[str], optional): Specifies the
name of the class used to represent the schema root element.
If None, it will use the json schema root element. Defaults to None.
serializer (Optional[List[BonsaiSgenSerializers]], optional):
Specifies the serializer data annotations to include in the generated classes.
Defaults to None.
"""

if serializer is None:
Expand Down
21 changes: 17 additions & 4 deletions src/DataSchemas/schemas/aind_manipulator_calibration_logic.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,32 @@
"title": "Description",
"type": "string"
},
"task_parameters": {
"allOf": [
{
"$ref": "#/definitions/CalibrationParameters"
}
],
"title": "Task parameters"
},
"version": {
"const": "0.2.0",
"default": "0.2.0",
"title": "Version",
"type": "string"
},
"task_parameters": {
"allOf": [
"stage_name": {
"default": null,
"description": "Optional stage name the `Task` object instance represents.",
"oneOf": [
{
"$ref": "#/definitions/CalibrationParameters"
"type": "string"
},
{
"type": "null"
}
],
"title": "Task parameters"
"title": "Stage Name"
}
},
"required": [
Expand Down
21 changes: 17 additions & 4 deletions src/DataSchemas/schemas/load_cells_calibration_logic.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,32 @@
"title": "Description",
"type": "string"
},
"task_parameters": {
"allOf": [
{
"$ref": "#/definitions/CalibrationParameters"
}
],
"title": "Task parameters"
},
"version": {
"const": "0.4.0",
"default": "0.4.0",
"title": "Version",
"type": "string"
},
"task_parameters": {
"allOf": [
"stage_name": {
"default": null,
"description": "Optional stage name the `Task` object instance represents.",
"oneOf": [
{
"$ref": "#/definitions/CalibrationParameters"
"type": "string"
},
{
"type": "null"
}
],
"title": "Task parameters"
"title": "Stage Name"
}
},
"required": [
Expand Down
21 changes: 17 additions & 4 deletions src/DataSchemas/schemas/olfactometer_calibration_logic.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,32 @@
"title": "Description",
"type": "string"
},
"task_parameters": {
"allOf": [
{
"$ref": "#/definitions/CalibrationParameters"
}
],
"title": "Task parameters"
},
"version": {
"const": "0.4.0",
"default": "0.4.0",
"title": "Version",
"type": "string"
},
"task_parameters": {
"allOf": [
"stage_name": {
"default": null,
"description": "Optional stage name the `Task` object instance represents.",
"oneOf": [
{
"$ref": "#/definitions/CalibrationParameters"
"type": "string"
},
{
"type": "null"
}
],
"title": "Task parameters"
"title": "Stage Name"
}
},
"required": [
Expand Down
21 changes: 17 additions & 4 deletions src/DataSchemas/schemas/water_valve_calibration_logic.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,32 @@
"title": "Description",
"type": "string"
},
"task_parameters": {
"allOf": [
{
"$ref": "#/definitions/CalibrationParameters"
}
],
"title": "Task parameters"
},
"version": {
"const": "0.4.0",
"default": "0.4.0",
"title": "Version",
"type": "string"
},
"task_parameters": {
"allOf": [
"stage_name": {
"default": null,
"description": "Optional stage name the `Task` object instance represents.",
"oneOf": [
{
"$ref": "#/definitions/CalibrationParameters"
"type": "string"
},
{
"type": "null"
}
],
"title": "Task parameters"
"title": "Stage Name"
}
},
"required": [
Expand Down
Loading

0 comments on commit 57a6d9f

Please sign in to comment.