diff --git a/b_asic/process.py b/b_asic/process.py index 04b1e48196114d3092972c9cef84d3a849241dcc..797af4fa710004c3b2d187011e371686b2a8c830 100644 --- a/b_asic/process.py +++ b/b_asic/process.py @@ -58,7 +58,7 @@ class Process: return self._name def __repr__(self) -> str: - return f"Process({self.start_time}, {self.execution_time}, {self.name})" + return f"Process({self.start_time}, {self.execution_time}, {self.name!r})" # Static counter for default names _name_cnt = 0 @@ -166,7 +166,8 @@ class PlainMemoryVariable(Process): Identifier for the source of the memory variable. reads : {int: int, ...} Dictionary where the key is the destination identifier and the value - is the time after *write_time* that the memory variable is read. + is the time after *write_time* that the memory variable is read, i.e., the + lifetime of the variable. name : str, optional The name of the process. """ diff --git a/test/fixtures/resources.py b/test/fixtures/resources.py index 61c8db254f09014ba55a482a8df28481bdc0d46b..8ef57979f4c7c1a170eeaaa0f6e18e393208132f 100644 --- a/test/fixtures/resources.py +++ b/test/fixtures/resources.py @@ -9,13 +9,13 @@ def simple_collection(): NO_PORT = 0 return ProcessCollection( { - PlainMemoryVariable(4, NO_PORT, {NO_PORT: 2}), - PlainMemoryVariable(2, NO_PORT, {NO_PORT: 6}), - PlainMemoryVariable(3, NO_PORT, {NO_PORT: 5}), - PlainMemoryVariable(6, NO_PORT, {NO_PORT: 2}), - PlainMemoryVariable(0, NO_PORT, {NO_PORT: 3}), - PlainMemoryVariable(0, NO_PORT, {NO_PORT: 2}), - PlainMemoryVariable(0, NO_PORT, {NO_PORT: 6}), + PlainMemoryVariable(4, NO_PORT, {NO_PORT: 2}, "Proc. 1"), + PlainMemoryVariable(2, NO_PORT, {NO_PORT: 6}, "Proc. 2"), + PlainMemoryVariable(3, NO_PORT, {NO_PORT: 5}, "Proc. 3"), + PlainMemoryVariable(6, NO_PORT, {NO_PORT: 2}, "Proc. 4"), + PlainMemoryVariable(0, NO_PORT, {NO_PORT: 3}, "Proc. 5"), + PlainMemoryVariable(0, NO_PORT, {NO_PORT: 2}, "Proc. 6"), + PlainMemoryVariable(0, NO_PORT, {NO_PORT: 6}, "Proc. 7"), }, 8, ) diff --git a/test/test_process.py b/test/test_process.py index 57837ee2692e02be854546b32c89f15b5c445501..e14df4303427622f01cf555330ada1f89bcf8580 100644 --- a/test/test_process.py +++ b/test/test_process.py @@ -1,3 +1,5 @@ +import re + import pytest from b_asic.process import PlainMemoryVariable @@ -10,3 +12,25 @@ def test_PlainMemoryVariable(): assert mem.execution_time == 2 assert mem.life_times == (1, 2) assert mem.read_ports == (4, 5) + assert repr(mem) == "PlainMemoryVariable(3, 0, {4: 1, 5: 2}, 'Proc. 0')" + + mem2 = PlainMemoryVariable(2, 0, {4: 2, 5: 3}, 'foo') + assert repr(mem2) == "PlainMemoryVariable(2, 0, {4: 2, 5: 3}, 'foo')" + + assert mem2 < mem + + mem3 = PlainMemoryVariable(2, 0, {4: 1, 5: 2}) + assert mem2 < mem3 + + +def test_MemoryVariables(secondorder_iir_schedule): + pc = secondorder_iir_schedule.get_memory_variables() + mem_vars = pc.collection + pattern = re.compile( + "MemoryVariable\\(3, <b_asic.port.OutputPort object at 0x[a-f0-9]+>," + " {<b_asic.port.InputPort object at 0x[a-f0-9]+>: 4}, 'cmul1.0'\\)" + ) + mem_var = [m for m in mem_vars if m.name == 'cmul1.0'][0] + assert pattern.match(repr(mem_var)) + assert mem_var.execution_time == 4 + assert mem_var.start_time == 3 diff --git a/test/test_resources.py b/test/test_resources.py index 18a8414193432bd09b3b41a3e03f835073fb8885..020fadfcbf63ff3592ef2f7b2861b73faa8628cd 100644 --- a/test/test_resources.py +++ b/test/test_resources.py @@ -4,6 +4,7 @@ import matplotlib.pyplot as plt import networkx as nx import pytest +from b_asic.process import Process from b_asic.research.interleaver import ( generate_matrix_transposer, generate_random_interleaver, diff --git a/test/test_simulation.py b/test/test_simulation.py index 65d3b5522c28ed557670950f57db81f413b85d84..cdcb86c0c82e1a6c6a2b5f0a603ef101ad086a5d 100644 --- a/test/test_simulation.py +++ b/test/test_simulation.py @@ -46,6 +46,8 @@ class TestRunFor: assert simulation.results["0"][3] == 13 assert simulation.results["1"][3] == 20 + assert simulation.iteration == 101 + def test_with_numpy_arrays_as_input(self, sfg_two_inputs_two_outputs): input0 = np.array([5, 9, 25, -5, 7]) input1 = np.array([7, 3, 3, 54, 2]) @@ -131,15 +133,11 @@ class TestRunFor: ) sim.run() assert ( - sim.results[ - precedence_sfg_delays.find_result_keys_by_name("ADD2")[0] - ][4] + sim.results[precedence_sfg_delays.find_result_keys_by_name("ADD2")[0]][4] == 31220 ) assert ( - sim.results[ - precedence_sfg_delays.find_result_keys_by_name("A1")[0] - ][2] + sim.results[precedence_sfg_delays.find_result_keys_by_name("A1")[0]][2] == 80 ) @@ -220,9 +218,7 @@ class TestRun: input0 = np.array([1, 2, 3, 4, 5]) simulation = Simulation(sfg_simple_filter, [input0]) simulation.run_for(len(input0), save_results=True) - assert all( - simulation.results["0"] == np.array([0, 1.0, 2.5, 4.25, 6.125]) - ) + assert all(simulation.results["0"] == np.array([0, 1.0, 2.5, 4.25, 6.125])) def test_custom_operation(self, sfg_custom_operation): simulation = Simulation(sfg_custom_operation, [lambda n: n + 1])