AIND Code Ocean dispatch
Launch, monitor, and capture batches of Code Ocean capsule runs
Installation
If you choose to clone the repository, you can install the package by running the following command from the root directory of the repository:
pip install .
Otherwise, you can use pip:
pip install aind-codeocean-dispatch
Usage
Running a batch of runs
run_jobs launches a batch of capsule or pipeline runs, waits for them from one polling
loop, and captures each successful run as a data asset:
from codeocean import CodeOcean
from codeocean.computation import DataAssetsRunParam, NamedRunParam, RunParams
from aind_codeocean_dispatch import Job, capture_as, job_key, raise_for_failures, run_jobs
client = CodeOcean(domain="https://codeocean.allenneuraldynamics.org", token=token)
jobs = []
for stream in streams:
params = RunParams(
capsule_id=WORKER_CAPSULE_ID,
data_assets=[DataAssetsRunParam(id=raw_asset_id, mount="raw")],
named_parameters=[NamedRunParam(param_name="stream", value=stream)],
)
jobs.append(
Job(
label=stream,
run_params=params,
capture=capture_as(f"{session}_{stream}_sorted", tags=["sorted"]),
key=job_key(params),
)
)
outcomes = run_jobs(client, jobs, launch_interval_s=1, start_retries=3, reuse=True)
raise_for_failures(outcomes)
asset_ids = {o.job.label: o.asset_id for o in outcomes}
A failed job does not raise; each Outcome carries its status, asset_id, every
computation_ids attempt, and on failure an error and a failure kind.
raise_for_failures turns failures into one DispatchFailed.
Behaviour worth knowing:
- Failed starts. Code Ocean sometimes fails to start a run (
end_status=Failed, no results). Up tostart_retriesrelaunches follow, afterstart_retry_backoff_s(60 s) doubling each time, and every pending launch waits too, since the cause is usually machine capacity. - Rate limits and errors. 429s are retried honouring
Retry-After. Other 5xx and connection errors are retried on reads only: a launch or capture POST may already have taken effect, so resending it could duplicate the computation or asset. - Pacing.
max_in_flightcaps concurrent runs andlaunch_interval_sspaces launches; both are off by default. - Reuse. A job's
keyis added to its asset as a tag. Withreuse=True, a Ready asset you created with that tag is returned instead of launching.job_keyfingerprints the launch request; passsalt=for what the request cannot show, such as the commit of an unreleased capsule (capsule_head_commit(client, capsule_id)reads it inside a run). - Acting on each job as it finishes.
on_outcome=is called with each job'sOutcomeas soon as it is reached, whatever its status, so a caller can register or report results without waiting for the whole batch. An exception it raises is logged and does not affect the other jobs. - Resuming a batch. A keyed job's computation is renamed to its label plus
key_marker(key). Withresume_owner=set to your Code Ocean user id or email, a later batch follows your computation of the same job instead of launching it again: one still running is waited on, one that succeeded but was never captured is captured, and a capture still in progress is waited on. A succeeded computation that already has a Ready capture is resumed only throughreuse. Code Ocean lists every user's computations of a capsule and has no call naming the caller, hence the argument; it needs codeocean 0.15 or later. - Cancelling a doomed batch.
cancel_on_failure=True, or a predicate on the failedOutcomesuch aslambda o: not o.transient, stops launching and stops and deletes running computations; captures already under way finish. - Capture names.
capture_asuses a fixed name.capture_named_by_data_descriptionuses the name a deriveddata_description.jsonin the results declares, and otherwise a fallback name plus the capture time.
Capturing runs from a post-run automation
A Code Ocean pipeline can name an automation capsule that runs after every run. A capsule
whose code/run is
#!/usr/bin/env bash
set -e
python -m aind_codeocean_dispatch.automation
captures each successful run as an internal data asset, named by the results'
data_description.json when it declares a derived name and otherwise after the first
input asset. It needs only CODEOCEAN_TOKEN; CAPTURE_TAGS, CAPTURE_FAILED and
CAPTURE_PERMISSIONS adjust it. It registers nothing in DocDB and writes no external
bucket, so pipelines that publish use asset-creation-capsule instead.
Contributing
Setup, checks, tests and conventions are in CONTRIBUTING.md.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for aind-codeocean-dispatch 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aind_codeocean_dispatch-0.6.0.tar.gz | 126.2 kB | Without provenance | Details for aind_codeocean_dispatch-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aind_codeocean_dispatch-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for aind_codeocean_dispatch-0.6.0-py3-none-any.whl |
Total release size: 147.7 kB
Release files / aind_codeocean_dispatch-0.6.0.tar.gz
| Download URL | aind_codeocean_dispatch-0.6.0.tar.gz |
|---|---|
| Size | 126.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
31d8859385aea35fdf4ee46864577160ab8e1a82014693cb71928df049fe4efc
|
|
BLAKE2b-256 checksum How to use checksums |
f4925b2ae90d7d946f95366a1c912a439ccfb2da2d14d5634f2ac43972e20127
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / aind_codeocean_dispatch-0.6.0-py3-none-any.whl
| Download URL | aind_codeocean_dispatch-0.6.0-py3-none-any.whl |
|---|---|
| Size | 21.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
13fa91e41a2a2d479066c8c8ada1e953ca692958874f603d713483f05a101013
|
|
BLAKE2b-256 checksum How to use checksums |
46d92f8b7017180298a517f2592fa394f692a8a19daf837b8d558456bc08a4a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for aind-codeocean-dispatch 0.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.