Skip to content

Commit

Permalink
Working on untangling import order
Browse files Browse the repository at this point in the history
  • Loading branch information
dkfellows committed Aug 7, 2023
1 parent 2ae3099 commit 25811fc
Show file tree
Hide file tree
Showing 23 changed files with 118 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -20,15 +21,16 @@
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
from spynnaker.pyNN.utilities import utility_calls
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 8 additions & 6 deletions spynnaker/pyNN/models/neuron/master_pop_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 25811fc

Please sign in to comment.