# API ## Using the package To use ChronoProp in your own code, install it with ```bash pip install "chronoprop @ git+https://github.com/Poirazi-Lab/chronoprop" ``` It needs Python 3.10 or newer, PyTorch, NumPy (1.x or 2.x), SciPy, h5py, scikit-learn and matplotlib, and torchvision for the image datasets. Build each network directly on the device it will run on (`device='cuda'` or `'cpu'`); moving a built network with `.to()` is not supported. `cp.jit` compiles a network with TorchScript, as the paper did. Recent PyTorch versions (such as 2.14) can no longer compile the surrogate gradient of the BPTT baseline, which every neuron model contains, and `cp.jit` then returns the networks uncompiled, which gives the same results up to rounding (see {doc}`Run locally `). We plan to port the code to `torch.compile`. A network of the paper, trained as the paper trained it (here the recurrent network of Fig. 3 at Δt = 0.1 ms, a few hours on a GPU): ```python import chronoprop as cp from chronoprop import configs train_set, val_set, test_set = cp.data.load_shd('data/SHD', dt_us=1000) # downloads SHD once cp.set_seed(1234) net, info = configs.build_fig3_network('rec', 'chronoprop', 'fine', 'cuda') net = cp.jit(net) res = cp.train.train(net, train_set, test_set, val_data=val_set, batch_size=128, epochs=400, lr=info['lr'], device='cuda', window_steps=info['window_steps'], recurrent=True) acc, epoch = cp.train.test_at_best_val(res) ``` The [tutorials](tutorials/index) build networks from their parts, and the scripts of [Run locally](run_locally.md) show every figure's training. | Module | What it holds | |---|---| | [`neurons`, `proxy`, `fi`](#neurons-proxy-and-fi-curves) | the neuron models, the ChronoProp proxy and the measured FI curves it uses | | [`networks`](#networks) | the networks of every figure, each trained by ChronoProp or by BPTT | | [`data`](#datasets) | SHD, addSHD, MNIST and Fashion-MNIST with the paper's splits | | [`train`, `configs`](#training-and-the-paper-s-settings) | the training loop, the paper's settings and a builder per figure | | [`pretrained`](#released-networks) | the trained networks of Fig. 6, Fig. 5's best SHD network among them | | [`defects`](#hardware-defects) | the simulated hardware defects of Fig. 6 | | [`cost`](#training-cost) | the time, memory and operations of a training step (Fig. 2c–f) | | [`utils`](#helpers) | seeding, TorchScript compilation, matched hidden sizes | ## Neurons, proxy and FI curves ### `neurons` ```{eval-rst} .. automodule:: chronoprop.neurons :members: LIF, AdaptiveLIF, TwoCompartmentLIF, ATanSurrogate ``` ### `proxy` ```{eval-rst} .. automodule:: chronoprop.proxy :members: SpikesToRate, SpikesToRateAdaptive, SpikesToRateDendrite ``` ### `fi` ```{eval-rst} .. automodule:: chronoprop.fi :members: ``` ## Networks ### `networks.static` ```{eval-rst} .. automodule:: chronoprop.networks.static :members: ChronoPropStatic, BPTTStatic, hidden_spike_counts ``` ### `networks.temporal` ```{eval-rst} .. automodule:: chronoprop.networks.temporal :members: ChronoPropFeedforward, ChronoPropRecurrent, BPTTFeedforward, BPTTRecurrent ``` ### `networks.adaptive` ```{eval-rst} .. automodule:: chronoprop.networks.adaptive :members: ChronoPropAdaptiveFeedforward, ChronoPropAdaptiveRecurrent, BPTTAdaptiveFeedforward, BPTTAdaptiveRecurrent ``` ### `networks.dendritic` ```{eval-rst} .. automodule:: chronoprop.networks.dendritic :members: ChronoPropDendriteFeedforward, ChronoPropDendriteRecurrent, BPTTDendriteFeedforward, BPTTDendriteRecurrent ``` ### `networks.techniques` ```{eval-rst} .. automodule:: chronoprop.networks.techniques :members: ChronoPropTechniques, BPTTTechniques ``` ## Datasets ### `data` ```{eval-rst} .. automodule:: chronoprop.data :members: SHD, PadToWindow, ChannelJitter, load_shd, paper_split, pool_channels, spikes_to_frames ``` ### `data.images` ```{eval-rst} .. automodule:: chronoprop.data.images :members: load_images, image_split ``` ### `data.addshd` ```{eval-rst} .. automodule:: chronoprop.data.addshd :members: AddSHD, load_addshd, addshd_split ``` ## Training and the paper's settings ### `train` ```{eval-rst} .. automodule:: chronoprop.train :members: train, evaluate, test_at_best_val ``` ### `configs` ```{eval-rst} .. automodule:: chronoprop.configs :members: build_fig2_network, fig2_cell, build_fig2_cost_network, build_fig3_network, fig3_cell, build_fig4_network, fig4_cell, build_fig4b_network, fig4b_cell, build_techniques_network, cosine_floor, reference ``` ## Released networks ### `pretrained` ```{eval-rst} .. automodule:: chronoprop.pretrained :members: fetch, manifest, load_network, load_checkpoint, load_state_dict ``` ## Hardware defects ### `defects` ```{eval-rst} .. automodule:: chronoprop.defects :members: Defects, MembraneNoise, WeightNoise, WeightQuantization, tau_mismatch, tau_mismatch_chip, membrane_noise_step_sigma, noise_full_scale, quantization_full_scale ``` ## Training cost ### `cost` ```{eval-rst} .. automodule:: chronoprop.cost :members: count_operations, count_dataset, totals, select, Conventions, draw_input_spikes, time_training_steps ``` ## Helpers The three helpers are also available directly as `cp.set_seed`, `cp.jit` and `cp.matched_hidden_size`. ### `utils` ```{eval-rst} .. automodule:: chronoprop.utils :members: set_seed, jit, matched_hidden_size ```