Skip to content

Commit

Permalink
Fix all test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
blankjul committed Jul 5, 2022
1 parent a0cac1e commit ae7d4ab
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/algorithms/moo/nsga2/nsga2_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pymoo.core.crossover import Crossover
from pymoo.core.duplicate import ElementwiseDuplicateElimination
from pymoo.core.mutation import Mutation
from pymoo.core.problem import Problem, ElementwiseProblem
from pymoo.core.problem import ElementwiseProblem
from pymoo.core.sampling import Sampling
from pymoo.optimize import minimize
from pymoo.visualization.scatter import Scatter
Expand Down
7 changes: 4 additions & 3 deletions pymoo/core/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,10 @@ def _evaluate_elementwise(self, X, out, *args, **kwargs):

out[k].append(v)

# convert to arrays (the none check is important because otherwise an empty array is initialized)
for k in out:
out[k] = anp.array(out[k])
if out[k] is not None:
out[k] = anp.array(out[k])

def _format_dict(self, out, N, return_values_of):

Expand All @@ -280,8 +282,7 @@ def _format_dict(self, out, N, return_values_of):
v = v.reshape(shape[name])
except Exception as e:
raise Exception(
f"Problem Error: {name} can not be set, expected shape {shape[name]} but provided {v.shape}",
e)
f"Problem Error: {name} can not be set, expected shape {shape[name]} but provided {v.shape}", e)

ret[name] = v

Expand Down
9 changes: 5 additions & 4 deletions pymoo/gradient/automatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ def __call__(self, x):

class ElementwiseAutomaticDifferentiation(Meta, Problem):

def __init__(self, object, copy=True):
super().__init__(object, copy)
def __init__(self, problem, copy=True):
if not problem.elementwise:
raise Exception("Elementwise automatic differentiation can only be applied to elementwise problems.")

super().__init__(problem, copy)
self.elementwise_func = ElementwiseEvaluationFunctionWithGradient


Expand All @@ -52,5 +55,3 @@ def do(self, x, return_values_of, *args, **kwargs):
out["d" + k] = v

return out


2 changes: 0 additions & 2 deletions tests/algorithms/test_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ class MyThreadedProblem(ElementwiseProblem):
def __init__(self):
super().__init__(n_var=2,
n_obj=1,
n_ieq_constr=0,
parallelization=("threads", 4),
xl=np.array([0, 0]),
xu=np.array([100, 100]))

Expand Down
2 changes: 1 addition & 1 deletion tests/problems/test_autodiff.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pytest

from pymoo.gradient.automatic import AutomaticDifferentiation
from pymoo.gradient.automatic import AutomaticDifferentiation, ElementwiseAutomaticDifferentiation
from pymoo.gradient.grad_complex import ComplexNumberGradient
from pymoo.operators.sampling.rnd import FloatRandomSampling
from pymoo.problems import get_problem
Expand Down

0 comments on commit ae7d4ab

Please sign in to comment.