app.domain.helpers

Submodules

app.domain.helpers.enums

Module with classes that inherit from python’s builtin Enum class.

class HttpCodes(value)[source]

Bases: enum.Enum

Enumerator class used to represent HTTP response codes.

The following codes are considered:

  • DUMMY: Dummy value. Use when no valid HTTP code exists;

  • OK: Callee accepts the sent file;

  • BAD_REQUEST: Callee refuses the integrity of sent file;

  • NOT_FOUND: Callee is not a member of the network;

  • NOT_ACCEPTABLE: Callee already has a file with same Id;

  • TIME_OUT: Message lost in translation;

  • SERVER_DOWN: Metadata server is offline;

BAD_REQUEST: int = 400
DUMMY: int = -1
NOT_ACCEPTABLE: int = 406
NOT_FOUND: int = 404
OK: int = 200
SERVER_DOWN: int = 521
TIME_OUT: int = 408
class Status(value)[source]

Bases: enum.Enum

Enumerator that defines connectivity status of a network node.

The following status exist:

  • SUSPECT: Network node may be offline;

  • OFFLINE: Network node is offline;

  • ONLINE: Network node is online;

OFFLINE: int = 2
ONLINE: int = 3
SUSPECT: int = 1

app.domain.helpers.exceptions

Module with classes that inherit from Python’s builtin Exception class and represent domain specific errors.

exception DistributionShapeError(value='')[source]

Bases: Exception

Raised when a vector shape is expected to match a matrix’s column or row shape and does not.

__init__(value='')[source]

Initialize self. See help(type(self)) for accurate signature.

exception IllegalArgumentError(value='')[source]

Bases: ValueError

Generic error used to indicate a parameter is not valid or expected.

__init__(value='')[source]

Initialize self. See help(type(self)) for accurate signature.

exception MatlabEngineContainerError(value='')[source]

Bases: Exception

Raised an AttributeError or EngineError is found in matlab container modules.

__init__(value='')[source]

Initialize self. See help(type(self)) for accurate signature.

exception MatrixError(value='')[source]

Bases: Exception

Generic Matrix Error, can be used for example when a pandas DataFrame has shape (0, 0) or is one-dimensional.

__init__(value='')[source]

Initialize self. See help(type(self)) for accurate signature.

exception MatrixNotSquareError(value='')[source]

Bases: Exception

Raised when a function expects a square (N * N) matrix in any representation and some other dimensions are given.

__init__(value='')[source]

Initialize self. See help(type(self)) for accurate signature.

app.domain.helpers.matlab_utils

Module with Matlab related classes.

class MatlabEngineContainer[source]

Bases: object

Singleton class wrapper containing thread safe access to a MatlabEngine.

This class provides a thread-safe way to access one singleton matlab engine object when running simulations in threaded mode. Having one single engine is important, since starting up an engine takes approximately 12s (machine dependant), not including the time matlab scripts are executing and data convertions between python and matlab and back.

eng

A matlab engine instance, which can be used for example for matrix and vector optimization operations throughout the simulations.

Note

MatlabEngine objects are not thread safe, thus it is recommended that you utilize the a wrapper function that obtains _LOCK, before you send any requests to eng.

__init__()[source]

Instantiates a new MatlabEngineContainer object.

Note

Do not directly invoke constructor, use get_instance() instead.

Return type

None

static get_instance()[source]

Used to obtain a singleton instance of MatlabEngineContainer.

If one instance already exists that instance is returned, otherwise a new one is created and returned.

Returns

A reference to the existing MatlabEngineContainer instance or None if matlab python engine is not properly installed.

Return type

app.domain.helpers.matlab_utils.MatlabEngineContainer

matrix_global_opt(a, v_)[source]

Constructs an optimized transition matrix using the matlab engine.

Constructs an optimized transition matrix using linear programming relaxations and convex envelope approximations for the specified steady state v_, this is done by invoke the matlabscript matrixGlobalOpt.m located inside MATLAB_DIR.

Parameters
  • a (numpy.ndarray) – A non-optimized symmetric adjency matrix.

  • v_ (numpy.ndarray) – A stochastic steady state distribution vector.

Returns

Markov Matrix with v_ as steady state distribution and the respective mixing rate or None.

Raises

EngineError – If you do not have a valid MatLab license.

Return type

Any

_LOCK = <unlocked _thread.RLock object owner=0 count=0>

A re-entrant lock used to make eng shareable by multiple threads.

_instance: app.domain.helpers.matlab_utils.MatlabEngineContainer = None

A reference to the instance of MatlabEngineContainer or None.

app.domain.helpers.matrices

Module used by domain.cluster_groups.Cluster to create transition matrices for the simulation.

You should implement your own metropolis-hastings or alternative algorithms as well as any steady-state or transition matrix optimization algorithms in this module.

_adjency_matrix_sdp_optimization(a)[source]

Optimizes a symmetric adjacency matrix using Semidefinite Programming.

The optimization is done with respect to the uniform stochastic vector with the the same length as the inputed symmetric matrix.

Note

This function tries to use Mosek Solver, if a valid license is not found, it uses SCS Solver instead.

Parameters

a (numpy.ndarray) – Any symmetric adjacency matrix.

Returns

The optimal matrix or None if the problem is unfeasible.

Return type

Optional[Tuple[cvxpy.problems.problem.Problem, cvxpy.expressions.variable.Variable]]

_construct_random_walk_matrix(a)[source]

Builds a random walk matrix over the given adjacency matrix

Parameters

a (numpy.ndarray) – Any adjacency matrix.

Returns

A matrix representing the performed random walk.

Return type

numpy.ndarray

_construct_rejection_matrix(rw, v_)[source]

Builds a matrix of rejection probabilities for a given random walk.

Parameters
Returns

A matrix whose entries are acceptance probabilities for rw.

Return type

numpy.ndarray

_get_diagonal_entry_probability_v1(rw, r, i)[source]

Helper function used during the metropolis-hastings algorithm.

Calculates the value that should be assigned to the entry (i, i) of the transition matrix being calculated by the metropolis hastings algorithm by considering the rejection probability over the random walk that was performed on an adjacency matrix.

Note

This method does considers element-wise rejection probabilities for random walk matrices. If you wish to implement a modification of the metropolis-hastings algorithm and you do not utilize rejection matrices use _get_diagonal_entry_probability_v2() instead.

Parameters
  • rw (numpy.ndarray) – A random walk over an adjacency matrix.

  • r (numpy.ndarray) – A matrix whose entries contain acceptance probabilities for rw.

  • i (int) – The diagonal-index of rw where summation needs to be performed on. E.g.: rw[i, i].

Returns

A probability to be inserted at entry (i, i) of the transition matrix outputed by the _metropolis_hastings().

Return type

numpy.float64

_get_diagonal_entry_probability_v2(m, i)[source]

Helper function used during the metropolis-hastings algorithm.

Calculates the value that should be assigned to the entry (i, i) of the transition matrix being calculated by the metropolis hastings algorithm by considering the rejection probability over the random walk that was performed on an adjacency matrix.

Note

This method does not consider element-wise rejection probabilities for random walk matrices. If you wish to implement a modification of the metropolis-hastings algorithm and you utilize rejection matrices use _get_diagonal_entry_probability_v1() instead.

Parameters
  • m (numpy.ndarray) – The matrix to receive the diagonal entry value.

  • i (int) – The diagonal entry index. E.g.: m[i, i].

Returns

A probability to be inserted at entry (i, i) of the transition matrix outputed by the _metropolis_hastings().

Return type

numpy.float64

_metropolis_hastings(a, v_, column_major_out=True, version=2)[source]

Constructs a transition matrix using metropolis-hastings algorithm.

Note

The input Matrix hould have no transient states/absorbent nodes, but this is not enforced or verified.

Parameters
  • a (numpy.ndarray) – A symmetric adjency matrix.

  • v_ (numpy.ndarray) – A stochastic vector that is the steady state of the resulting transition matrix.

  • column_major_out (bool) – Indicates whether to return transition_matrix output is in row or column major form.

  • version (int) – Indicates which version of the algorith should be used (default is version 2).

Returns

An unlabeled transition matrix with steady state v_.

Raises
Return type

numpy.ndarray

get_mixing_rate(m)[source]

Calculats the fast mixing rate the input matrix.

The fast mixing rate of matrix m is the highest eigenvalue that is smaller than one. If returned value is 1.0 than the matrix has transient states or absorbent nodes and as a result is not a markov matrix.

Parameters

m (numpy.ndarray) – A matrix.

Returns

The highest eigenvalue of m that is smaller than one or one.

Return type

float

is_connected(m, directed=False)[source]

Checks if a matrix is connected by counting the number of connected components.

Parameters
  • m (numpy.ndarray) – The matrix to be verified.

  • directed (bool) – If m edges are directed, i.e., if m is an adjency matrix in which the edges bidirectional. False means they are. True means they are not.

Returns

True if the matrix is a connected graph, else False.

Return type

bool

is_symmetric(m, tol=1e-08)[source]

Checks if a matrix is symmetric by performing element-wise equality comparison on entries of m and m.T.

Parameters
  • m (numpy.ndarray) – The matrix to be verified.

  • tol (float) – The tolerance used to verify the entries of the m (default is 1e-8).

Returns

True if the m is symmetric, else False.

Return type

bool

make_connected(m)[source]

Turns a matrix into a connected matrix that could represent a connected graph.

Parameters

m (numpy.ndarray) – The matrix to be made connected.

Returns

A connected matrix. If m was symmetric the modified matrix will also be symmetric.

Return type

numpy.ndarray

new_go_transition_matrix(a, v_)[source]

Constructs a transition matrix using global optimization techniques.

Constructs an optimized markov matrix using linear programming relaxations and convex envelope approximations for the specified steady state v. Result is only trully optimal if \(normal(Mopt - (1 / len(v)), 2)\) is equal to the highest Markov Matrix eigenvalue that is smaller than one.

Parameters
  • a (numpy.ndarray) – A non-optimized symmetric adjency matrix.

  • v_ (numpy.ndarray) – A stochastic steady state distribution vector.

Returns

Markov Matrix with v_ as steady state distribution and the respective mixing rate.

Return type

Tuple[Optional[numpy.ndarray], float]

new_mgo_transition_matrix(a, v_)[source]

Constructs an optimized transition matrix using the matlab engine.

Constructs an optimized transition matrix using linear programming relaxations and convex envelope approximations for the specified steady state v. Result is only trully optimal if \(normal(Mopt - (1 / len(v)), 2)\) is equal to the highest Markov Matrix eigenvalue that is smaller than one.

Note

