uni-courses / snncompare

Runs networkx graphs representing spiking neural networks of LIF-neurons on lava-nc or networkx.
GNU Affero General Public License v3.0
2 stars 0 forks source link

Separate code into modules #74

Closed a-t-0 closed 1 year ago

a-t-0 commented 1 year ago
a-t-0 commented 1 year ago
a-t-0 commented 1 year ago
a-t-0 commented 1 year ago
a-t-0 commented 1 year ago
a-t-0 commented 1 year ago

Backup in case you need to export graph from lava getting the monitors error:

# pylint: disable=R0913
    remove_monitors_from_get_degree(get_degree)
    # pylint: disable=R0801
    unique_hash = get_unique_hash(
        test_object.final_dead_neuron_names,
        has_adaptation,
        has_radiation,
        iteration,
        m,
        neuron_death_probability,
        seed,
        sim_time,
    )
a-t-0 commented 1 year ago
@typechecked
def get_unique_hash(
    dead_neuron_names: List[str],
    has_adaptation: bool,
    has_radiation: bool,
    iteration: int,
    m: int,
    neuron_death_probability: float,
    seed: int,
    sim_time: int,
) -> int:
    """

    :param dead_neuron_names:
    :param has_adaptation:
    :param has_radiation: Indicates whether the experiment simulates radiation
    or not.
    param iteration: The initialisation iteration that is used.
    :param m: The amount of approximation iterations used in the MDSA
    approximation.
    :param neuron_death_probability:
    :param seed: The value of the random seed used for this test.
    :param sim_time: Nr. of timesteps for which the experiment is ran.

    """
    # pylint: disable=R0913
    # One could perform work to cluster the properties into different objects.
    # Then one could read out these separate objects and write them to file.
    if dead_neuron_names is None:
        dead_neuron_names = []

    # Needs to be frozen, because otherwise the set is mutable, and mutable
    # Python objects are not hashable.
    hash_set = frozenset(
        [
            frozenset(dead_neuron_names),
            has_adaptation,
            has_radiation,
            iteration,
            m,
            neuron_death_probability,
            seed,
            sim_time,
        ]
    )
    # set(dead_neuron_names),
    # hashable_set = [frozenset(i) for i in hash_set]

    # return hash(hashable_set)
    return hash(hash_set)

@typechecked
def uniq(lst: List) -> Generator:
    """

    :param lst:

    """
    last = object()
    for item in lst:
        if item == last:
            continue
        yield item
        last = item

@typechecked
def sort_and_deduplicate(some_list: List[Any]) -> List[Any]:
    """

    :param list:

    """
    return list(uniq(sorted(some_list, reverse=True)))
a-t-0 commented 1 year ago

Done.