Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-f-cruz committed Oct 14, 2024
2 parents 6427a58 + 1e8e890 commit e3a6dff
Show file tree
Hide file tree
Showing 33 changed files with 102 additions and 292 deletions.
72 changes: 67 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ A repository containing code for data acquisition and processing for AIND behavi

---

## Deployment
## Installation

Install the [prerequisites](#prerequisites) mentioned below.
From the root of the repository, run `./scripts/deploy.ps1` to bootstrap both python and bonsai environments.
The python package can be installed from pypi using the following command:

---
```bash
pip install aind-behavior-services
```

However, to use all the tasks and hardware that this package supports, you should over over the [prerequisites](#prerequisites) and [deployment](#deployment) sections.

## Prerequisites

Check warning on line 18 in README.md

View workflow job for this annotation

GitHub Actions / pages

undefined label: 'prerequisites'

Check warning on line 18 in README.md

View workflow job for this annotation

GitHub Actions / pages

undefined label: 'deployment'
Expand All @@ -24,6 +27,13 @@ These should only need to be installed once on a fresh new system, and are not r

---

## Deployment

Install the [prerequisites](#prerequisites) mentioned below.
From the root of the repository, run `./scripts/deploy.ps1` to bootstrap both python and bonsai environments.

---

## Generating valid JSON input files

One of the core principles of this repository is the strict adherence to [json-schemas](https://json-schema.org/). We use [Pydantic](https://pydantic.dev/) as a way to write and compile our schemas, but also to generate valid JSON input files. These files can be used by Bonsai (powered by [Bonsai.SGen](https://github.com/bonsai-rx/sgen) code generation tool) or to simply record metadata. Examples of how to interact with the library can be found in the `./examples` folder.
Expand Down Expand Up @@ -58,4 +68,56 @@ Where possible, adhere to [Semantic Versioning](https://semver.org/).

## Project dependency tree

![Dependency tree](https://github.com/AllenNeuralDynamics/Aind.Behavior.Services/raw/main/assets/dependency_tree.drawio.svg)

```mermaid
classDiagram
class aind_behavior_curriculum {
+Task
+Curriculum
}
class aind_behavior_services {
+Task (Subclasses)
+Rig (maintains hardware library)
+Session
+Calibration (maintains device/calibration library)
+Deployment instructions
+Ecosystem documentation
}

Check warning on line 87 in README.md

View workflow job for this annotation

GitHub Actions / pages

Pygments lexer name 'mermaid' is not known
class aind_behavior_experiment_launcher {
+Launch experiment
+Interfaces with external applications (e.g. Bonsai)
+Interfaces with aind-services
}
class aind_behavior_some_task {
+Concrete implementation of a task
+Rig (Subclasses for some task)
+Session
+Task Logic (Subclasses for some task)
+Maintains a task data-schema
+Saves data in standard format
}
class aind_behavior_some_task_analysis {
+Analysis code for some task
}
class aind_behavior_core_analysis {
+Data ingestion
+Data contract definition
+Core analysis primitives
+QC
}
aind_behavior_curriculum --|> aind_behavior_services : Subclasses Task
aind_behavior_services --|> aind_behavior_some_task
aind_behavior_some_task --|> aind_behavior_some_task_analysis : Analysis
aind_behavior_core_analysis --|> aind_behavior_some_task_analysis : Imports core analysis methods
aind_behavior_some_task_analysis --|> aind_behavior_curriculum : Metrics[Task]
aind_behavior_experiment_launcher --|> aind_behavior_some_task : Launches
```

236 changes: 0 additions & 236 deletions assets/dependency_tree.drawio

This file was deleted.

4 changes: 0 additions & 4 deletions assets/dependency_tree.drawio.svg

This file was deleted.

2 changes: 1 addition & 1 deletion docs/_static/AindBehaviorSessionModel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Extensions/AindBehaviorSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace AindBehaviorServices.AindBehaviorSession
public partial class AindBehaviorSessionModel
{

private string _aindBehaviorServicesPkgVersion = "0.8.0";
private string _aindBehaviorServicesPkgVersion = "0.8.1";

private string _version = "0.3.0";

Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/AindManipulatorCalibrationLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class CalibrationParameters

private double? _rngSeed;

private string _aindBehaviorServicesPkgVersion = "0.8.0";
private string _aindBehaviorServicesPkgVersion = "0.8.1";

public CalibrationParameters()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/AindManipulatorCalibrationRig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ public enum MotorOperationMode
public partial class CalibrationRig
{

private string _aindBehaviorServicesPkgVersion = "0.8.0";
private string _aindBehaviorServicesPkgVersion = "0.8.1";

private string _version = "0.1.0";

Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/LoadCellsCalibrationLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class CalibrationParameters

private double? _rngSeed;

private string _aindBehaviorServicesPkgVersion = "0.8.0";
private string _aindBehaviorServicesPkgVersion = "0.8.1";

private System.Collections.Generic.List<int> _channels = new System.Collections.Generic.List<int>();

Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/LoadCellsCalibrationRig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ public override string ToString()
public partial class CalibrationRig
{

private string _aindBehaviorServicesPkgVersion = "0.8.0";
private string _aindBehaviorServicesPkgVersion = "0.8.1";

private string _version = "0.0.0";

Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/OlfactometerCalibrationLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class CalibrationParameters

private double? _rngSeed;

private string _aindBehaviorServicesPkgVersion = "0.8.0";
private string _aindBehaviorServicesPkgVersion = "0.8.1";

private System.Collections.Generic.IDictionary<string, OlfactometerChannelConfig> _channelConfig;

Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/OlfactometerCalibrationRig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ public enum OlfactometerChannelType
public partial class CalibrationRig
{

private string _aindBehaviorServicesPkgVersion = "0.8.0";
private string _aindBehaviorServicesPkgVersion = "0.8.1";

private string _version = "0.0.0";

Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/TreadmillCalibrationLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class CalibrationParameters

private double? _rngSeed;

private string _aindBehaviorServicesPkgVersion = "0.8.0";
private string _aindBehaviorServicesPkgVersion = "0.8.1";

public CalibrationParameters()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/TreadmillCalibrationRig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ public override string ToString()
public partial class CalibrationRig
{

private string _aindBehaviorServicesPkgVersion = "0.8.0";
private string _aindBehaviorServicesPkgVersion = "0.8.1";

private string _version = "0.0.0";

Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/WaterValveCalibrationLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class CalibrationParameters

private double? _rngSeed;

private string _aindBehaviorServicesPkgVersion = "0.8.0";
private string _aindBehaviorServicesPkgVersion = "0.8.1";

private System.Collections.Generic.List<double> _valveOpenTime = new System.Collections.Generic.List<double>();

Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/WaterValveCalibrationRig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace AindBehaviorServices.WaterValveCalibrationRig
public partial class CalibrationRig
{

private string _aindBehaviorServicesPkgVersion = "0.8.0";
private string _aindBehaviorServicesPkgVersion = "0.8.1";

private string _version = "0.0.0";

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

from .rig import AindBehaviorRigModel # noqa: F401
from .session import AindBehaviorSessionModel # noqa: F401
Expand Down
9 changes: 3 additions & 6 deletions src/aind_behavior_services/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SchemaVersionedModel(BaseModel):
)
version: str = Field(..., pattern=SEMVER_REGEX, description="schema version", title="Version", frozen=True)

@field_validator("aind_behavior_services_pkg_version", mode="before", check_fields=False)
@field_validator("aind_behavior_services_pkg_version", "version", mode="before", check_fields=False)
@classmethod
def coerce_version(cls, v: str, ctx) -> str:
return coerce_schema_version(cls, v, ctx.field_name)
Expand Down Expand Up @@ -72,14 +72,11 @@ def coerce_schema_version(cls: type[SchemaVersionedModel], v: str, version_strin
semver = Version.parse(v)
if semver > _default_schema_version:
raise ValueError(
f"Deserialized schema version ({semver}) \
is greater than the current version({_default_schema_version})."
f"Error deserializing versioned field {version_string} (v{semver} > v{_default_schema_version})"
)
elif semver < _default_schema_version:
warnings.warn(
f"Deserialized schema version ({semver}) \
is less than the current version({_default_schema_version}). \
Will attempt to coerce the conversion."
f"Coercing deserialized versioned field {version_string} (v{semver} < v{_default_schema_version})"
)
return str(_default_schema_version)
else:
Expand Down
7 changes: 1 addition & 6 deletions src/aind_behavior_services/rig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from pydantic import BaseModel, Field, RootModel, field_validator

from aind_behavior_services.base import SchemaVersionedModel, coerce_schema_version
from aind_behavior_services.base import SchemaVersionedModel


class Device(BaseModel):
Expand Down Expand Up @@ -275,8 +275,3 @@ class Screen(Device):
class AindBehaviorRigModel(SchemaVersionedModel):
computer_name: str = Field(default_factory=lambda: os.environ["COMPUTERNAME"], description="Computer name")
rig_name: str = Field(..., description="Rig name")

@field_validator("version", mode="before")
@classmethod
def coerce_version(cls, v: str) -> str:
return coerce_schema_version(cls, v)
9 changes: 2 additions & 7 deletions src/aind_behavior_services/session/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import datetime
from typing import List, Literal, Optional, Self

from pydantic import Field, field_validator, model_validator
from pydantic import Field, model_validator

import aind_behavior_services.utils
from aind_behavior_services.base import SchemaVersionedModel, coerce_schema_version
from aind_behavior_services.base import SchemaVersionedModel

__version__ = "0.3.0"

Expand All @@ -28,11 +28,6 @@ class AindBehaviorSessionModel(SchemaVersionedModel):
allow_dirty_repo: bool = Field(default=False, description="Allow running from a dirty repository")
skip_hardware_validation: bool = Field(default=False, description="Skip hardware validation")

@field_validator("version", mode="before")
@classmethod
def coerce_version(cls, v: str, ctx) -> str:
return coerce_schema_version(cls, v)

@model_validator(mode="after")
def generate_session_name_default(self) -> Self:
if self.session_name is None:
Expand Down
3 changes: 2 additions & 1 deletion src/aind_behavior_services/task_logic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ def coerce_version(cls, v: str, ctx) -> str:
return coerce_schema_version(cls, v, ctx.field_name)


# This class should be inherited from but do not add extra parameters. Instead, add them to 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")
@field_validator("version", mode="before", check_fields=False)
@classmethod
def coerce_version(cls, v: str) -> str:
return coerce_schema_version(cls, v)
2 changes: 1 addition & 1 deletion src/schemas/aind_behavior_data_types.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
},
"properties": {
"aind_behavior_services_pkg_version": {
"default": "0.8.0",
"default": "0.8.1",
"pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$",
"title": "aind_behavior_services package version",
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/aind_behavior_session.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"properties": {
"aind_behavior_services_pkg_version": {
"default": "0.8.0",
"default": "0.8.1",
"pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$",
"title": "aind_behavior_services package version",
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/aind_behavior_subject_database.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"properties": {
"aind_behavior_services_pkg_version": {
"default": "0.8.0",
"default": "0.8.1",
"pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$",
"title": "aind_behavior_services package version",
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/aind_manipulator_calibration_logic.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"title": "Rng Seed"
},
"aind_behavior_services_pkg_version": {
"default": "0.8.0",
"default": "0.8.1",
"pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$",
"title": "aind_behavior_services package version",
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/aind_manipulator_calibration_rig.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@
},
"properties": {
"aind_behavior_services_pkg_version": {
"default": "0.8.0",
"default": "0.8.1",
"pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$",
"title": "aind_behavior_services package version",
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/load_cells_calibration_logic.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"title": "Rng Seed"
},
"aind_behavior_services_pkg_version": {
"default": "0.8.0",
"default": "0.8.1",
"pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$",
"title": "aind_behavior_services package version",
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/load_cells_calibration_rig.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
},
"properties": {
"aind_behavior_services_pkg_version": {
"default": "0.8.0",
"default": "0.8.1",
"pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$",
"title": "aind_behavior_services package version",
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/olfactometer_calibration_logic.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"title": "Rng Seed"
},
"aind_behavior_services_pkg_version": {
"default": "0.8.0",
"default": "0.8.1",
"pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$",
"title": "aind_behavior_services package version",
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/olfactometer_calibration_rig.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@
},
"properties": {
"aind_behavior_services_pkg_version": {
"default": "0.8.0",
"default": "0.8.1",
"pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$",
"title": "aind_behavior_services package version",
"type": "string"
Expand Down
4 changes: 2 additions & 2 deletions src/schemas/treadmill_calibration_logic.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"title": "Rng Seed"
},
"aind_behavior_services_pkg_version": {
"default": "0.8.0",
"default": "0.8.1",
"pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$",
"title": "aind_behavior_services package version",
"type": "string"
Expand Down Expand Up @@ -45,7 +45,7 @@
"$ref": "#/definitions/CalibrationParameters",
"default": {
"rng_seed": null,
"aind_behavior_services_pkg_version": "0.8.0"
"aind_behavior_services_pkg_version": "0.8.1"
},
"title": "Task parameters"
},
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/treadmill_calibration_rig.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
},
"properties": {
"aind_behavior_services_pkg_version": {
"default": "0.8.0",
"default": "0.8.1",
"pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$",
"title": "aind_behavior_services package version",
"type": "string"
Expand Down
Loading

0 comments on commit e3a6dff

Please sign in to comment.