torq and also available as torq.lab.
from torq import (
Protocol, Session, TrialResult, Stimulus, Window,
Timeline, TimelineEvent, StimulusDriver, DAQDevice, SampleRecord,
StubDriver, StubDAQ, dumps_timeline, loads_timeline, dumps_session_csv,
Sensor, Metric, LabEngine, sensor, metric,
)
Core types
| Symbol | Meaning |
|---|---|
Stimulus | Timed onset + duration (+ payload) |
Window | DAQ acquisition interval (channels, optional rate) |
Sensor / sensor(name) | Lab sensor handle (Flow): .probe() / .mark(...) + >> / @ / .to / .send |
Metric / metric(name) | Lab metric handle (same sugar as Sensor) |
LabEngine / torq.lab.engine(name) | Named DAQ/engine bind target for @ / .on |
Protocol | Builder: .stimulus / .window / .inject / .wait / .isi / .mark / .times / .extend |
Protocol.inject(values, *, at=None, window=None, advance=False) | Schedule a DAQ inject edge |
Protocol.plan() | Deterministic offline Timeline (no hardware; includes inject) |
Protocol.play() / .run(clock, arm=True) | Spork edges on the logical clock; optional arm/disarm |
Session(protocol, isi=…) | N sequential trials; optional shuffle + ISI jitter |
TrialResult / Session.as_dict() / .to_jsonable() / .to_json() | JSON-safe snapshots |
Session.to_csv(path) / dumps_session_csv(session) | Wide trial CSV |
Timeline / TimelineEvent | Sorted edges; .as_dict() / .to_json() |
dumps_timeline / loads_timeline | Stdlib JSON round-trip |
StimulusDriver / DAQDevice | Base hardware interfaces (no-op defaults) |
StubDriver / StubDAQ | Recording stubs |
SampleRecord | Closed DAQ window (samples, by_channel, in-window marks) |
window_open → stimulus_on → mark → inject → stimulus_off → window_close.
Probe / mark
Lab handle.mark(name, *, when=None, payload=None) annotates a probed sensor/metric (records on .marks). Protocol.mark remains timeline-only.
No
% for lab windows — use Window(..., rate=) or bind a clock / LabEngine.Example
from torq import Clock, Protocol, Session, Stimulus, Window, ms, second
from torq import StubDriver, StubDAQ
proto = Protocol(driver=StubDriver(), daq=StubDAQ())
proto.window(Window(channels=("ai0",), rate=1000), at=0 * second, dur=200 * ms)
proto.stimulus(Stimulus(onset=50 * ms, dur=20 * ms, payload="flash"))
proto.inject({"ao0": 1.0}, at=50 * ms)
timeline = proto.plan()
clock = Clock()
session = Session(proto, isi=100 * ms)
session.run(clock, trials=3, shuffle=True, seed=0)
csv_text = dumps_session_csv(session)
session.to_csv("trials.csv") # or a text file object