-
Notifications
You must be signed in to change notification settings - Fork 1
fix: Let writing data to file at flush #213
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
Open
filimarc
wants to merge
5
commits into
main
Choose a base branch
from
fix/checkpoint_flush
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
129cba2
fix: make flush method to save in file
afc9711
Merge branch 'main' into fix/checkpoint_flush
filimarc 98f2e06
fix: filename options and sim tests
filimarc 3ae4746
fix: backward compatibility
filimarc 92d2334
Merge branch 'main' into fix/checkpoint_flush
filimarc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,22 +9,37 @@ | |
|
|
||
|
|
||
| class SimulationResult: | ||
| def __init__(self, simulation): | ||
| from neo import Block | ||
| def __init__(self, simulation, filename=None): | ||
| from neo import Block, io | ||
|
|
||
| tree = simulation.__tree__() | ||
| with contextlib.suppress(KeyError): | ||
| del tree["post_prepare"] | ||
| self.block = Block(name=simulation.name, config=tree) | ||
| if filename: | ||
| self.filename = filename | ||
| self.name = simulation.name | ||
| io = io.NixIO(filename, mode="rw") | ||
| io.write(Block(name=self.name, nix_name=self.name, config=tree)) | ||
| for i, nixblock in enumerate(io.nix_file.blocks): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. something seems off here, only 1 block id is ever stored, so it seems like everything will write to the first block? each simulation should write to their own block inside the same file |
||
| if self.name == nixblock.name: | ||
| self.block_id = i | ||
| io.close() | ||
| else: | ||
| self.block = Block( | ||
| name=simulation.name, nix_name=simulation.name, config=tree | ||
| ) | ||
|
|
||
| self.recorders = [] | ||
|
|
||
| @property | ||
| def spiketrains(self): | ||
| return self.block.segments[0].spiketrains | ||
| def analogsignals(self): | ||
| if hasattr(self, "block"): | ||
| return self.block.segments[0].analogsignals | ||
|
|
||
| @property | ||
| def analogsignals(self): | ||
| return self.block.segments[0].analogsignals | ||
| def spiketrains(self): | ||
| if hasattr(self, "block"): | ||
| return self.block.segments[0].spiketrains | ||
|
|
||
| def add(self, recorder): | ||
| self.recorders.append(recorder) | ||
|
|
@@ -36,21 +51,28 @@ def create_recorder(self, flush: typing.Callable[["neo.core.Segment"], None]): | |
| return recorder | ||
|
|
||
| def flush(self): | ||
| from neo import Segment | ||
| from neo import Segment, io | ||
|
|
||
| segment = Segment() | ||
| self.block.segments.append(segment) | ||
| for recorder in self.recorders: | ||
| try: | ||
| recorder.flush(segment) | ||
| except Exception: | ||
| traceback.print_exc() | ||
| warn("Recorder errored out!") | ||
| if hasattr(self, "filename"): | ||
| io = io.NixIO(self.filename, mode="rw") | ||
| block = io.nix_file.blocks[self.block_id] | ||
| io._write_segment(segment, block) | ||
| io.close() | ||
| else: | ||
| self.block.segments.append(segment) | ||
|
|
||
| def write(self, filename, mode): | ||
| from neo import io | ||
|
|
||
| io.NixIO(filename, mode=mode).write(self.block) | ||
| if hasattr(self, "block"): | ||
| io.NixIO(filename, mode=mode).write(self.block) | ||
|
|
||
|
|
||
| class SimulationRecorder: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.