Skip to content

Commit

Permalink
Write placeholder data storage
Browse files Browse the repository at this point in the history
Write executable example
  • Loading branch information
KonstiNik committed May 14, 2024
1 parent 5545551 commit f511d9d
Show file tree
Hide file tree
Showing 6 changed files with 484 additions and 139 deletions.
64 changes: 62 additions & 2 deletions CI/unit_tests/recorders/test_base_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
-------
"""

import os

import numpy as np
from numpy.testing import assert_array_equal

from papyrus.measurements.base_measurement import BaseMeasurement
from papyrus.recorders.base_recorder import BaseRecorder
from papyrus.measurements import BaseMeasurement
from papyrus.recorders import BaseRecorder


class DummyMeasurement1(BaseMeasurement):
Expand Down Expand Up @@ -145,3 +147,61 @@ def test_measure(self):
recorder._results["dummy_1"], 1 * np.ones(shape=(2, 3, 10, 5))
)
assert_array_equal(recorder._results["dummy_2"], 10 * np.ones(shape=(2, 3, 10)))

def test_write_read(self):
"""
Test the write and read methods of the BaseRecorder class.
"""
# Create a temporary directory
os.makedirs("temp/", exist_ok=True)
name = "test"
storage_path = "temp/"
recorder = BaseRecorder(
name, storage_path, [self.measurement_1, self.measurement_2], 10
)

# Test writing and reading
recorder._measure(**self.neural_state)
recorder._write(recorder._results)
data = recorder.load()

assert set(data.keys()) == {"dummy_1", "dummy_2"}
assert_array_equal(data["dummy_1"], np.ones(shape=(1, 3, 10, 5)))
assert_array_equal(data["dummy_2"], 10 * np.ones(shape=(1, 3, 10)))

# Delete temporary directory
os.system("rm -r temp/")

def test_store(self):
"""
Test the store method of the BaseRecorder class.
"""
# Create a temporary directory
os.makedirs("temp/", exist_ok=True)
name = "test"
storage_path = "temp/"
recorder = BaseRecorder(
name, storage_path, [self.measurement_1, self.measurement_2], 10
)

# Test storing
recorder._measure(**self.neural_state)
recorder._store(0)
data = recorder.load()

assert set(data.keys()) == {"dummy_1", "dummy_2"}
assert_array_equal(data["dummy_1"], np.ones(shape=(1, 3, 10, 5)))
assert_array_equal(data["dummy_2"], 10 * np.ones(shape=(1, 3, 10)))

# Test storing again
recorder._measure(**self.neural_state)
recorder._store(10)
data = recorder.load()

assert set(data.keys()) == {"dummy_1", "dummy_2"}
print(data["dummy_1"].shape)
assert_array_equal(data["dummy_1"], np.ones(shape=(2, 3, 10, 5)))
assert_array_equal(data["dummy_2"], 10 * np.ones(shape=(2, 3, 10)))

# Delete temporary directory
os.system("rm -r temp/")
Loading

0 comments on commit f511d9d

Please sign in to comment.