Authoring or changing a schema#
This is the loop you run whenever a paradigm's parameters change. The golden rule of schema-first: edit the Pydantic model, never the generated artifacts. JSON Schema and C# are always regenerated.
When#
Any time you add/remove/rename a field, add a device to a Rig, or extend the task logic — in the framework repo or an experiment repo.
Steps (in an experiment repo)#
- Edit the model. Change
src/<pkg>/rig.pyorsrc/<pkg>/task_logic.py(subclasses of the framework'sRig/Task). Reuse framework building blocks — the device+calibration library andtask.distributions. - Bump the version if the shape changed. Update the model's
versionLiteraldefault per SemVer (versioning). This is what lets contraqctor select the right data contract later. - Regenerate. Run the repo's
regenerate.py(it collects the models into aRootModeland callsconvert_pydantic_to_bonsai). This rewrites: - JSON Schema →
schema/(orsrc/DataSchemas/) - C# →
src/Extensions/<Name>.Generated.cs - Rebuild the Bonsai
Extensionsassembly somain.bonsaisees the new generated types (they are referenced viaclr-namespace:...;assembly=Extensions). Update the workflow if you added new operators. - Update the data contract in
data_contract/if new output streams appear, and itsdata_qc/suites. - Test & commit. Run the repo's tests; CI enforces that regeneration is up to date (generated files must not drift from the models).
Steps (in the framework repo itself)#
The framework's own generators live under src/_generators/ (the generate console script):
rig_harp.pyregeneratesrig/_harp_gen.pyfrom the harp-techwhoami.ymlregistry — run this when new Harp devices are published.json_schema.pywrites./schema/forSession,DataTypes,MessageProtocol,AindManipulator.
Prerequisites#
dotnet, Bonsai.Sgen (>= 0.6.0), and Harp.Toolkit must be installed (Windows). See docs/articles/requirements.rst.
Gotchas#
- Never hand-edit
*.Generated.cs— it is excluded from linting because it is machine output. - Watch the known
schema/vssrc/schemasvssrc/DataSchemas/path inconsistency in this repo's docs config when wiring generation output.
Citations#
- src/aind_behavior_services/schema/init.py
- src/_generators/ (rig_harp.py, json_schema.py)
- Aind.Behavior.Telekinesis
src/aind_behavior_telekinesis/regenerate.py