Metadata-Version: 2.4
Name: rodent-sdk
Version: 0.4.2
Summary: Run Virtual Rodent Behaviour Environment experiments from Python, headlessly.
Author: Huzaifa Majeed, Ahmed Majeed, Muhammed Abed, Zidan Fajandar
License-Expression: Apache-2.0
Project-URL: Documentation, https://virtual-rodent-docs.pages.dev/docs/API/python-sdk
Project-URL: User guide, https://virtual-rodent-docs.pages.dev/docs/User%20Guide/python-and-colab
Project-URL: Simulation packs, https://github.com/HuzaifaMajeed/rodent-sdk-releases
Keywords: neuroscience,behaviour,rodent,simulation,godot
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Provides-Extra: analysis
Requires-Dist: pandas; extra == "analysis"
Requires-Dist: matplotlib; extra == "analysis"
Provides-Extra: train
Requires-Dist: gymnasium>=1.0; extra == "train"
Requires-Dist: numpy; extra == "train"
Requires-Dist: pandas; extra == "train"
Requires-Dist: matplotlib; extra == "train"
Dynamic: license-file

# rodent-sdk

Run Virtual Rodent Behaviour Environment experiments from Python, with no graphics.

```bash
pip install rodent-sdk
```

On first use the SDK downloads the official Godot build and the simulation pack for this
version, checks the pack's SHA-256 fingerprint, and caches both. The same experiment and
seed always produce the same run on any machine.

The rat is moved by a simple statistical placeholder model. Its behaviour is not a
validated biological result.

- Documentation: https://virtual-rodent-docs.pages.dev/docs/API/python-sdk
- Step-by-step guide for Google Colab: https://virtual-rodent-docs.pages.dev/docs/User%20Guide/python-and-colab

```python
import rodent_sdk as rodent

exp = rodent.experiment("complex_habitat", seed=42)
exp.doors["bridge_entry_gate"].open = False
exp.treatment.condition = "placebo"
run = exp.run(steps=5000, changes={2500: {"doors": {"bridge_entry_gate": True}}})

run.summary()        # time, entries and first entry per region, plus distance
run.to_dataframe()   # one row per step
run.plot()           # trajectory with walls and doors
run.save_csv("run.csv")
```

## Working with the website

Running experiments needs no account. Saving them to the RODENT website, and opening
your team's projects, needs a RODENT website account; a project lead then adds you to
their projects.

```python
import rodent_sdk as rodent

client = rodent.login()   # in Colab, reads RODENT_EMAIL and RODENT_PASSWORD from Secrets
print(client.email)       # confirm which account will own any new project
project = client.project("Anxiety study")          # or client.create_project(...)
exp = project.experiment("Baseline")               # or project.create_experiment(...)

exp.doors["bridge_entry_gate"].open = False
exp.save()                                          # checked against your role's modules

run = exp.run(steps=5000)
run.save()                                          # appears under Review on the website
```

If that website account has two-factor authentication enabled, `rodent.login()` asks
for the current six-digit authenticator code. Do not save this changing code in a
shared notebook. You can also pass it once as `rodent.login(totp_code="123456")`.

- Only the lead of that project can add experiments from a template. Everyone else
  copies one with `exp.save_as_new("name")`, within their modules.
- Published versions are frozen: continue from them with `save_as_new`.
- If someone else saved the experiment after you loaded it, `save()` refuses instead of
  overwriting their work. Load it again and reapply your changes.
- A run made with unsaved edits cannot be saved to Review, because the website replays it
  on the saved arena.

All errors are subclasses of `rodent.RodentError`, with a message that says what to do next.

## Training your own model

Your own model can control the rat and learn in the simulation. The environment uses
the Gymnasium format, so PyTorch training loops work unchanged.

```bash
pip install "rodent-sdk[train]"
```

```python
exp = rodent.experiment("light_dark_box", seed=1)
env = exp.training_env(max_steps=150, reward=lambda step: float(step.region == "dark_room"),
                       actions="discrete", log="training-log")
obs, info = env.reset()
obs, reward, terminated, truncated, info = env.step(1)   # forward

env.log.plot()                     # learning curves
episode = env.log.episode(522)     # any episode, rebuilt exactly
episode.plot(steps=(400, 600))
run = exp.run(steps=5000, model=my_policy)              # the trained rat in a normal run
project.save_model("Dark seeker", network, training=env.log)   # share it with your project
```

## Licence

Apache License 2.0. See `LICENSE` and `NOTICE`.