This function’s code runs inside a matlab engine because it provides a non-convex SDP solver BMIBNB. If you do not have valid matlab license the output of this function is always (None, float('inf').

Parameters
  • a (numpy.ndarray) – A non-optimized symmetric adjency matrix.

  • v_ (numpy.ndarray) – A stochastic steady state distribution vector.

Returns

Markov Matrix with v_ as steady state distribution and the respective mixing rate.

Return type

Tuple[Optional[numpy.ndarray], float]

new_mh_transition_matrix(a, v_)[source]

Constructs a transition matrix using metropolis-hastings.

Constructs a transition matrix using metropolis-hastings algorithm for the specified steady state v.

Note

The input Matrix hould have no transient states or absorbent nodes, but this is not enforced or verified.

Parameters
Returns

Markov Matrix with v_ as steady state distribution and the respective mixing rate or None, float('inf') if the problem is infeasible.

Return type

Tuple[numpy.ndarray, float]

new_sdp_mh_transition_matrix(a, v_)[source]

Constructs a transition matrix using semi-definite programming techniques.

Constructs a transition matrix using metropolis-hastings algorithm for the specified steady state v. The provided adjacency matrix A is first optimized with semi-definite programming techniques for the uniform distribution vector.

Parameters
  • a (numpy.ndarray) – A non-optimized symmetric adjency matrix.

  • v_ (numpy.ndarray) – A stochastic steady state distribution vector.

Returns

Markov Matrix with v_ as steady state distribution and the respective mixing rate or None, float('inf') if the problem is infeasible.

Return type

Tuple[Optional[numpy.ndarray], float]

new_symmetric_connected_matrix(size, allow_sloops=True, force_sloops=True)[source]

Generates a random symmetric matrix which is also connected.

See new_symmetric_matrix() and make_connected().

Parameters
Returns

A matrix that represents an adjacency matrix that is also connected.

Return type

numpy.ndarray

new_symmetric_matrix(size, allow_sloops=True, force_sloops=True)[source]

Generates a random symmetric matrix.

The generated adjacency matrix does not have transient state sets or absorbent nodes and can effectively represent a network topology with bidirectional connections between network nodes.

Parameters
  • size (int) – The length of the square matrix.

  • allow_sloops (bool) – Indicates if the generated adjacency matrix allows diagonal entries representing self-loops. If False, then, all diagonal entries must be zeros. Otherwise, they can be zeros or ones.

  • force_sloops (bool) – Indicates if the diagonal of the generated matrix should be filled with ones. If False valid diagonal entries are decided by allow_self_loops param. Otherwise, diagonal entries are filled with ones. If allow_self_loops is False and enforce_loops is True, an error is raised.

Returns

The adjency matrix representing the connections between a groups of network nodes.

Raises

IllegalArgumentError – When allow_self_loops (False) conflicts with enforce_loops (True).

Return type

numpy.ndarray

new_vector(size)[source]
Parameters

size (int) –

Return type

numpy.ndarray

app.domain.helpers.smart_dataclasses

Module with classes that help to avoid domain class polution by encapsulating attribute and method behaviour.

class FileBlockData(cluster_id, name, number, data)[source]

Bases: object

Wrapping class for the contents of a file block.

Among other responsabilities FileBlockData helps managing simulation parameters, e.g., replica control such or file block integrity.

cluster_id

Unique identifier of the cluster that manages the file block.

name

The name of the file the file block belongs to.

number

The number that uniquely identifies the file block.

id

Concatenation the the name and number.

references

Tracks how many references exist to the file block in the simulation environment. When it reaches 0 the file block ceases to exist and the simulation fails.

replication_epoch

When a reference to the file block is lost, i.e., decremented, a replication epoch that simulates time to copy blocks from one node to another is assigned to this attribute. Until a loss occurs and after a loss is recovered, recovery_epoch is set to positive infinity.

data

A base64-encoded string representation of the file block bytes.

sha256

The hash value of data resulting from a SHA256 digest.

__init__(cluster_id, name, number, data)[source]

Creates an instance of FileBlockData.

Parameters
  • cluster_id (str) – Unique identifier of the cluster that manages the file block.

  • name (str) – The name of the file the file block belongs to.

  • number (int) – The number that uniquely identifies the file block.

  • data (bytes) – Actual file block data as a sequence of bytes.

Return type

None

__str__()[source]

Overrides default string representation of FileBlockData instances.

Returns

A dictionary representation of the object.

can_replicate(epoch)[source]

Informs the calling network node if file block needs replication.

Parameters

epoch (int) – Simulation’s current epoch.

Returns

How many times the caller should replicate the block. The network node knows how many blocks he needs to create and distribute if returned value is bigger than zero.

Return type

int

decrement_and_get_references()[source]

Decreases by one and gets the number of file block references.

Returns

The number of file block references existing in the simulation environment.

set_replication_epoch(epoch)[source]

Sets the epoch in which replication levels should be restored.

This method tries to assign a new epoch, in the future, at which recovery should be performed. If the proposition is sooner than the previous proposition then assignment is accepted, else, it’s rejected.

Note

This method of calculating the replication_epoch may seem controversial, but the justification lies in the assumption that if there are more network nodes monitoring file parts, than failure detections should be in theory, faster, unless complex consensus algorithms are being used between volatile peers, which is not our case. We assume peers only report their suspicions to a small number of trusted of monitors who then decide if the reported network node is disconnected, consequently losing the instance of FileBlockData and possibly others.

Parameters

epoch (int) – Simulation’s current epoch.

Returns

Zero if the current replication_epoch is positive infinity, otherwise the expected delay_replication is returned. This value can be used to log, for example, the average recovery delay_replication in a simulation.

Return type

float

update_epochs_to_recover(epoch)[source]

Update the replication_epoch after a recovery attempt was carried out.

If the recovery attempt performed by some network node successfully managed to restore the replication levels to the original target, then, replication_epoch is set to positive infinity, otherwise, another attempt will be done in the next epoch.

Parameters

epoch (int) – Simulation’s current epoch.

Return type

None

class FileData(name, sim_id=0, origin='')[source]

Bases: object

Holds essential simulation data concerning files being persisted.

FileData is a helper class which has responsabilities such as tracking how many file block replicas currently existing in a cluster group but also keeping simulation events logged in RAM until the simulation ends, at which point the logs are written to disk.

name

The name of the original file.

Type

str

existing_replicas

The number of file parts including blocks that exist for the named file that exist in the simulation. Updated every epoch.

Type

int

logger

Object that stores captured simulation data. Stored data can be post-processed using user defined scripts to create items such has graphs and figures.

Type

LoggingData

out_file

File output stream to where captured data is written in append mode and to which logger will be written to at the end of the simulation.

Type

Union[str, bytes, int]

__init__(name, sim_id=0, origin='')[source]

Creates an instance of FileData.

Parameters
  • name (str) – Name of the file to be referenced by the FileData object.

  • sim_id (int) – Identifier that generates unique output file names, thus guaranteeing that different simulation instances do not overwrite previous output files.

  • origin (str) – The name of the simulation file name that started the simulation process. See Master and hive_simulation. In addition to the previous, the origin should somehow include the cluster class name being run, to differentiate simulations’ output files being executed by different distributed storage system implementations.

Return type

None

fclose(msg=None)[source]

Closes the output stream controlled by the FileData instance.

Parameters

msg (Optional[str]) – If filled, a termination message is appended to out_file, before closing it.

Return type

None

fwrite(msg)[source]

Appends a message to the output stream of FileData.

The method automatically adds a new line character to msg.

Parameters

msg (str) – The message to be logged on the out_file.

Return type

None

jwrite(cluster, origin, epoch)[source]

Appends a json string to the output stream of FileData.

The logged data are all attributes belonging to logger.

Parameters
Return type

None

class LoggingData[source]

Bases: object

Logger object that stores simulation events and other data.

Note

Some attributes might not be documented, but should be straight forward to understand after inspecting their usage in the source code.

cswc

Indicates how many consecutive steps a file as been in convergence. Once convergence is not verified by equal_distributions() this attribute is reset to zero.

Type

int

largest_convergence_window

Stores the largest convergence window that occurred throughout the simulation, i.e., it stores the highest verified cswc.

Type

int

convergence_set

Set of consecutive epochs in which convergence was verified. This list only stores the most up to date convergence set and like cswc is cleared once convergence is not verified, after being appended to convergence_sets.

Type

List[int]

convergence_sets

Stores all but the most recent convergence_set. If simulation terminates and convergence_set is not an empty list, that list will be appended to this one.

Type

List[List[int]]

terminated

Indicates the epoch at which the simulation was terminated.

Type

int

terminated_messages

Set of at least one error message that led to the failure of the simulation or one success message, at termination epoch.

Type

List[str]

successfull

When the simulation is terminated, this value is set to True if no errors or failures occurred, i.e., if the simulation managed to persist the file throughout the entire simulation epochs.

Type

bool

blocks_corrupted

The number of file block replicas lost at each simulation epoch due to disk errors.

Type

List[int]

blocks_existing

The number of existing file block replicas inside the cluster group members’ storage disks at each epoch.

Type

List[int]

blocks_lost

The number of file block replicas that were lost at each epoch due to network nodes going offline.

Type

List[int]

blocks_moved

The number of messages containing file block replicas that were transmited, including those that were not delivered or acknowledged, at each epoch.

Type

List[int]

cluster_size_bm

The number of network nodes registered at a cluster group's members list, before the maintenance step of the epoch.

Type

List[int]

cluster_size_am

The number of network nodes registered at a cluster group's members list, after the maintenance step of the epoch.

Type

List[int]

cluster_status_bm

Strings describing the health of the cluster group at each epoch, before the maintenance step of the epoch.

Type

List[str]

cluster_status_am

Strings describing the health of the cluster group at each epoch, after the maintenance step of the epoch.

Type

List[str]

delay_replication

Log of the average time it took to recover one or more lost file block replicas, at each epoch.

Type

List[float]

delay_suspects_detection

Log of the time it took for each suspicious network node to be evicted from the his cluster group after having his status changed from online to offline or suspicious.

Type

Dict[int, str]

initial_spread

Records the strategy used distribute file blocks in the beggining of the simulation. See spread_files().

Type

str

matrices_nodes_degrees

Stores the in-degree and out-degree of each network node in the cluster group. One dictionary is kept in the list for each transition matrix used throughout the simulation. The integral part of the float value is the in-degree, the decimal part is the out-degree.

Type

List[Dict[str, float]]

off_node_count

The number of network nodes whose status changed to offline or suspicious, at each epoch.

Type

List[int]

topologies_goal_achieved

Stores if a boolean indicating if each topology achieved the desired density distribution, on average.

Type

List[bool]

topologies_goal_distance

Stores magnitude difference between the desired density distribution and the topologies’ average density distribution.

Type

List[float]

transmissions_failed

The number of message transmissions that were lost in the overlay network of a cluster group, at each epoch.

Type

List[int]

__init__()[source]

Instanciates a LoggingData object.

Return type

None

_recursive_len(item)[source]

Recusively sums the length of all lists in convergence_sets.

Parameters

item (Any) – A sub list of convergence_sets that needs that as not yet been counted.

Returns

The number of epochs that were registered at the inputed sub list.

Return type

int

log_bandwidth_units(n, epoch)[source]

Logs the amount of moved file blocks moved at an epoch.

Parameters
  • n (int) – Number of parts moved at epoch.

  • epoch (int) – A simulation epoch index.

Return type

None

log_corrupted_file_blocks(n, epoch)[source]

Logs the amount of corrupted file block blocks at an epoch.

Parameters
  • n (int) – Number of corrupted blocks

  • epoch (int) – A simulation epoch index.

Return type

None

log_existing_file_blocks(n, epoch)[source]

Logs the amount of existing file blocks in the simulation environment at an epoch.

Parameters
  • n (int) – Number of file blocks in the system.

  • epoch (int) – A simulation epoch index.

Return type

None

log_fail(epoch, message='')[source]

Logs the epoch at which a simulation terminated due to a failure.

Note

This method should only be called when simulation terminates due to a failure such as a the loss of all blocks of a file block or the simultaneous disconnection of all network nodes in the cluster.

Parameters
  • message (str) – A log error message.

  • epoch (int) – A simulation epoch at which termination occurred.

Return type

None

log_lost_file_blocks(n, epoch)[source]

Logs the amount of permanently lost file block blocks at an epoch.

Parameters
  • n (int) – Number of blocks that were lost.

  • epoch (int) – A simulation epoch index.

Return type

None

log_lost_messages(n, epoch)[source]

Logs the amount of failed message transmissions at an epoch.

Parameters
  • n (int) – Number of lost terminated_messages.

  • epoch (int) – A simulation epoch index.

Return type

None

log_maintenance(size_bm, size_am, status_bm, status_am, epoch)[source]

Logs cluster membership status and size at an epoch.

Parameters
  • size_bm (int) – The number of network nodes in the cluster before maintenance.

  • size_am (int) – The number of network nodes in the cluster after maintenance.

  • status_bm (str) – A string that describes the status of the cluster before maintenance.

  • status_am (str) – A string that describes the status of the cluster after maintenance.

  • epoch (int) – A simulation epoch at which termination occurred.

Return type

None

log_matrices_degrees(nodes_degrees)[source]

Logs the degree of all nodes in a Markov Matrix overlay, at the time of its creation, before any faults on the overlay occurs.

Parameters

nodes_degrees (Dict[str, str]) – A dictionary mapping the node identifiers to their in-degree and out-degree seperated by the delimiter i#o.

log_off_nodes(n, epoch)[source]

Logs the amount of disconnected network_nodes at an epoch.

Parameters
  • n (int) – Number of disconnected network_nodes in the system.

  • epoch (int) – A simulation epoch index.

Return type

None

log_replication_delay(delay, calls, epoch)[source]

Logs the expected delay_replication at epoch at an epoch.

Parameters
  • delay (int) – The delay sum.

  • calls (int) – Number of times a delay_replication was generated.

  • epoch (int) – A simulation epoch index.

Return type

None

log_suspicous_node_detection_delay(node_id, delay)[source]

Logs the expected delay_replication at epoch at an epoch.

Parameters
  • delay (int) – The time it took until the specified node was evicted from a Cluster after it was known to be offline by the perfect failure detector.

  • node_id (str) – A unique Network Node identifier.

Return type

None

log_topology_goal_performance(achieved_goal, distance_magnitude)[source]

Logs wether or not the topology reached it’s goals, on average.

Parameters
  • achieved_goal (bool) – Indicates wether or not the topology being registered achieved it’s desired density distribution.

  • distance_magnitude (int) – The magnitude of the distance between the desired density distribution and the topology’s average density distribution.

Return type

None

register_convergence(epoch)[source]

Increments cswc by one and tries to update the convergence_set

Checks if the counter for consecutive epoch convergence is bigger than MIN_CONVERGENCE_THRESHOLD and if it is, it appends the epoch to the most recent convergence_set.

Parameters

epoch (int) – The simulation epoch at which the convergence was verified.

Return type

None

save_sets_and_reset()[source]

Resets all convergence variables

Tries to update largest_convergence_window and convergence_sets when convergence_set is not an empty list.

Return type

None