From 25811fc38948cfaffe8000ca263ae0f40865ad9e Mon Sep 17 00:00:00 2001 From: "Donal K. Fellows" Date: Mon, 7 Aug 2023 17:14:43 +0100 Subject: [PATCH] Working on untangling import order --- .../connectors/abstract_connector.py | 5 ++++- .../connectors/all_to_all_connector.py | 7 ++++--- .../connectors/array_connector.py | 6 ++++-- .../connectors/convolution_connector.py | 9 ++++++--- .../connectors/csa_connector.py | 5 ++++- ...istance_dependent_probability_connector.py | 6 ++++-- .../connectors/fixed_number_post_connector.py | 6 ++++-- .../connectors/fixed_number_pre_connector.py | 6 ++++-- .../connectors/from_list_connector.py | 11 ++++++---- .../index_based_probability_connector.py | 6 ++++-- .../connectors/kernel_connector.py | 14 +++++++------ .../connectors/multapse_connector.py | 6 ++++-- .../connectors/one_to_one_connector.py | 2 +- .../connectors/pool_dense_connector.py | 9 ++++++--- .../connectors/small_world_connector.py | 8 +++++--- .../pyNN/models/neuron/master_pop_table.py | 14 +++++++------ .../abstract_plastic_synapse_dynamics.py | 7 ++++--- .../abstract_static_synapse_dynamics.py | 7 ++++--- .../synapse_dynamics_structural_common.py | 10 +++++----- .../synapse_dynamics_structural_static.py | 7 ++++--- .../synapse_dynamics_structural_stdp.py | 8 ++++---- spynnaker/pyNN/models/recorder.py | 20 +++++++++++++------ .../pyNN/utilities/bit_field_utilities.py | 10 ++++++---- 23 files changed, 118 insertions(+), 71 deletions(-) diff --git a/spynnaker/pyNN/models/neural_projections/connectors/abstract_connector.py b/spynnaker/pyNN/models/neural_projections/connectors/abstract_connector.py index 646f09328d..0ed3ff61dd 100644 --- a/spynnaker/pyNN/models/neural_projections/connectors/abstract_connector.py +++ b/spynnaker/pyNN/models/neural_projections/connectors/abstract_connector.py @@ -254,13 +254,16 @@ def _get_n_connections_from_pre_vertex_with_delay_maximum( @abstractmethod def get_n_connections_from_pre_vertex_maximum( self, n_post_atoms: int, synapse_info: SynapseInformation, - min_delay: float, max_delay: float) -> int: + min_delay: Optional[float] = None, + max_delay: Optional[float] = None) -> int: """ Get the maximum number of connections from any neuron in the pre vertex to the neurons in the post_vertex_slice, for connections with a delay between min_delay and max_delay (inclusive) if both specified (otherwise all connections). + Not all concrete connectors support omitting the delay range. + :param delays: :type delays: ~pyNN.random.RandomDistribution or int or float or str :param int n_post_atoms: diff --git a/spynnaker/pyNN/models/neural_projections/connectors/all_to_all_connector.py b/spynnaker/pyNN/models/neural_projections/connectors/all_to_all_connector.py index 44c7a02441..622c4282f5 100644 --- a/spynnaker/pyNN/models/neural_projections/connectors/all_to_all_connector.py +++ b/spynnaker/pyNN/models/neural_projections/connectors/all_to_all_connector.py @@ -11,11 +11,11 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +from __future__ import annotations import numpy from numpy import uint32 from numpy.typing import NDArray -from typing import Sequence, Optional +from typing import Sequence, Optional, TYPE_CHECKING from spinn_utilities.overrides import overrides from pacman.model.graphs.common import Slice from spinn_front_end_common.utilities.constants import BYTES_PER_WORD @@ -24,7 +24,8 @@ AbstractGenerateConnectorOnMachine, ConnectorIDs) from .abstract_generate_connector_on_host import ( AbstractGenerateConnectorOnHost) -from spynnaker.pyNN.models.neural_projections import SynapseInformation +if TYPE_CHECKING: + from spynnaker.pyNN.models.neural_projections import SynapseInformation class AllToAllConnector(AbstractGenerateConnectorOnMachine, diff --git a/spynnaker/pyNN/models/neural_projections/connectors/array_connector.py b/spynnaker/pyNN/models/neural_projections/connectors/array_connector.py index 789b4f9b49..9e5669b805 100644 --- a/spynnaker/pyNN/models/neural_projections/connectors/array_connector.py +++ b/spynnaker/pyNN/models/neural_projections/connectors/array_connector.py @@ -12,16 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations import numpy from numpy import uint8 from numpy.typing import NDArray -from typing import Sequence, Optional +from typing import Sequence, Optional, TYPE_CHECKING from spinn_utilities.overrides import overrides from pacman.model.graphs.common import Slice from .abstract_connector import AbstractConnector from .abstract_generate_connector_on_host import ( AbstractGenerateConnectorOnHost) -from spynnaker.pyNN.models.neural_projections import SynapseInformation +if TYPE_CHECKING: + from spynnaker.pyNN.models.neural_projections import SynapseInformation class ArrayConnector(AbstractConnector, AbstractGenerateConnectorOnHost): diff --git a/spynnaker/pyNN/models/neural_projections/connectors/convolution_connector.py b/spynnaker/pyNN/models/neural_projections/connectors/convolution_connector.py index 806c70ded9..86958787e5 100644 --- a/spynnaker/pyNN/models/neural_projections/connectors/convolution_connector.py +++ b/spynnaker/pyNN/models/neural_projections/connectors/convolution_connector.py @@ -14,12 +14,14 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations from collections.abc import Sequence import numpy from numpy import floating, float64, integer, int16, uint16, uint32, bool_ from numpy.typing import NDArray from typing import ( - List, Optional, Sequence as TSequence, Tuple, Union, cast, overload) + List, Optional, Sequence as TSequence, Tuple, Union, + cast, overload, TYPE_CHECKING) from spinn_utilities.overrides import overrides from pacman.model.graphs.application import ApplicationVertex from pacman.model.graphs.machine import MachineVertex @@ -35,8 +37,9 @@ from spynnaker.pyNN.models.abstract_models import HasShapeKeyFields from spynnaker.pyNN.utilities.constants import SPIKE_PARTITION_ID from spynnaker.pyNN.data.spynnaker_data_view import SpynnakerDataView -from spynnaker.pyNN.models.neural_projections import ( - ProjectionApplicationEdge, SynapseInformation) +if TYPE_CHECKING: + from spynnaker.pyNN.models.neural_projections import ( + ProjectionApplicationEdge, SynapseInformation) #: The number of 32-bit words in the source_key_info struct SOURCE_KEY_INFO_WORDS = 7 diff --git a/spynnaker/pyNN/models/neural_projections/connectors/csa_connector.py b/spynnaker/pyNN/models/neural_projections/connectors/csa_connector.py index 7598d23cb8..9dba9c59b5 100644 --- a/spynnaker/pyNN/models/neural_projections/connectors/csa_connector.py +++ b/spynnaker/pyNN/models/neural_projections/connectors/csa_connector.py @@ -124,7 +124,10 @@ def _get_n_connections( @overrides(AbstractConnector.get_n_connections_from_pre_vertex_maximum) def get_n_connections_from_pre_vertex_maximum( self, n_post_atoms: int, synapse_info: SynapseInformation, - min_delay: float, max_delay: float) -> int: + min_delay: Optional[float] = None, + max_delay: Optional[float] = None) -> int: + if min_delay is None or max_delay is None: + raise ValueError("min_delay and max_delay must be supplied") n_connections_max = n_post_atoms return self._get_n_connections_from_pre_vertex_with_delay_maximum( synapse_info.delays, diff --git a/spynnaker/pyNN/models/neural_projections/connectors/distance_dependent_probability_connector.py b/spynnaker/pyNN/models/neural_projections/connectors/distance_dependent_probability_connector.py index 5dba15367a..40a5624be3 100644 --- a/spynnaker/pyNN/models/neural_projections/connectors/distance_dependent_probability_connector.py +++ b/spynnaker/pyNN/models/neural_projections/connectors/distance_dependent_probability_connector.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations import math import numpy from numpy import ( @@ -20,7 +21,7 @@ minimum, e, pi, floating) from numpy.typing import NDArray from pyNN.random import NumpyRNG -from typing import Optional +from typing import Optional, TYPE_CHECKING from spinn_utilities.overrides import overrides from spinn_utilities.safe_eval import SafeEval from pacman.model.graphs.common import Slice @@ -29,7 +30,8 @@ from .abstract_connector import AbstractConnector from .abstract_generate_connector_on_host import ( AbstractGenerateConnectorOnHost) -from spynnaker.pyNN.models.neural_projections import SynapseInformation +if TYPE_CHECKING: + from spynnaker.pyNN.models.neural_projections import SynapseInformation # support for arbitrary expression for the distance dependence _d_expr_context = SafeEval(math, numpy, arccos, arcsin, arctan, arctan2, ceil, diff --git a/spynnaker/pyNN/models/neural_projections/connectors/fixed_number_post_connector.py b/spynnaker/pyNN/models/neural_projections/connectors/fixed_number_post_connector.py index c898d9972c..c7a37bc09f 100644 --- a/spynnaker/pyNN/models/neural_projections/connectors/fixed_number_post_connector.py +++ b/spynnaker/pyNN/models/neural_projections/connectors/fixed_number_post_connector.py @@ -11,12 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations import math import numpy from numpy import integer, uint32 from numpy.typing import NDArray from pyNN.random import NumpyRNG -from typing import List, Optional +from typing import List, Optional, TYPE_CHECKING from spinn_utilities.overrides import overrides from pacman.model.graphs.common import Slice from spinn_front_end_common.utilities.constants import BYTES_PER_WORD @@ -27,7 +28,8 @@ from spynnaker.pyNN.exceptions import SpynnakerException from .abstract_generate_connector_on_host import ( AbstractGenerateConnectorOnHost) -from spynnaker.pyNN.models.neural_projections import SynapseInformation +if TYPE_CHECKING: + from spynnaker.pyNN.models.neural_projections import SynapseInformation N_GEN_PARAMS = 8 diff --git a/spynnaker/pyNN/models/neural_projections/connectors/fixed_number_pre_connector.py b/spynnaker/pyNN/models/neural_projections/connectors/fixed_number_pre_connector.py index d8e6e7b8c0..86062dc078 100644 --- a/spynnaker/pyNN/models/neural_projections/connectors/fixed_number_pre_connector.py +++ b/spynnaker/pyNN/models/neural_projections/connectors/fixed_number_pre_connector.py @@ -11,12 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations import math import numpy from numpy import integer, uint32 from numpy.typing import NDArray from pyNN.random import NumpyRNG -from typing import List, Optional +from typing import List, Optional, TYPE_CHECKING from spinn_utilities.overrides import overrides from pacman.model.graphs.common import Slice from spinn_front_end_common.utilities.constants import BYTES_PER_WORD @@ -27,7 +28,8 @@ from spynnaker.pyNN.exceptions import SpynnakerException from .abstract_generate_connector_on_host import ( AbstractGenerateConnectorOnHost) -from spynnaker.pyNN.models.neural_projections import SynapseInformation +if TYPE_CHECKING: + from spynnaker.pyNN.models.neural_projections import SynapseInformation class FixedNumberPreConnector(AbstractGenerateConnectorOnMachine, diff --git a/spynnaker/pyNN/models/neural_projections/connectors/from_list_connector.py b/spynnaker/pyNN/models/neural_projections/connectors/from_list_connector.py index 1c649370d9..4ee3216323 100644 --- a/spynnaker/pyNN/models/neural_projections/connectors/from_list_connector.py +++ b/spynnaker/pyNN/models/neural_projections/connectors/from_list_connector.py @@ -12,11 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations from dataclasses import dataclass import numpy from numpy import floating, integer, int64, uint32 from numpy.typing import NDArray -from typing import Dict, List, Optional, Sequence, Tuple, Union, cast +from typing import ( + Dict, List, Optional, Sequence, Tuple, Union, cast, TYPE_CHECKING) from typing_extensions import TypeGuard from spinn_utilities.overrides import overrides from pacman.model.graphs import AbstractVertex @@ -29,9 +31,10 @@ from .abstract_generate_connector_on_host import ( AbstractGenerateConnectorOnHost) from spynnaker.pyNN.utilities.constants import SPIKE_PARTITION_ID -from spynnaker.pyNN.models.neural_projections import SynapseInformation -from spynnaker.pyNN.models.neuron.synapse_dynamics import ( - AbstractSynapseDynamics) +if TYPE_CHECKING: + from spynnaker.pyNN.models.neural_projections import SynapseInformation + from spynnaker.pyNN.models.neuron.synapse_dynamics import ( + AbstractSynapseDynamics) # Indices of the source and target in the connection list array _SOURCE = 0 diff --git a/spynnaker/pyNN/models/neural_projections/connectors/index_based_probability_connector.py b/spynnaker/pyNN/models/neural_projections/connectors/index_based_probability_connector.py index 0ecf4280df..7f79c1b4d2 100644 --- a/spynnaker/pyNN/models/neural_projections/connectors/index_based_probability_connector.py +++ b/spynnaker/pyNN/models/neural_projections/connectors/index_based_probability_connector.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations import math import numpy from numpy import ( @@ -20,7 +21,7 @@ minimum, e, pi) from numpy.typing import NDArray from pyNN.random import NumpyRNG -from typing import Optional +from typing import Optional, TYPE_CHECKING from spinn_utilities.overrides import overrides from spinn_utilities.safe_eval import SafeEval from pacman.model.graphs.common import Slice @@ -28,7 +29,8 @@ from .abstract_connector import AbstractConnector from .abstract_generate_connector_on_host import ( AbstractGenerateConnectorOnHost) -from spynnaker.pyNN.models.neural_projections import SynapseInformation +if TYPE_CHECKING: + from spynnaker.pyNN.models.neural_projections import SynapseInformation # support for arbitrary expression for the indices _index_expr_context = SafeEval(math, numpy, arccos, arcsin, arctan, arctan2, diff --git a/spynnaker/pyNN/models/neural_projections/connectors/kernel_connector.py b/spynnaker/pyNN/models/neural_projections/connectors/kernel_connector.py index b2e748a879..0ca6c8a742 100644 --- a/spynnaker/pyNN/models/neural_projections/connectors/kernel_connector.py +++ b/spynnaker/pyNN/models/neural_projections/connectors/kernel_connector.py @@ -11,10 +11,11 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations import numpy from numpy import ndarray, integer, uint32, floating from numpy.typing import NDArray -from typing import Dict, List, Optional, Tuple, Union +from typing import Dict, List, Optional, Tuple, Union, TYPE_CHECKING from typing_extensions import TypeAlias from pyNN.random import RandomDistribution from pyNN.space import Space @@ -30,14 +31,15 @@ from .abstract_generate_connector_on_host import ( AbstractGenerateConnectorOnHost) from spynnaker.pyNN.utilities.constants import SPIKE_PARTITION_ID -from spynnaker.pyNN.models.neural_projections.synapse_information import ( - SynapseInformation, _Weights, _Delays) +if TYPE_CHECKING: + from spynnaker.pyNN.models.neural_projections.synapse_information import ( + SynapseInformation, _Weights, _Delays) + _TwoD: TypeAlias = Union[List[int], Tuple[int, int]] + _Kernel: TypeAlias = Union[ + float, int, List[float], NDArray[floating], RandomDistribution] HEIGHT, WIDTH = 0, 1 N_KERNEL_PARAMS = 8 -_TwoD: TypeAlias = Union[List[int], Tuple[int, int]] -_Kernel: TypeAlias = Union[ - float, int, List[float], NDArray[floating], RandomDistribution] class ConvolutionKernel(ndarray): diff --git a/spynnaker/pyNN/models/neural_projections/connectors/multapse_connector.py b/spynnaker/pyNN/models/neural_projections/connectors/multapse_connector.py index 67377307b6..8c5aa46a9a 100644 --- a/spynnaker/pyNN/models/neural_projections/connectors/multapse_connector.py +++ b/spynnaker/pyNN/models/neural_projections/connectors/multapse_connector.py @@ -12,12 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations import math from numpy import uint32, integer from numpy.typing import NDArray import numpy.random from pyNN.random import NumpyRNG -from typing import Optional, Sequence +from typing import Optional, Sequence, TYPE_CHECKING from spinn_utilities.overrides import overrides from pacman.model.graphs.common import Slice from spinn_front_end_common.utilities.constants import BYTES_PER_WORD @@ -28,7 +29,8 @@ AbstractGenerateConnectorOnMachine, ConnectorIDs) from .abstract_generate_connector_on_host import ( AbstractGenerateConnectorOnHost) -from spynnaker.pyNN.models.neural_projections import SynapseInformation +if TYPE_CHECKING: + from spynnaker.pyNN.models.neural_projections import SynapseInformation class MultapseConnector(AbstractGenerateConnectorOnMachine, diff --git a/spynnaker/pyNN/models/neural_projections/connectors/one_to_one_connector.py b/spynnaker/pyNN/models/neural_projections/connectors/one_to_one_connector.py index 69af397bca..9ef28c3c4c 100644 --- a/spynnaker/pyNN/models/neural_projections/connectors/one_to_one_connector.py +++ b/spynnaker/pyNN/models/neural_projections/connectors/one_to_one_connector.py @@ -29,8 +29,8 @@ from .abstract_generate_connector_on_host import ( AbstractGenerateConnectorOnHost) from spynnaker.pyNN.utilities.constants import SPIKE_PARTITION_ID -from spynnaker.pyNN.models.neural_projections import SynapseInformation if TYPE_CHECKING: + from spynnaker.pyNN.models.neural_projections import SynapseInformation from spynnaker.pyNN.models.populations import PopulationView _expr_context = SafeEval( diff --git a/spynnaker/pyNN/models/neural_projections/connectors/pool_dense_connector.py b/spynnaker/pyNN/models/neural_projections/connectors/pool_dense_connector.py index ee539d0fce..725c58be66 100644 --- a/spynnaker/pyNN/models/neural_projections/connectors/pool_dense_connector.py +++ b/spynnaker/pyNN/models/neural_projections/connectors/pool_dense_connector.py @@ -14,12 +14,14 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations from collections.abc import Iterable import numpy from numpy import integer, floating, float64 from numpy.typing import ArrayLike, NDArray from pyNN.random import RandomDistribution -from typing import Optional, Sequence, Tuple, Union, cast, overload +from typing import ( + Optional, Sequence, Tuple, Union, cast, overload, TYPE_CHECKING) from spinn_utilities.overrides import overrides from pacman.model.graphs.common import Slice from spinn_front_end_common.utilities.constants import ( @@ -31,8 +33,9 @@ from spinn_front_end_common.utilities.exceptions import ConfigurationException from spynnaker.pyNN.models.abstract_models import HasShapeKeyFields from spynnaker.pyNN.data.spynnaker_data_view import SpynnakerDataView -from spynnaker.pyNN.models.neural_projections import ( - ProjectionApplicationEdge, SynapseInformation) +if TYPE_CHECKING: + from spynnaker.pyNN.models.neural_projections import ( + ProjectionApplicationEdge, SynapseInformation) _DIMENSION_SIZE = (2 * BYTES_PER_WORD) + (6 * BYTES_PER_SHORT) diff --git a/spynnaker/pyNN/models/neural_projections/connectors/small_world_connector.py b/spynnaker/pyNN/models/neural_projections/connectors/small_world_connector.py index 601bd0ba77..21e8153518 100644 --- a/spynnaker/pyNN/models/neural_projections/connectors/small_world_connector.py +++ b/spynnaker/pyNN/models/neural_projections/connectors/small_world_connector.py @@ -11,18 +11,20 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations import math import numpy from numpy.typing import NDArray from pyNN.random import NumpyRNG -from typing import Optional +from typing import Optional, TYPE_CHECKING from spinn_utilities.overrides import overrides from pacman.model.graphs.common import Slice +from spinn_front_end_common.utilities.exceptions import ConfigurationException from .abstract_connector import AbstractConnector from .abstract_generate_connector_on_host import ( AbstractGenerateConnectorOnHost) -from spynnaker.pyNN.models.neural_projections import SynapseInformation -from spinn_front_end_common.utilities.exceptions import ConfigurationException +if TYPE_CHECKING: + from spynnaker.pyNN.models.neural_projections import SynapseInformation class SmallWorldConnector(AbstractConnector, AbstractGenerateConnectorOnHost): diff --git a/spynnaker/pyNN/models/neuron/master_pop_table.py b/spynnaker/pyNN/models/neuron/master_pop_table.py index bbb1d79635..4b74aae587 100644 --- a/spynnaker/pyNN/models/neuron/master_pop_table.py +++ b/spynnaker/pyNN/models/neuron/master_pop_table.py @@ -11,19 +11,25 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations import math import numpy from numpy import uint32 from numpy.typing import NDArray import ctypes -from typing import Dict, Iterable, List, Sequence, Tuple, Type, TypeVar +from typing import ( + Dict, Iterable, List, Sequence, Tuple, Type, TypeVar, TYPE_CHECKING) from pacman.model.routing_info import BaseKeyAndMask from spinn_front_end_common.utilities.constants import BYTES_PER_WORD from spynnaker.pyNN.exceptions import ( SynapseRowTooBigException, SynapticConfigurationException) from spynnaker.pyNN.utilities.constants import POP_TABLE_MAX_ROW_LENGTH from spynnaker.pyNN.utilities.bit_field_utilities import BIT_IN_A_WORD -from spynnaker.pyNN.models.projection import Projection +if TYPE_CHECKING: + from spynnaker.pyNN.models.projection import Projection + # pylint: disable=no-member, protected-access + _T = TypeVar("_T", bound=ctypes._CData) + # Scale factor for an address; allows more addresses to be represented, but # means addresses have to be aligned to these offsets @@ -58,10 +64,6 @@ def _n_bits(field) -> int: return _BITS_PER_BYTES * field.size -_T = TypeVar( - "_T", bound=ctypes._CData) # pylint: disable=no-member, protected-access - - def _make_array(ctype: Type[_T], n_items: int) -> ctypes.Array[_T]: """ Make an array of ctype items; done separately as the syntax is a diff --git a/spynnaker/pyNN/models/neuron/synapse_dynamics/abstract_plastic_synapse_dynamics.py b/spynnaker/pyNN/models/neuron/synapse_dynamics/abstract_plastic_synapse_dynamics.py index 319ee022c2..b6c2d900f2 100644 --- a/spynnaker/pyNN/models/neuron/synapse_dynamics/abstract_plastic_synapse_dynamics.py +++ b/spynnaker/pyNN/models/neuron/synapse_dynamics/abstract_plastic_synapse_dynamics.py @@ -11,14 +11,15 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +from __future__ import annotations from numpy import integer, uint32 from numpy.typing import NDArray -from typing import List, Tuple +from typing import List, Tuple, TYPE_CHECKING from spinn_utilities.abstract_base import AbstractBase, abstractmethod from pacman.model.graphs.common import Slice from .abstract_sdram_synapse_dynamics import AbstractSDRAMSynapseDynamics -from spynnaker.pyNN.models.neuron.synapse_io import ConnectionsArray +if TYPE_CHECKING: + from spynnaker.pyNN.models.neuron.synapse_io import ConnectionsArray class AbstractPlasticSynapseDynamics( diff --git a/spynnaker/pyNN/models/neuron/synapse_dynamics/abstract_static_synapse_dynamics.py b/spynnaker/pyNN/models/neuron/synapse_dynamics/abstract_static_synapse_dynamics.py index 9abe09ea47..f9b3fd4064 100644 --- a/spynnaker/pyNN/models/neuron/synapse_dynamics/abstract_static_synapse_dynamics.py +++ b/spynnaker/pyNN/models/neuron/synapse_dynamics/abstract_static_synapse_dynamics.py @@ -11,14 +11,15 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +from __future__ import annotations from numpy import integer, uint32 from numpy.typing import NDArray -from typing import List, Tuple +from typing import List, Tuple, TYPE_CHECKING from spinn_utilities.abstract_base import AbstractBase, abstractmethod from pacman.model.graphs.common import Slice from .abstract_sdram_synapse_dynamics import AbstractSDRAMSynapseDynamics -from spynnaker.pyNN.models.neuron.synapse_io import ConnectionsArray +if TYPE_CHECKING: + from spynnaker.pyNN.models.neuron.synapse_io import ConnectionsArray class AbstractStaticSynapseDynamics( diff --git a/spynnaker/pyNN/models/neuron/synapse_dynamics/synapse_dynamics_structural_common.py b/spynnaker/pyNN/models/neuron/synapse_dynamics/synapse_dynamics_structural_common.py index 9f18b312bb..a44e651bf5 100644 --- a/spynnaker/pyNN/models/neuron/synapse_dynamics/synapse_dynamics_structural_common.py +++ b/spynnaker/pyNN/models/neuron/synapse_dynamics/synapse_dynamics_structural_common.py @@ -47,11 +47,11 @@ _SubpopIndexType: TypeAlias = Dict[ Tuple[AbstractPopulationVertex, SynapseInformation, int], int] -#: :meta private: -ConnectionsInfo: TypeAlias = Dict[ - Tuple[AbstractPopulationVertex, int], - List[Tuple[ConnectionsArray, ProjectionApplicationEdge, - SynapseInformation]]] + #: :meta private: + ConnectionsInfo: TypeAlias = Dict[ + Tuple[AbstractPopulationVertex, int], + List[Tuple[ConnectionsArray, ProjectionApplicationEdge, + SynapseInformation]]] #: Default value for frequency of rewiring DEFAULT_F_REW = 10 ** 4.0 diff --git a/spynnaker/pyNN/models/neuron/synapse_dynamics/synapse_dynamics_structural_static.py b/spynnaker/pyNN/models/neuron/synapse_dynamics/synapse_dynamics_structural_static.py index 70238e5892..0e3e052790 100644 --- a/spynnaker/pyNN/models/neuron/synapse_dynamics/synapse_dynamics_structural_static.py +++ b/spynnaker/pyNN/models/neuron/synapse_dynamics/synapse_dynamics_structural_static.py @@ -25,15 +25,14 @@ from .synapse_dynamics_structural_common import ( DEFAULT_F_REW, DEFAULT_INITIAL_WEIGHT, DEFAULT_INITIAL_DELAY, DEFAULT_S_MAX, SynapseDynamicsStructuralCommon as - _Common, ConnectionsInfo) + _Common) from .abstract_static_synapse_dynamics import AbstractStaticSynapseDynamics from .synapse_dynamics_static import SynapseDynamicsStatic from .synapse_dynamics_stdp import SynapseDynamicsSTDP from .synapse_dynamics_structural_stdp import SynapseDynamicsStructuralSTDP from spynnaker.pyNN.utilities.constants import SPIKE_PARTITION_ID -from spynnaker.pyNN.models.neuron.synapse_io import ConnectionsArray +from .abstract_synapse_dynamics import AbstractSynapseDynamics if TYPE_CHECKING: - from .abstract_synapse_dynamics import AbstractSynapseDynamics from spynnaker.pyNN.models.neural_projections import ( ProjectionApplicationEdge, SynapseInformation) from spynnaker.pyNN.models.neuron.synapse_dynamics.\ @@ -48,6 +47,8 @@ from spynnaker.pyNN.models.neuron.structural_plasticity.synaptogenesis.\ elimination.abstract_elimination import ( AbstractElimination) + from spynnaker.pyNN.models.neuron.synapse_io import ConnectionsArray + from .synapse_dynamics_structural_common import ConnectionsInfo class SynapseDynamicsStructuralStatic(SynapseDynamicsStatic, _Common): diff --git a/spynnaker/pyNN/models/neuron/synapse_dynamics/synapse_dynamics_structural_stdp.py b/spynnaker/pyNN/models/neuron/synapse_dynamics/synapse_dynamics_structural_stdp.py index 2a8bec83b0..42ba65f144 100644 --- a/spynnaker/pyNN/models/neuron/synapse_dynamics/synapse_dynamics_structural_stdp.py +++ b/spynnaker/pyNN/models/neuron/synapse_dynamics/synapse_dynamics_structural_stdp.py @@ -24,11 +24,11 @@ from .synapse_dynamics_stdp import SynapseDynamicsSTDP from .synapse_dynamics_structural_common import ( DEFAULT_F_REW, DEFAULT_INITIAL_WEIGHT, DEFAULT_INITIAL_DELAY, - DEFAULT_S_MAX, SynapseDynamicsStructuralCommon, ConnectionsInfo) + DEFAULT_S_MAX, SynapseDynamicsStructuralCommon) from .synapse_dynamics_neuromodulation import SynapseDynamicsNeuromodulation from spynnaker.pyNN.utilities.constants import SPIKE_PARTITION_ID -from spynnaker.pyNN.models.neuron.synapse_io import ConnectionsArray from .abstract_synapse_dynamics import AbstractSynapseDynamics +from .abstract_plastic_synapse_dynamics import AbstractPlasticSynapseDynamics if TYPE_CHECKING: from spynnaker.pyNN.models.neuron.structural_plasticity.synaptogenesis.\ partner_selection.abstract_partner_selection import \ @@ -42,8 +42,8 @@ from spynnaker.pyNN.models.neuron.plasticity.stdp.weight_dependence.\ abstract_weight_dependence import AbstractWeightDependence from spynnaker.pyNN.models.neural_projections import SynapseInformation - from .abstract_plastic_synapse_dynamics import ( - AbstractPlasticSynapseDynamics) + from spynnaker.pyNN.models.neuron.synapse_io import ConnectionsArray + from .synapse_dynamics_structural_common import ConnectionsInfo class SynapseDynamicsStructuralSTDP( diff --git a/spynnaker/pyNN/models/recorder.py b/spynnaker/pyNN/models/recorder.py index 3c552cf0b8..37305d1057 100644 --- a/spynnaker/pyNN/models/recorder.py +++ b/spynnaker/pyNN/models/recorder.py @@ -23,11 +23,11 @@ from spinn_front_end_common.utilities.exceptions import ConfigurationException from spynnaker.pyNN.data import SpynnakerDataView from spynnaker.pyNN.utilities.neo_buffer_database import NeoBufferDatabase -from spynnaker.pyNN.models.neuron import AbstractPopulationVertex if TYPE_CHECKING: from spynnaker.pyNN.models.common.types import Names from spynnaker.pyNN.models.populations import Population from spynnaker.pyNN.models.common import PopulationApplicationVertex + from spynnaker.pyNN.models.neuron import AbstractPopulationVertex _IoDest: TypeAlias = Union[str, neo.baseio.BaseIO, None] logger = FormatAdapter(logging.getLogger(__name__)) @@ -152,6 +152,12 @@ def __turn_on_all_record( self.turn_on_record( variable, sampling_interval, to_file, indexes) + @property + def __apv(self) -> Optional[AbstractPopulationVertex]: + from spynnaker.pyNN.models.neuron import ( + AbstractPopulationVertex as APV) + return self.__vertex if isinstance(self.__vertex, APV) else None + def turn_on_record( self, variable: str, sampling_interval: Optional[int] = None, to_file: _IoDest = None, @@ -192,8 +198,9 @@ def turn_on_record( "input. You will receive current measurements instead.") # Tell the vertex to record - if isinstance(self.__vertex, AbstractPopulationVertex): - self.__vertex.set_recording(variable, sampling_interval, indexes) + apv = self.__apv + if apv is not None: + apv.set_recording(variable, sampling_interval, indexes) @property def recording_label(self) -> str: @@ -208,9 +215,10 @@ def turn_off_all_recording( :param indexes: :type indexes: list or None """ - if isinstance(self.__vertex, AbstractPopulationVertex): - for variable in self.__vertex.get_recordable_variables(): - self.__vertex.set_not_recording(variable, indexes) + apv = self.__apv + if apv is not None: + for variable in apv.get_recordable_variables(): + apv.set_not_recording(variable, indexes) def extract_neo_block( self, variables: Names, view_indexes: Optional[Sequence[int]], diff --git a/spynnaker/pyNN/utilities/bit_field_utilities.py b/spynnaker/pyNN/utilities/bit_field_utilities.py index b64ebd8990..f08ccfe5b6 100644 --- a/spynnaker/pyNN/utilities/bit_field_utilities.py +++ b/spynnaker/pyNN/utilities/bit_field_utilities.py @@ -11,18 +11,20 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +from __future__ import annotations import math import numpy from numpy import uint32 from numpy.typing import NDArray -from typing import Iterable, Optional +from typing import Iterable, Optional, TYPE_CHECKING from spinn_front_end_common.interface.ds import DataSpecificationBase from spinn_front_end_common.utilities.constants import BYTES_PER_WORD from spynnaker.pyNN.utilities.constants import SPIKE_PARTITION_ID from spynnaker.pyNN.data import SpynnakerDataView -from spynnaker.pyNN.models.projection import Projection -from spynnaker.pyNN.models.neural_projections import ProjectionApplicationEdge +if TYPE_CHECKING: + from spynnaker.pyNN.models.projection import Projection + from spynnaker.pyNN.models.neural_projections import ( + ProjectionApplicationEdge) #: number of elements # key, n atoms, atoms_per_core, pointer to bitfield