Skip to content
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
2 changes: 1 addition & 1 deletion .github/test_real.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ cd tests
# we have to copy over the coveragerc file to make sure it's in the
# same directory where codecov is run
cp ../.coveragerc .
testflo --pre_announce --disallow_deprecations -v --coverage --coverpkg pyoptsparse $EXTRA_FLAGS
testflo -i --pre_announce --disallow_deprecations -v --coverage --coverpkg pyoptsparse $EXTRA_FLAGS
2 changes: 1 addition & 1 deletion .github/workflows/linux-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
- name: Run tests
run: |
cd tests
testflo --pre_announce -v -n 1 .
testflo -i --pre_announce -v -n 1 .
2 changes: 1 addition & 1 deletion .github/workflows/windows-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ jobs:
run: |
conda activate pyos-build
cd tests
testflo --pre_announce -v -n 1 .
testflo -i --pre_announce -v -n 1 .
3 changes: 3 additions & 0 deletions pyoptsparse/pyNSGA2/pyNSGA2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def __init__(self, raiseError=True, options={}):
if isinstance(nsga2, str) and raiseError:
raise ImportError(nsga2)

if self.getOption("PopSize") % 4 != 0:
raise ValueError("Option 'PopSize' must be a multiple of 4")

@staticmethod
def _getInforms():
informs = {}
Expand Down
2 changes: 1 addition & 1 deletion pyoptsparse/pyNSGA2/source/allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void allocate_memory_ind (individual *ind, Global global)
if (global.nbin != 0)
{
ind->xbin = (double *)malloc(global.nbin*sizeof(double));
ind->gene = (int **)malloc(global.nbin*sizeof(int));
ind->gene = (int **)malloc(global.nbin*sizeof(int *));
for (j=0; j<global.nbin; j++)
{
ind->gene[j] = (int *)malloc(global.nbits[j]*sizeof(int));
Expand Down
4 changes: 2 additions & 2 deletions pyoptsparse/pyNSGA2/source/crowddist.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void assign_crowding_distance_list (population *pop, list *lst, int front_size,
pop->ind[lst->child->index].crowd_dist = INF;
return;
}
obj_array = (int **)malloc(global.nobj*sizeof(int));
obj_array = (int **)malloc(global.nobj*sizeof(int *));
dist = (int *)malloc(front_size*sizeof(int));
for (i=0; i<global.nobj; i++)
{
Expand Down Expand Up @@ -66,7 +66,7 @@ void assign_crowding_distance_indices (population *pop, int c1, int c2, Global g
pop->ind[c2].crowd_dist = INF;
return;
}
obj_array = (int **)malloc(global.nobj*sizeof(int));
obj_array = (int **)malloc(global.nobj*sizeof(int *));
dist = (int *)malloc(front_size*sizeof(int));
for (i=0; i<global.nobj; i++)
{
Expand Down
9 changes: 8 additions & 1 deletion tests/test_nsga2_multi_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def setup_optProb(self, n_obj):
@parameterized.expand(
[
(1,),
# (2,), # skipping flaky multi-objective test
(2,),
]
)
def test_opt(self, n_obj):
Expand All @@ -73,6 +73,13 @@ def test_opt(self, n_obj):
assert_allclose(sol.fStar["obj1"], 12.0, atol=tol, rtol=tol)
assert_allclose(sol.fStar["obj2"], 0.0, atol=tol, rtol=tol)

def test_options(self):
with self.assertRaises(ValueError):
# PopSize must be a multiple of 4
self.setup_optProb(1)
optOptions = {"PopSize": 5}
self.optimize(optOptions=optOptions)


if __name__ == "__main__":
unittest.main()