Skip to content

Commit

Permalink
Update dependencies #minor (#112)
Browse files Browse the repository at this point in the history
* use bluepysnap<3.0.0

* add python_requires='>=3.8'

* Use pydantic >= 2.5

* update sonata-network with snapV2

* use bluepysnap>=2.0.0 due to breaking changes
  • Loading branch information
anilbey authored Nov 30, 2023
1 parent 25187af commit 8bc636f
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 69 deletions.
3 changes: 1 addition & 2 deletions bluecellulab/circuit/circuit_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from bluepysnap.exceptions import BluepySnapError
from bluepysnap import Circuit as SnapCircuit
import pandas as pd
from pydantic import Extra
from pydantic.dataclasses import dataclass

from bluecellulab import circuit, neuron
Expand All @@ -54,7 +53,7 @@
logger = logging.getLogger(__name__)


@dataclass(config=dict(extra=Extra.forbid))
@dataclass(config=dict(extra="forbid"))
class EmodelProperties:
threshold_current: float
holding_current: float
Expand Down
16 changes: 8 additions & 8 deletions bluecellulab/circuit/config/sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
"""Classes to represent config sections."""

from __future__ import annotations
from typing import Optional
from typing import Literal, Optional

from pydantic import Extra, Field, validator
from pydantic.typing import Literal
from pydantic import field_validator, Field
from pydantic.dataclasses import dataclass

from libsonata._libsonata import Conditions as LibSonataConditions
Expand All @@ -34,22 +33,22 @@ def string_to_bool(value: str) -> bool:
raise ValueError(f"Invalid boolean value {value}")


@dataclass(frozen=True, config=dict(extra=Extra.forbid))
@dataclass(frozen=True, config=dict(extra="forbid"))
class ConditionEntry:
"""For mechanism specific conditions."""
minis_single_vesicle: Optional[int] = Field(None, ge=0, le=1)
init_depleted: Optional[int] = Field(None, ge=0, le=1)


@dataclass(frozen=True, config=dict(extra=Extra.forbid))
@dataclass(frozen=True, config=dict(extra="forbid"))
class MechanismConditions:
"""For mechanism specific conditions."""
ampanmda: Optional[ConditionEntry] = None
gabaab: Optional[ConditionEntry] = None
glusynapse: Optional[ConditionEntry] = None


@dataclass(frozen=True, config=dict(extra=Extra.forbid))
@dataclass(frozen=True, config=dict(extra="forbid"))
class Conditions:
mech_conditions: Optional[MechanismConditions] = None
celsius: Optional[float] = None
Expand Down Expand Up @@ -125,7 +124,7 @@ def init_empty(cls) -> Conditions:
)


@dataclass(frozen=True, config=dict(extra=Extra.forbid))
@dataclass(frozen=True, config=dict(extra="forbid"))
class ConnectionOverrides:
source: str
target: str
Expand All @@ -135,7 +134,8 @@ class ConnectionOverrides:
synapse_configure: Optional[str] = None
mod_override: Optional[Literal["GluSynapse"]] = None

@validator("mod_override")
@field_validator("mod_override")
@classmethod
def validate_mod_override(cls, value):
"""Make sure the mod file to override is present."""
if isinstance(value, str) and not hasattr(bluecellulab.neuron.h, value):
Expand Down
40 changes: 22 additions & 18 deletions bluecellulab/stimuli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from typing import Optional
import warnings

from pydantic import Extra, NonNegativeFloat, PositiveFloat, validator
from pydantic import field_validator, NonNegativeFloat, PositiveFloat
from pydantic.dataclasses import dataclass


Expand Down Expand Up @@ -92,7 +92,7 @@ def from_sonata(cls, pattern: str) -> Pattern:
raise ValueError(f"Unknown pattern {pattern}")


@dataclass(frozen=True, config=dict(extra=Extra.forbid))
@dataclass(frozen=True, config=dict(extra="forbid"))
class Stimulus:
target: str
delay: NonNegativeFloat
Expand Down Expand Up @@ -301,42 +301,43 @@ def from_sonata(cls, stimulus_entry: dict) -> Optional[Stimulus]:
raise ValueError(f"Unknown pattern {pattern}")


@dataclass(frozen=True, config=dict(extra=Extra.forbid))
@dataclass(frozen=True, config=dict(extra="forbid"))
class Noise(Stimulus):
mean_percent: float
variance: float


@dataclass(frozen=True, config=dict(extra=Extra.forbid))
@dataclass(frozen=True, config=dict(extra="forbid"))
class Hyperpolarizing(Stimulus):
...


@dataclass(frozen=True, config=dict(extra=Extra.forbid))
@dataclass(frozen=True, config=dict(extra="forbid"))
class Pulse(Stimulus):
amp_start: float
width: float
frequency: float


@dataclass(frozen=True, config=dict(extra=Extra.forbid))
@dataclass(frozen=True, config=dict(extra="forbid"))
class RelativeLinear(Stimulus):
percent_start: float


@dataclass(frozen=True, config=dict(extra=Extra.forbid))
@dataclass(frozen=True, config=dict(extra="forbid"))
class SynapseReplay(Stimulus):
spike_file: str
source: str

@validator("spike_file")
@field_validator("spike_file")
@classmethod
def spike_file_exists(cls, v):
if not Path(v).exists():
raise ValueError(f"spike_file {v} does not exist")
return v


@dataclass(frozen=True, config=dict(extra=Extra.forbid))
@dataclass(frozen=True, config=dict(extra="forbid"))
class ShotNoise(Stimulus):
rise_time: float
decay_time: float
Expand All @@ -348,14 +349,15 @@ class ShotNoise(Stimulus):
mode: ClampMode = ClampMode.CURRENT
reversal: float = 0.0

@validator("decay_time")
@field_validator("decay_time")
@classmethod
def decay_time_gt_rise_time(cls, v, values):
if v <= values["rise_time"]:
if v <= values.data["rise_time"]:
raise ValueError("decay_time must be greater than rise_time")
return v


@dataclass(frozen=True, config=dict(extra=Extra.forbid))
@dataclass(frozen=True, config=dict(extra="forbid"))
class RelativeShotNoise(Stimulus):
rise_time: float
decay_time: float
Expand All @@ -367,14 +369,15 @@ class RelativeShotNoise(Stimulus):
mode: ClampMode = ClampMode.CURRENT
reversal: float = 0.0

@validator("decay_time")
@field_validator("decay_time")
@classmethod
def decay_time_gt_rise_time(cls, v, values):
if v <= values["rise_time"]:
if v <= values.data["rise_time"]:
raise ValueError("decay_time must be greater than rise_time")
return v


@dataclass(frozen=True, config=dict(extra=Extra.forbid))
@dataclass(frozen=True, config=dict(extra="forbid"))
class OrnsteinUhlenbeck(Stimulus):
tau: float
sigma: PositiveFloat
Expand All @@ -384,17 +387,18 @@ class OrnsteinUhlenbeck(Stimulus):
mode: ClampMode = ClampMode.CURRENT
reversal: float = 0.0

@validator("mean")
@field_validator("mean")
@classmethod
def mean_in_range(cls, v, values):
if v < 0 and abs(v) > 2 * values["sigma"]:
if v < 0 and abs(v) > 2 * values.data["sigma"]:
warnings.warn(
"mean is outside of range [0, 2*sigma],",
" ornstein uhlenbeck signal is mostly zero.",
)
return v


@dataclass(frozen=True, config=dict(extra=Extra.forbid))
@dataclass(frozen=True, config=dict(extra="forbid"))
class RelativeOrnsteinUhlenbeck(Stimulus):
tau: float
mean_percent: float
Expand Down
Loading

0 comments on commit 8bc636f

Please sign in to comment.