Skip to content

Commit

Permalink
Merge pull request #140 from AllenNeuralDynamics/release-0.9
Browse files Browse the repository at this point in the history
Release v0.9
  • Loading branch information
bruno-f-cruz authored Jan 10, 2025
2 parents d7c30cb + 5ae7fb3 commit e133ecb
Show file tree
Hide file tree
Showing 86 changed files with 763 additions and 13,153 deletions.
110 changes: 13 additions & 97 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: CI
name: ci/cd

on:
workflow_dispatch:
pull_request:
branches:
- main
Expand All @@ -9,100 +10,15 @@ on:
- main

jobs:
linters:
runs-on: windows-latest
name: Lint ${{ matrix.python-version }}
strategy:
fail-fast: false
matrix:
python-version: ['3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v4

- uses: astral-sh/setup-uv@v3
with:
enable-cache: true

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
- name: Install dependencies
run: uv sync --extra dev
- name: Run ruff format
run: uv run ruff format . --config .\pyproject.toml
- name: Run ruff check
run: uv run ruff check . --config .\pyproject.toml
- name: Run codespell
run : uv run codespell .

setup-bonsai:
runs-on: windows-latest
name: Setup Bonsai
steps:
- uses: actions/checkout@v4

- name: Setup .NET Core SDK
uses: actions/[email protected]
with:
dotnet-version: 8.x

- name: Restore dotnet tools
run: dotnet tool restore

- name: Setup Bonsai
working-directory: bonsai
run: .\Setup.ps1

- name: Upload Bonsai Files
uses: actions/upload-artifact@v3
with:
name: bonsai-environment
path: bonsai


tests:
runs-on: windows-latest
name: Testing ${{ matrix.python-version }}
needs: setup-bonsai
strategy:
fail-fast: false
matrix:
python-version: ['3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v4

- name: Setup .NET Core SDK
uses: actions/[email protected]
with:
dotnet-version: 8.x

- name: Restore dotnet tools
run: dotnet tool restore

- name: Download Bonsai artifact
uses: actions/download-artifact@v3
with:
name: bonsai-environment
path: bonsai-environment

- name: Remove and Move Bonsai Files
run: |
Remove-Item -Recurse -Force bonsai\*
move bonsai-environment\* bonsai
- uses: astral-sh/setup-uv@v3
with:
enable-cache: true

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install dependencies
run: uv sync --extra dev
- name: Run tests
run: uv run -m unittest
- name: Regenerate schemas
run: uv run regenerate
- name: Check for uncommitted changes
run: |
git config --global core.safecrlf false
git diff --exit-code || (echo "Untracked changes found" && exit 1)
python-linting:
uses: AllenNeuralDynamics/Aind.Behavior.GitHubActions/.github/workflows/python-linting.yml@main
with:
runs-on: ubuntu-latest

aind-behavior-framework-testing:
uses: AllenNeuralDynamics/Aind.Behavior.GitHubActions/.github/workflows/test-aind-behavior-framework.yml@main
with:
python-version-path: .python-version
run-coverage: false
run-schema: true
65 changes: 4 additions & 61 deletions .github/workflows/tag_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,7 @@ on:
workflow_dispatch: {}

jobs:
tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Pull latest changes
run: git pull origin ${{ env.DEFAULT_BRANCH }}
- uses: astral-sh/setup-uv@v3
with:
enable-cache: true
- name: Set up Python
run: uv python install

- name: Extract version from __init__.py and package name from pyproject.toml
id: get_version_and_name
run: |
package_name=$(uv run python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['name'])")
package_name=${package_name//-/_}
version=$(uv run python -c "import re;
with open(f'./src/${package_name}/__init__.py', 'r') as f:
content = f.read();
match = re.search(r'__version__\s*=\s*[\'\"]([^\'\"]+)[\'\"]', content);
print(match.group(1)) if match else exit(1)")
echo "PACKAGE_NAME=$package_name" >> $GITHUB_ENV
echo "PACKAGE_VERSION=$version" >> $GITHUB_ENV
shell: bash

- name: Create Git tag
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git tag -a v${{ env.PACKAGE_VERSION }} -m "v${{ env.PACKAGE_VERSION }}"
git push origin v${{ env.PACKAGE_VERSION }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.SERVICE_TOKEN }}
tag_name: v${{ env.PACKAGE_VERSION }}
name: Release v${{ env.PACKAGE_VERSION }}
generate_release_notes: true

publish:
needs: tag
if: ${{ always() && contains(join(needs.*.result, ','), 'success') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Pull latest changes
run: git pull origin ${{ env.DEFAULT_BRANCH }}
- uses: astral-sh/setup-uv@v3
with:
enable-cache: true

- name: Set up Python
run: uv python install

- name: Build
run: uv build

- name: Publish
run: uv publish --token ${{ secrets.AIND_PYPI_TOKEN }}
tag-and-publish:
uses : AllenNeuralDynamics/Aind.Behavior.GitHubActions/.github/workflows/python-package-tag-and-publish.yml@main
with:
publish: true
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Bonsai.exe.WebView2
*.exe.settings
*.bonsai.layout
local
.venv
*.snl

# Byte-compiled / optimized / DLL files
Expand Down Expand Up @@ -82,3 +81,6 @@ ipython_config.py
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# venv
.venv
File renamed without changes.
8 changes: 0 additions & 8 deletions docs/api.base.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
base
-------------

.. toctree::
:maxdepth: 2

api.base/session
api.base/rig
api.base/task_logic


.. automodule:: aind_behavior_services.base
:members:
:undoc-members:
Expand Down
7 changes: 0 additions & 7 deletions docs/api.base/rig.rst

This file was deleted.

10 changes: 0 additions & 10 deletions docs/api.base/session.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/api.base/task_logic.rst

This file was deleted.

69 changes: 3 additions & 66 deletions docs/api.calibration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,11 @@ calibration
Calibration Module
####################

The calibration module of this library is used to generate the metadata necessary configure and run calibration workflows for different assets/devices.
The calibration module of this library keep a collection of models used to keep track of calibration metadata.

The metadata follows the general logic of the library by implementing the three core classes:
- :py:class:`~aind_behavior_services.session.AindBehaviorSessionModel`
- :py:class:`~aind_behavior_services.rig.AindBehaviorRigModel`
- :py:class:`~aind_behavior_services.task_logic.AindBehaviorTaskLogicModel`

A fourth class :py:class:`~aind_behavior_services.calibration.Calibration`,
specific to the Calibration module, is also implemented to keep track of the calibration metrics.
Every submodule has a single :py:class:`~aind_behavior_services.calibration.Calibration` class that is used to store the calibration metadata.
This class was written to be aligned to the Calibration class in `aind-data-schemas
<https://github.com/AllenNeuralDynamics/aind-data-schema/blob/2fd0e403bf46f0f1a47e5922c4228517e68376a3/src/aind_data_schema/components/devices.py#L274>`_.
An application example will be provided below.

While we use the base :py:class:`~aind_behavior_services.session.AindBehaviorSessionModel` class to keep track of the session metadata,
both :py:class:`~aind_behavior_services.rig.AindBehaviorRigModel` and :py:class:`~aind_behavior_services.task_logic.AindBehaviorTaskLogicModel` are
expected to be sub-classed to specify the necessary dependencies of the calibration workflow.
<https://github.com/AllenNeuralDynamics/aind-data-schema/blob/2fd0e403bf46f0f1a47e5922c4228517e68376a3/src/aind_data_schema/components/devices.py#L274>`_ as to provide an easy way to map calibration data.

Sub-classing :py:class:`~aind_behavior_services.calibration.Calibration`
##########################################################################
Expand Down Expand Up @@ -59,58 +48,6 @@ An example of a sub-class of `Calibration` is provided below:
input: DeviceCalibrationInput = Field(..., title="Input of the calibration")
output: DeviceCalibrationOutput = Field(..., title="Output of the calibration")
Sub-classing :py:class:`~aind_behavior_services.rig.AindBehaviorRigModel`
##########################################################################

We adopt the following pattern to sub-class the :py:class:`~aind_behavior_services.rig.AindBehaviorRigModel` class:

.. code-block:: python
from aind_behavior_services.rig import AindBehaviorRigModel, Device
RIG_VERSION = "1.0.0" # Use SemVer
class FooDevice(Device):
calibration: DeviceCalibration = Field(..., title="Calibration of the device foo")
class CalibrationRig(AindBehaviorRigModel):
version: Literal[RIG_VERSION] = RIG_VERSION
device_foo: FooDevice = Field(..., title="Device Foo")
device_bar: Device = Field(..., title="Device Bar")
For an example see :py:class:`aind_behavior_services.calibration.olfactometer.CalibrationRig`.



Sub-classing :py:class:`~aind_behavior_services.task_logic.AindBehaviorTaskLogicModel`
########################################################################################

The same way a :py:class:`~aind_behavior_services.task_logic.AindBehaviorTaskLogicModel` is used to define
the settings to run a behavior task, it is also used to define the settings to run a calibration workflow.
It will thus follow an identical sub-classing pattern:


.. code-block:: python
from aind_behavior_services.task_logic import AindBehaviorTaskLogicModel, TaskParameters
TASK_LOGIC_VERSION = "0.1.0"
class CalibrationParameters(TaskParameters):
n_iterations: int = Field(default=10, description="Number of iterations to run the calibration")
channels_to_calibrate: List[Literal[1,2,3]] = Field(default=[1], description="List of channels to calibrate")
class CalibrationLogic(AindBehaviorTaskLogicModel):
name: Literal["CalibrationLogic"] = "CalibrationLogic
version: Literal[TASK_LOGIC_VERSION] = TASK_LOGIC_VERSION
task_parameters: CalibrationParameters = Field(default=CalibrationParameters(), title="Task parameters", validate_default=True)
For an example see :py:class:`aind_behavior_services.calibration.olfactometer.CalibrationLogic`.


.. toctree::
:maxdepth: 4
Expand Down
2 changes: 1 addition & 1 deletion docs/api.calibration/water_valve.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Example
########

.. literalinclude:: ../../examples/water_valve.py
:language: python
:language: python
7 changes: 7 additions & 0 deletions docs/api.rig.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rig
-------------------------

.. automodule:: aind_behavior_services.rig
:members:
:undoc-members:
:show-inheritance:
5 changes: 4 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ API
:maxdepth: 2

api.base
api.calibration
api.rig
api.task_logic
api.session
api.data_types
api.calibration
api.utils
10 changes: 10 additions & 0 deletions docs/api.session.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
session
--------------------------

.. image:: _static/AindBehaviorSessionModel.svg
:target: _static/AindBehaviorSessionModel.svg

.. automodule:: aind_behavior_services.session
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/api.task_logic.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
task_logic
--------------------------------

.. automodule:: aind_behavior_services.task_logic
:members:
:undoc-members:
:show-inheritance:
Loading

0 comments on commit e133ecb

Please sign in to comment.