Skip to content

Commit

Permalink
Improved compatibility with py3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
squillero committed Aug 23, 2023
1 parent 969cd43 commit af0ea59
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 18 deletions.
4 changes: 2 additions & 2 deletions byron/classes/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
'ScriptEvaluator',
]

from typing import Callable, Sequence
from typing import Callable, Sequence, Optional
from abc import ABC, abstractmethod
from dataclasses import dataclass
from itertools import zip_longest
Expand Down Expand Up @@ -444,7 +444,7 @@ class ScriptEvaluator(EvaluatorABC):
def __init__(
self,
script_name: str,
args: Sequence[str] | None = None,
args: Optional[Sequence[str]] = None,
*,
filename_format: str = 'phenotype_{i:x}.txt',
timeout: int | None = 60,
Expand Down
12 changes: 3 additions & 9 deletions byron/classes/individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ class Individual(Paranoid):
__COUNTER: int = 0

_genome: nx.classes.MultiDiGraph
_fitness: FitnessABC | None
_lineage: Lineage | None
_fitness: Optional[FitnessABC]
_lineage: Optional[Lineage]
_age: Age
_str: str

Expand Down Expand Up @@ -365,7 +365,7 @@ def run_paranoia_checks(self) -> bool:

# ==[check nodes (semantic)]=========================================
assert all(
n < self._genome.graph['node_count'] for n in self._genome
n < self._genome.graph["node_count"] for n in self._genome
), f"{PARANOIA_VALUE_ERROR}: Invalid 'node_count' attribute ({self._genome.graph['node_count']})"

assert all(
Expand Down Expand Up @@ -402,12 +402,6 @@ def run_paranoia_checks(self) -> bool:

return True

def consolidate_genome(self) -> None:
self._genome = nx.convert_node_labels_to_integers(self._genome)
fasten_subtree_parameters(NodeReference(self._genome, NODE_ZERO))
self._genome.graph['node_count'] = len(self._genome)
self.run_paranoia_checks()

def describe(
self,
*,
Expand Down
4 changes: 2 additions & 2 deletions byron/classes/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
__all__ = ['ParameterABC', 'ParameterNumericABC', 'ParameterArrayABC', 'ParameterStructuralABC', 'ParameterSharedABC']

from abc import ABC, abstractmethod
from typing import Any
from typing import Any, Optional

from networkx.classes import MultiDiGraph

Expand Down Expand Up @@ -101,7 +101,7 @@ class ParameterStructuralABC(ParameterABC):

__slots__ = [] # Preventing the automatic creation of __dict__

_node_reference: NodeReference | None
_node_reference: Optional[NodeReference]

def __init__(self):
super().__init__()
Expand Down
4 changes: 3 additions & 1 deletion byron/ea/parametric.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

__all__ = ["parametric_ea"]

from typing import Optional

from byron.operators import *
from byron.sys import *
from byron.classes.selement import *
Expand All @@ -52,7 +54,7 @@ def parametric_ea(
mu: int = 10,
lambda_: int = 20,
max_generation: int = 100,
max_fitness: FitnessABC | None = None,
max_fitness: Optional[FitnessABC] = None,
top_best: int = None,
lifespan: int = None,
operators: list = None,
Expand Down
4 changes: 2 additions & 2 deletions byron/ea/vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

__all__ = ["vanilla_ea"]

from typing import Any
from typing import Any, Optional
from time import perf_counter_ns, process_time_ns
from datetime import timedelta

Expand Down Expand Up @@ -73,7 +73,7 @@ def vanilla_ea(
mu: int = 10,
lambda_: int = 20,
max_generation: int = 100,
max_fitness: Any | None = None,
max_fitness: Optional = None,
population_extra_parameters: dict = None,
) -> Population:
r"""A simple evolutionary algorithm
Expand Down
4 changes: 2 additions & 2 deletions byron/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

__all__ = ["Statistics", "fitness_function", "genetic_operator", "get_byron_type"]

from typing import Callable
from typing import Callable, Optional
from dataclasses import dataclass

from functools import wraps
Expand Down Expand Up @@ -99,7 +99,7 @@ def __str__(self):


def fitness_function(
func: Callable[..., FitnessABC] | None = None, /, *, type_: type[FitnessABC] = None, backend: str | None = 'list'
func: Optional[Callable[..., FitnessABC]] = None, /, *, type_: type[FitnessABC] = None, backend: str | None = 'list'
):
if type_ is None:
type_ = lambda f: fitness.make_fitness(f)
Expand Down

0 comments on commit af0ea59

Please sign in to comment.