Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset cache #1512

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions spynnaker/pyNN/models/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def csv_neo_block(

wrote_metadata = False
for segment in range(SpynnakerDataView.get_reset_number()):
with NeoBufferDatabase.segement_db(segment) as db:
with NeoBufferDatabase.reset_db(segment) as db:
if not wrote_metadata:
wrote_metadata = db.csv_block_metadata(
csv_file, pop_label, annotations)
Expand Down Expand Up @@ -335,7 +335,7 @@ def __append_previous_segment(
~spinn_front_end_common.utilities.exceptions.ConfigurationException:
If the recording not setup correctly
"""
with NeoBufferDatabase.segement_db(
with NeoBufferDatabase.reset_db(
segment_number, read_only=not clear) as db:
if block is None:
block = db.get_empty_block(
Expand Down
19 changes: 9 additions & 10 deletions spynnaker/pyNN/utilities/neo_buffer_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import re
import struct
from typing import (
Any, Collection, Dict, Iterable, List, Optional, Sequence, Tuple, Union,
TYPE_CHECKING)
Any, Collection, Dict, Iterable, List, Optional, Sequence, Set, Tuple,
TYPE_CHECKING, Union)

import numpy
from numpy import floating, integer, uint8, uint32
Expand Down Expand Up @@ -66,7 +66,7 @@

logger = FormatAdapter(logging.getLogger(__name__))

segment_cache: Dict[int, str] = {}
seen_files: Set[str] = set()


class NeoBufferDatabase(BufferDatabase, NeoCsv):
Expand Down Expand Up @@ -118,22 +118,21 @@ def __init__(self, database_file: Optional[str] = None,

super().__init__(database_file, read_only=read_only)

segment = SpynnakerDataView.get_reset_number()
if (segment not in segment_cache or
segment_cache[segment] != database_file):
if database_file not in seen_files:
# The file may exist if opened by another class but will need DDL
seen_files.add(database_file)
with open(self.__NEO_DDL_FILE, encoding="utf-8") as f:
sql = f.read()
# pylint: disable=no-member
self._SQLiteDB__db.executescript(sql) # type: ignore[attr-defined]
segment_cache[segment] = database_file

@classmethod
def segement_db(cls, segment_number: int,
read_only: Optional[bool] = None) -> NeoBufferDatabase:
def reset_db(cls, reset_number: int,
read_only: Optional[bool] = None) -> NeoBufferDatabase:
"""
Retrieves a NeoBufferDatabase for this segment.
"""
database_file = segment_cache[segment_number]
database_file = cls.reset_file(reset_number)
return NeoBufferDatabase(database_file, read_only)

def write_segment_metadata(self) -> None:
Expand Down
Loading