Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify travis config file to add job matrix #120

Merged
merged 3 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
sudo: false
language: python
python:
- "3.6"
- "3.7"
- "3.8"
env:
- DEP=[all]
- DEP=
branches:
only:
- master
jobs:
exclude:
- python: "3.6"
env: DEP=
- python: "3.7"
env: DEP=
before_install:
- wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
- chmod +x miniconda.sh
Expand All @@ -16,15 +24,14 @@ before_install:
- source activate myenv
- pip install --upgrade pip
install:
- pip install -r requirements.txt
- pip install pytest pytest-cov coveralls
- pip install flake8 black
- pip install .[all]
- pip install mypy
- pip install .$DEP
script:
- pytest --cov
- black --check .
- flake8 --config=.flake8 .
- mypy cgp
- cd test && pytest --cov=cgp
after_success:
- coveralls
6 changes: 3 additions & 3 deletions cgp/cartesian_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def _f(x):

def to_torch(
self, parameter_names_to_values: Optional[Dict[str, float]] = None
) -> torch.nn.Module:
) -> "torch.nn.Module":
"""Compile the function(s) represented by the graph to a Torch class.
Generates a definition of the Torch class in Python code and
Expand All @@ -335,7 +335,7 @@ def to_torch(
node.format_parameter_str()
all_parameter_str.append(node.parameter_str)
forward_str = ", ".join(node.output_str for node in self.output_nodes)
class_str = f"""\
class_str = """\
class _C(torch.nn.Module):
def __init__(self):
Expand Down Expand Up @@ -370,7 +370,7 @@ def to_sympy(
self,
simplify: Optional[bool] = True,
parameter_names_to_values: Optional[Dict[str, float]] = None,
) -> List[sympy_expr.Expr]:
) -> List["sympy_expr.Expr"]:
"""Compile the function(s) represented by the graph to a SymPy expression.
Generates one SymPy expression for each output node.
Expand Down
6 changes: 3 additions & 3 deletions cgp/local_search/gradient_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

try:
import torch # noqa: F401
from torch.optim.optimizer import Optimizer
from torch.optim.optimizer import Optimizer # noqa: F401

torch_available = True
except ModuleNotFoundError:
Expand All @@ -16,10 +16,10 @@

def gradient_based(
individual: Individual,
objective: Callable[[torch.nn.Module], torch.Tensor],
objective: Callable[["torch.nn.Module"], "torch.Tensor"],
lr: float,
gradient_steps: int,
optimizer: Optional[Optimizer] = None,
optimizer: Optional["Optimizer"] = None,
clip_value: Optional[float] = None,
) -> None:
"""Perform a local search for numeric leaf values for an individual
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def read_extra_requirements():
extra_requirements = {}
extra_requirements["all"] = []
with open("./extra-requirements.txt") as f:
for l in f:
req = l.replace("\n", " ")
for dep in f:
req = dep.replace("\n", " ")
extra_requirements[req] = [req]
extra_requirements["all"].append(req)

Expand Down
6 changes: 3 additions & 3 deletions test/test_individual.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import math
import pickle
import pytest
import torch

import cgp
from cgp.individual import Individual
Expand Down Expand Up @@ -57,7 +56,7 @@ def test_individual_with_parameter_python():


def test_individual_with_parameter_torch():

torch = pytest.importorskip("torch")
primitives = (cgp.Add, cgp.Parameter)
genome = cgp.Genome(1, 1, 2, 1, 2, primitives)
# f(x) = x + c
Expand Down Expand Up @@ -97,7 +96,7 @@ def test_individual_with_parameter_torch():


def test_individual_with_parameter_sympy():

sympy = pytest.importorskip("sympy") # noqa
primitives = (cgp.Add, cgp.Parameter)
genome = cgp.Genome(1, 1, 2, 1, 2, primitives)
# f(x) = x + c
Expand Down Expand Up @@ -135,6 +134,7 @@ def test_individual_with_parameter_sympy():


def test_to_and_from_torch_plus_backprop():
torch = pytest.importorskip("torch")
primitives = (cgp.Mul, cgp.Parameter)
genome = cgp.Genome(1, 1, 2, 2, 1, primitives)
# f(x) = c * x
Expand Down