Skip to content

Commit

Permalink
add ci, opt out of multisim
Browse files Browse the repository at this point in the history
  • Loading branch information
Helveg committed Feb 13, 2024
1 parent 1e09219 commit e84565a
Show file tree
Hide file tree
Showing 18 changed files with 120 additions and 33 deletions.
34 changes: 34 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[bumpversion]
current_version = 0.0.0b0
files = bsb_arbor/__init__.py
commit = True
tag = True
parse = ^
(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
((?P<prekind>a|alpha|b|beta|d|dev|rc)
(?P<pre>\d+) # pre-release version num
)?
(\.(?P<postkind>post)(?P<post>\d+))? # post-release
serialize =
{major}.{minor}.{patch}{prekind}{pre}.{postkind}{post}
{major}.{minor}.{patch}{prekind}{pre}
{major}.{minor}.{patch}{postkind}{post}
{major}.{minor}.{patch}

[bumpversion:part:prekind]
optional_value = _
values =
_
dev
d
alpha
a
beta
b
rc

[bumpversion:part:postkind]
optional_value = _
values =
_
post
15 changes: 15 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Black

on: [push, pull_request]

jobs:
black:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
with:
options: "--check --verbose"
version: "24.1.1"
20 changes: 20 additions & 0 deletions .github/workflows/isort.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Run isort
on:
- push

jobs:
isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Install apt dependencies
# Install `libopenmpi` for mpi4py
run: |
sudo apt update
sudo apt install openmpi-bin libopenmpi-dev
# Install dependencies for proper 1st/2nd/3rd party import sorting
- run: pip install -e .[parallel]
- uses: isort/isort-action@master
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ jobs:
- name: Install dependencies & self
run: |
python -m pip install --upgrade pip
pip install -e . --no-deps
pip install -r requirements.txt --prefer-binary
pip install -e .
pip install -e .[test]
- name: Run tests & coverage
run: |
coverage run -p -m unittest
Expand Down
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.1.1
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
5 changes: 3 additions & 2 deletions bsb_arbor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"""

from bsb.simulation import SimulationBackendPlugin
from .simulation import ArborSimulation
from .adapter import ArborAdapter

from . import devices
from .adapter import ArborAdapter
from .simulation import ArborSimulation

__version__ = "0.0.0b0"
__plugin__ = SimulationBackendPlugin(Simulation=ArborSimulation, Adapter=ArborAdapter)
22 changes: 14 additions & 8 deletions bsb_arbor/adapter.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import itertools
import itertools as it
import time
import typing

from bsb.reporting import report, warn
import arbor
from bsb.exceptions import AdapterError, UnknownGIDError
from bsb.reporting import report, warn
from bsb.services import MPI
from bsb.simulation.adapter import SimulationData, SimulatorAdapter
import itertools as it
import time
import arbor

from bsb.storage import Chunk

if typing.TYPE_CHECKING:
Expand Down Expand Up @@ -79,7 +78,9 @@ def _get_ranges(self, chunks, ps, offset):
return ranges

def __iter__(self):
yield from itertools.chain.from_iterable(range(r[0], r[1]) for r in self._ranges)
yield from itertools.chain.from_iterable(
range(r[0], r[1]) for r in self._ranges
)


class GIDManager:
Expand Down Expand Up @@ -266,7 +267,12 @@ def prepare_samples(self, simulation, simdata):
for device in simulation.devices.values():
device.prepare_samples(simdata)

def run(self, simulation):
def run(self, *simulations):
if len(simulations) != 1:
raise RuntimeError(
"Can not run multiple simultaneous simulations. Composition not implemented."
)
simulation = simulations[0]
try:
simdata = self.simdata[simulation]
arbor_sim = simdata.arbor_sim
Expand All @@ -285,7 +291,7 @@ def run(self, simulation):
if simulation.profiling and arbor.config()["profiling"]:
report("printing profiler summary", level=2)
report(arbor.profiler_summary(), level=1)
return simdata.result
return [simdata.result]
finally:
del self.simdata[simulation]

Expand Down
2 changes: 1 addition & 1 deletion bsb_arbor/cell.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import abc
import typing

import arbor
from bsb import config
from bsb.config import types
from bsb.exceptions import ConfigurationError
from bsb.simulation.cell import CellModel
import arbor

from .adapter import SingleReceiverCollection

Expand Down
7 changes: 4 additions & 3 deletions bsb_arbor/connection.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import arbor
import tqdm

from bsb import config
from bsb.simulation.connection import ConnectionModel
import arbor


class Receiver:
Expand Down Expand Up @@ -63,5 +62,7 @@ def create_connections_from(self, conns_from_gid, conns, pop_pre, pop_post):

def gap_junction(self, conn):
l = arbor.cell_local_label(f"gap_{conn.to_compartment.id}")
g = arbor.cell_global_label(int(conn.from_id), f"gap_{conn.from_compartment.id}")
g = arbor.cell_global_label(
int(conn.from_id), f"gap_{conn.from_compartment.id}"
)
return arbor.gap_junction_connection(g, l, self.weight)
3 changes: 1 addition & 2 deletions bsb_arbor/device.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import abc

import arbor
from bsb import config
from bsb.config import types
from bsb.simulation.device import DeviceModel
from bsb.simulation.targetting import Targetting

import arbor


@config.dynamic(attr_name="device", auto_classmap=True, classmap_entry=None)
class ArborDevice(DeviceModel):
Expand Down
2 changes: 1 addition & 1 deletion bsb_arbor/devices/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .poisson_generator import PoissonGenerator
from .spike_recorder import SpikeRecorder
from .probe import Probe
from .spike_recorder import SpikeRecorder
3 changes: 2 additions & 1 deletion bsb_arbor/devices/poisson_generator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import arbor
from bsb import config

from ..connection import Receiver
from ..device import ArborDevice
import arbor


@config.node
Expand Down
5 changes: 3 additions & 2 deletions bsb_arbor/devices/probe.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ..device import ArborDevice
from bsb.exceptions import ConfigurationError
import arbor
from bsb.exceptions import ConfigurationError

from ..device import ArborDevice


class Probe(ArborDevice):
Expand Down
2 changes: 1 addition & 1 deletion bsb_arbor/devices/spike_recorder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import neo

from bsb import config
from bsb.services import MPI

from ..device import ArborDevice


Expand Down
1 change: 1 addition & 0 deletions bsb_arbor/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from bsb import config
from bsb.config import types
from bsb.simulation.simulation import Simulation

from .cell import ArborCell
from .connection import ArborConnection
from .device import ArborDevice
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ arbor = "bsb_arbor"
name = "bsb_arbor"

[project.optional-dependencies]
test = ["bsb-test>=0.0.0b0"]
test = ["bsb-core[parallel]", "bsb-test>=0.0.0b0", "coverage~=7.0"]
5 changes: 0 additions & 5 deletions requirements.txt

This file was deleted.

11 changes: 8 additions & 3 deletions tests/test_arbor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import unittest

from bsb.config import from_file
from bsb.core import Scaffold
from bsb.services import MPI
from bsb_test import RandomStorageFixture, get_config_path
import unittest


@unittest.skipIf(MPI.get_size() > 1, "Skipped during parallel testing.")
Expand All @@ -26,8 +27,12 @@ def test_brunel(self):
self.assertIsNotNone(sr_exc)
self.assertIsNotNone(sr_inh)

rate_ex = len(sr_exc) / simcfg.duration * 1000.0 / sr_exc.annotations["pop_size"]
rate_in = len(sr_inh) / simcfg.duration * 1000.0 / sr_inh.annotations["pop_size"]
rate_ex = (
len(sr_exc) / simcfg.duration * 1000.0 / sr_exc.annotations["pop_size"]
)
rate_in = (
len(sr_inh) / simcfg.duration * 1000.0 / sr_inh.annotations["pop_size"]
)

# These are temporary circular values, taken from the output. May be incorrect.
self.assertAlmostEqual(rate_in, 34.2, delta=1)
Expand Down

0 comments on commit e84565a

Please sign in to comment.