Skip to content

Commit

Permalink
pylint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Jun 11, 2024
1 parent 7a1a6d7 commit 953964a
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 22 deletions.
52 changes: 52 additions & 0 deletions mcmc/mcmc_coordinator_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,29 +118,50 @@ def __init__(
self._data_receiver = dict()

def register_processor(self, mcmc_vertex):
"""
Records the vertex to its list of vertices
"""
self._mcmc_vertices.append(mcmc_vertex)

@property
def n_samples(self):
"""
n_samples as passed into the init.
"""
return self._n_samples

@property
def burn_in(self):
"""
burn_in as passed inot the init
"""
return self._burn_in

@property
def thinning(self):
"""
thinning as passed into the init
"""
return self._thinning

@property
def degrees_of_freedom(self):
"""
degrees_of_freedom as passed into the init
"""
return self._degrees_of_freedom

@property
def n_data_points(self):
"""
The length of the data passed inot the init
"""
return len(self._data)

def _is_receiver_placement(self, placement):
"""
Checks if this is the first placement seen with this X, Y
"""
x = placement.x
y = placement.y
if (x, y) not in self._data_receiver:
Expand All @@ -149,18 +170,32 @@ def _is_receiver_placement(self, placement):
return self._data_receiver[(x, y)] == placement.p

def get_data_window_size(self, placement):
"""
Gets the window size passed into the init if this is the first \
placement seen with this X, Y otherwise 0
"""
if self._is_receiver_placement(placement):
return self._window_size
return 0

def get_sequence_mask(self, placement, routing_info):
"""
Gets the mask for the data_partition_name vertex
Only if this is the first placement seen with this X, Y otherwise 0
"""
if self._is_receiver_placement(placement):
mask = routing_info.get_routing_info_from_pre_vertex(
self, self._data_partition_name).mask
return ~mask & 0xFFFFFFFF
return 0

def get_acknowledge_key(self, placement, routing_info):
"""
Gets the key for the acknowledge_partition_name vertex
Only if this is the first placement seen with this X, Y otherwise 0
"""
if self._is_receiver_placement(placement):
key = routing_info.get_first_key_from_pre_vertex(
placement.vertex, self._acknowledge_partition_name)
Expand All @@ -169,24 +204,41 @@ def get_acknowledge_key(self, placement, routing_info):

@property
def data_tag(self):
"""
Gets the data_tag value passed into the init
"""
return self._data_tag

@property
def acknowledge_timer(self):
"""
Gets the receive_timer passed inot the init
"""
return self._receive_timer

@property
def seed(self):
"""
Get a consistent random seed
Uses the one passed into the init or creates one on the first call
"""
if self._seed is None:
return [random.randint(0, 0xFFFFFFFF) for _ in range(5)]
return self._seed

@property
def data_partition_name(self):
"""
The data_partition_name passed into the init.
"""
return self._data_partition_name

@property
def acknowledge_partition_name(self):
"""
acknowledge_partition_name passed inot the init.
"""
return self._acknowledge_partition_name

@property
Expand Down
36 changes: 18 additions & 18 deletions mcmc/mcmc_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import spinnaker_graph_front_end as g
import logging
import time

from spinnman.exceptions import SpinnmanException
from .mcmc_vertex import MCMCVertex
from .mcmc_coordinator_vertex import MCMCCoordinatorVertex
from .mcmc_root_finder_vertex import MCMCRootFinderVertex
from .mcmc_cholesky_vertex import MCMCCholeskyVertex
from . import model_binaries
from spinnman.model.enums.cpu_state import CPUState

from pacman.model.graphs.machine import MachineEdge

from spinnman.model.enums.cpu_state import CPUState

from spinn_front_end_common.data import FecDataView

import logging
import time
import spinnaker_graph_front_end as g

from .mcmc_vertex import MCMCVertex
from .mcmc_coordinator_vertex import MCMCCoordinatorVertex
from .mcmc_root_finder_vertex import MCMCRootFinderVertex
from .mcmc_cholesky_vertex import MCMCCholeskyVertex
from . import model_binaries

# timing
start_time = time.time()
Expand Down Expand Up @@ -246,13 +246,13 @@ def run_mcmc(
finish_time = time.time()

# Note: this timing appears to be incorrect now; needs looking at
print("Overhead time is %s seconds" % (start_computing_time - start_time))
print("Computing time is %s seconds"
% (finish_computing_time - start_computing_time))
print("run_until_complete takes %s seconds"
% (mid_computing_time - start_computing_time))
print("Data collecting time is %s seconds"
% (finish_time - finish_computing_time))
print("Overall running time is %s seconds" % (finish_time - start_time))
print(f"Overhead time is {start_computing_time - start_time} seconds" )
print(f"Computing time is {finish_computing_time - start_computing_time}"
f" seconds")
print(f"run_until_complete takes "
f"{mid_computing_time - start_computing_time} seconds")
print(f"Data collecting time is "
f"{finish_time - finish_computing_time} seconds")
print(f"Overall running time is {finish_time - start_time} seconds")

return samples
2 changes: 1 addition & 1 deletion mcmc/mcmc_state_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def name(self):
@property
def initial_value(self):
"""
The initial value as passed inot the init
"""
return self._initial_value

Expand Down
39 changes: 39 additions & 0 deletions mcmc/mcmc_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ def __init__(self, coordinator, model,
self._cholesky_data_receiver = dict()

def _get_model_parameters_array(self):
"""
Convert the models parameters into a numpy array
"""
parameters = self._model.get_parameters()
numpy_format = list()
numpy_values = list()
Expand All @@ -119,6 +122,9 @@ def _get_model_parameters_array(self):
[tuple(numpy_values)], dtype=numpy_format).view("uint32")

def _get_model_state_array(self):
"""
Convert the models state variables into a numpy array
"""
state = self._model.get_state_variables()
numpy_format = list()
numpy_values = list()
Expand All @@ -144,6 +150,11 @@ def _get_model_state_array(self):
[tuple(numpy_values)], dtype=numpy_format).view("uint32")

def get_result_key(self, placement):
"""
Get the key for the given placement if it is the first on this X Y
param Placement placement: the placement to get the result key for
"""
if self._is_receiver_placement(placement):
routing_info = FecDataView.get_routing_infos()
key = routing_info.get_first_key_from_pre_vertex(
Expand All @@ -152,6 +163,9 @@ def get_result_key(self, placement):
return 0

def _is_receiver_placement(self, placement):
"""
Checks if this is the first placement seen with this X, Y
"""
x = placement.x
y = placement.y
if (x, y) not in self._data_receiver:
Expand All @@ -160,6 +174,11 @@ def _is_receiver_placement(self, placement):
return self._data_receiver[(x, y)] == placement.p

def get_cholesky_result_key(self, placement):
"""
Get the key for the given placement if it is the first on this X Y
param Placement placement: the placement to get the result key for
"""
if self._is_cholesky_receiver_placement(placement):
routing_info = FecDataView.get_routing_infos()
key = routing_info.get_first_key_from_pre_vertex(
Expand All @@ -168,6 +187,9 @@ def get_cholesky_result_key(self, placement):
return 0

def _is_cholesky_receiver_placement(self, placement):
"""
Checks if this is the first placement seen with this X, Y
"""
x = placement.x
y = placement.y
if (x, y) not in self._cholesky_data_receiver:
Expand All @@ -177,22 +199,37 @@ def _is_cholesky_receiver_placement(self, placement):

@property
def coordinator(self):
"""
Returns the coordinator vertex passed intoi the init
"""
return self._coordinator

@property
def parameter_partition_name(self):
"""
The parameter_partition_name passed into the init
"""
return self._parameter_partition_name

@property
def result_partition_name(self):
"""
The result_partition_name passed into the init
"""
return self._result_partition_name

@property
def cholesky_partition_name(self):
"""
The cholesky_partition_name passed into the init
"""
return self._cholesky_partition_name

@property
def cholesky_result_partition_name(self):
"""
The cholesky_result_partition_name passed into the init
"""
return self._cholesky_result_partition_name

@property
Expand Down Expand Up @@ -343,9 +380,11 @@ def read_samples(self, buffer_manager, placement):
else:
return numpy.array(data, dtype="uint8").view(numpy_format)

@overrides(AbstractReceiveBuffersToHost.get_recorded_region_ids)
def get_recorded_region_ids(self):
return [0]

@overrides(AbstractReceiveBuffersToHost.get_recording_region_base_address)
def get_recording_region_base_address(self, placement):
return helpful_functions.locate_memory_region_for_placement(
placement, MCMCRegions.RECORDING.value)
2 changes: 1 addition & 1 deletion mcmc_examples/arma/arma_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy
from typing import List
import numpy
from spinn_utilities.overrides import overrides

from mcmc.mcmc_model import MCMCModel
Expand Down
9 changes: 7 additions & 2 deletions mcmc_examples/lighthouse/lighthouse_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
# limitations under the License.

from typing import List
import numpy
from spinn_utilities.overrides import overrides

from mcmc.mcmc_model import MCMCModel
from mcmc.mcmc_parameter import MCMCParameter
from mcmc.mcmc_state_variable import MCMCStateVariable

import numpy


class LightHouseModel(MCMCModel):
""" MCMC Model for the lighthouse problem
Expand Down Expand Up @@ -74,8 +73,14 @@ def get_state_variables(self) -> List[MCMCStateVariable]:

@property
def root_finder(self):
"""
The root_finder passed inot the init.
"""
return self._root_finder

@property
def cholesky(self):
"""
The cholesky passed into the init.
"""
return self._cholesky

0 comments on commit 953964a

Please sign in to comment.