Skip to content

[DEFECT] Multi Objective GA - crossover crash with 2 variables #2509

@alfoa

Description

@alfoa

Thank you for the defect report

Defect Description

( 34.99 sec) GeneticAlgorithm : DEBUG -> ### rlz.sizes['RAVEN_sample_ID'] = 50 Traceback (most recent call last): File "/Users/aalfonsi/projects/raven/raven_framework.py", line 25, in <module> sys.exit(main(True)) ^^^^^^^^^^ File "/Users/aalfonsi/projects/raven/ravenframework/Driver.py", line 207, in main raven() File "/Users/aalfonsi/projects/raven/ravenframework/Driver.py", line 160, in raven simulation.run() File "/Users/aalfonsi/projects/raven/ravenframework/Simulation.py", line 909, in run self.executeStep(stepInputDict, stepInstance) File "/Users/aalfonsi/projects/raven/ravenframework/Simulation.py", line 842, in executeStep stepInstance.takeAstep(stepInputDict) File "/Users/aalfonsi/projects/raven/ravenframework/Steps/Step.py", line 320, in takeAstep self._localTakeAstepRun(inDictionary) File "/Users/aalfonsi/projects/raven/ravenframework/Steps/MultiRun.py", line 224, in _localTakeAstepRun sampler.finalizeActualSampling(finishedJobList[0],model,inputs) File "/Users/aalfonsi/projects/raven/ravenframework/Samplers/Sampler.py", line 1134, in finalizeActualSampling self.localFinalizeActualSampling(jobObject, model, myInput) File "/Users/aalfonsi/projects/raven/ravenframework/Optimizers/RavenSampled.py", line 325, in localFinalizeActualSampling self._useRealization(info, rlz) File "/Users/aalfonsi/projects/raven/ravenframework/Optimizers/GeneticAlgorithm.py", line 870, in _useRealization childrenXover = self._crossoverInstance(parents=parents, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/aalfonsi/projects/raven/ravenframework/Optimizers/crossOverOperators/crossovers.py", line 139, in twoPointsCrossover [loc1,loc2] = randomUtils.randomChoice(list(range(1,nGenes)), size=2, replace=False, engine=None) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/aalfonsi/projects/raven/ravenframework/utils/randomUtils.py", line 409, in randomChoice raise RuntimeError("array size < of number of requested samples (size)") RuntimeError: array size < of number of requested samples (size)

This happens when you have only 2 variables to optimize. It is due to line 139 in crossovers.py:
[loc1,loc2] = randomUtils.randomChoice(list(range(1,nGenes)), size=2, replace=False, engine=None)

This list(range(1,nGenes)) returns a list of 1 element when it should return 2?

I guess that line should be modified to
[loc1,loc2] = randomUtils.randomChoice(list(range(0,nGenes)), size=nGenes, replace=False, engine=None)

Steps to Reproduce

just take the MinwoRepMultiObjective.xml test file and convert to 2 variables case.

Expected Behavior

No crash?

Screenshots and Input Files

No response

OS

Linux

OS Version

No response

Dependency Manager

PIP

For Change Control Board: Issue Review

  • Is it tagged with a type: defect or task?
  • Is it tagged with a priority: critical, normal or minor?
  • If it will impact requirements or requirements tests, is it tagged with requirements?
  • If it is a defect, can it cause wrong results for users? If so an email needs to be sent to the users.
  • Is a rationale provided? (Such as explaining why the improvement is needed or why current code is wrong.)

For Change Control Board: Issue Closure

  • If the issue is a defect, is the defect fixed?
  • If the issue is a defect, is the defect tested for in the regression test system? (If not explain why not.)
  • If the issue can impact users, has an email to the users group been written (the email should specify if the defect impacts stable or master)?
  • If the issue is a defect, does it impact the latest release branch? If yes, is there any issue tagged with release (create if needed)?
  • If the issue is being closed without a pull request, has an explanation of why it is being closed been provided?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions