-
Notifications
You must be signed in to change notification settings - Fork 137
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
Mandd/mutator changes #1968
Mandd/mutator changes #1968
Conversation
…rt of the repair duplicated chromosomes in GA
[WIP] adding changes to bitFlipMutator and randomMutator
Mutators tests updated
Job Mingw Test on b005a9b : invalidated by @mandd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wangcj05 : this PR is ready to be reviewed
@mandd The following test failed, I guess you need to re-gold the outputs: FAILED: |
''' | ||
if output.name not in optionalOutputNames: | ||
if output.name not in targetEvaluationNames.keys(): | ||
if 'batchMode' not in joinedResponse.keys(): | ||
output.addRealization(joinedResponse) | ||
else: | ||
inputVarValues = joinedResponse['batchInfo'][0]['batchRealizations'][0]['SampledVars'] | ||
for key in inputVarValues.keys(): | ||
inputVarValues[key] = np.array([inputVarValues[key]]) | ||
metaValues = joinedResponse['batchInfo'][0]['batchRealizations'][0] | ||
for key in metaValues.keys(): | ||
metaValues[key] = np.array([metaValues[key]]) | ||
outputData = joinedResponse | ||
batchData = {**inputVarValues, **metaValues, **outputData} | ||
output.addRealization(batchData) | ||
else: | ||
output.addRealization(outcomes[targetEvaluationNames[output.name]]['response']) | ||
else: | ||
# collect optional output if present and not already collected | ||
output.addRealization(optionalOutputs[optionalOutputNames[output.name]]) | ||
''' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the commented lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
Test has been regolded |
Job Test CentOS 8 on 2b3d0db : invalidated by @joshua-cogliati-inl mystery failure |
Job Test Ubuntu 20-2 Optional on 2b3d0db : invalidated by @joshua-cogliati-inl mystery failure |
Job Test Ubuntu 18-2 Python 3 on 2b3d0db : invalidated by @joshua-cogliati-inl mystery failure |
Job Test Fedora 31 on 2b3d0db : invalidated by @joshua-cogliati-inl mystery failure |
Job Test Fedora 32 on 2b3d0db : invalidated by @joshua-cogliati-inl mystery failure |
Job Test Ubuntu 16 on 2b3d0db : invalidated by @joshua-cogliati-inl mystery failure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mandd I have several comments for you to consider.
@@ -476,6 +476,7 @@ def collectOutput(self,finishedJob,output): | |||
if output.name not in targetEvaluationNames.keys(): | |||
# in the event a batch is run, the evaluations will be a dict as {'RAVEN_isBatch':True, 'realizations': [...]} | |||
if isinstance(evaluation,dict) and evaluation.get('RAVEN_isBatch',False): | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to have an empty space here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
if kwargs['locs'] == None: | ||
locs = list(set(randomUtils.randomChoice(list(np.arange(offSprings.data.shape[1])),size=2,replace=False))) | ||
locs.sort() | ||
else: | ||
locs = [kwargs['locs'][0], kwargs['locs'][1]] | ||
locs.sort() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar lines have been repeated three times in this file, I would to recommend to create a function to perform this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function locationsGenerator has been added
if kwargs['locs'] == None: | ||
locs = list(set(randomUtils.randomChoice(list(np.arange(offSprings.data.shape[1])),size=2,replace=False))) | ||
loc1 = locs[0] | ||
loc2 = locs[1] | ||
loc1 = np.minimum(locs[0], locs[1]) | ||
loc2 = np.maximum(locs[0], locs[1]) | ||
else: | ||
loc1 = kwargs['locs'][0] | ||
loc2 = kwargs['locs'][1] | ||
loc1 = np.minimum(kwargs['locs'][0], kwargs['locs'][1]) | ||
loc2 = np.maximum(kwargs['locs'][0], kwargs['locs'][1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These have been repeated several times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed with new method
This method is designed to randomly mutate a single gene in each chromosome with probability = mutationProb. | ||
@ In, offSprings, xr.DataArray, children resulting from the crossover process | ||
@ In, kwargs, dict, dictionary of parameters for this mutation method: | ||
mutationProb, float, probability that governs the mutation process, i.e., if prob < random number, then the mutation will occur |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docstring for "distDict"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
if kwargs['locs'] == None: | ||
locs = list(set(randomUtils.randomChoice(list(np.arange(offSprings.data.shape[1])),size=2,replace=False))) | ||
locL = np.minimum(locs[0], locs[1]) | ||
locU = np.maximum(locs[0], locs[1]) | ||
else: | ||
locL = np.minimum(kwargs['locs'][0], kwargs['locs'][1]) | ||
locU = np.maximum(kwargs['locs'][0], kwargs['locs'][1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines have been repeated several times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new function has been created
@@ -186,6 +198,7 @@ def inversionMutator(offSprings, distDict, **kwargs): | |||
__mutators['scrambleMutator'] = scrambleMutator | |||
__mutators['bitFlipMutator'] = bitFlipMutator | |||
__mutators['inversionMutator'] = inversionMutator | |||
__mutators['randomMutator'] = randomMutator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the manual for the randomMutator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, added
def checkSameDataArrays(comment, resultedDA, expectedDA, update=True): | ||
""" | ||
This method compares two identical things | ||
@ In, comment, string, a comment printed out if it fails | ||
@ In, resultedDA, xr.DataArray, the resulted DataArray to be tested | ||
@ In, expectedDA, xr.DataArray, the expected DataArray | ||
@ In, update, bool, optional, if False then don't update results counter | ||
@ Out, res, bool, True if same | ||
""" | ||
res = resultedDA.identical(expectedDA) | ||
if update: | ||
if res: | ||
results["pass"] += 1 | ||
else: | ||
print("checking string", comment, '|', resultedDA, "!=", expectedDA) | ||
results["fail"] += 1 | ||
return res | ||
|
||
results = {'pass': 0, 'fail': 0} | ||
|
||
def createElement(tag,attrib={},text={}): | ||
""" | ||
Method to create a dummy xml element readable by the distribution classes | ||
@ In, tag, string, the node tag | ||
@ In, attrib, dict, optional, the attribute of the xml node | ||
@ In, text, dict, optional, the dict containing what should be in the xml text | ||
""" | ||
element = ET.Element(tag,attrib) | ||
element.text = text | ||
return element |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this PR. I think we should start to standardize our unit tests. The first thing to do is to create utils functions for unit tests. For examples, the above functions have been existed in a lot of unit test files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, it looks like it's a Wednesday morning topics
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressing Wang's comments
@@ -476,6 +476,7 @@ def collectOutput(self,finishedJob,output): | |||
if output.name not in targetEvaluationNames.keys(): | |||
# in the event a batch is run, the evaluations will be a dict as {'RAVEN_isBatch':True, 'realizations': [...]} | |||
if isinstance(evaluation,dict) and evaluation.get('RAVEN_isBatch',False): | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
This method is designed to randomly mutate a single gene in each chromosome with probability = mutationProb. | ||
@ In, offSprings, xr.DataArray, children resulting from the crossover process | ||
@ In, kwargs, dict, dictionary of parameters for this mutation method: | ||
mutationProb, float, probability that governs the mutation process, i.e., if prob < random number, then the mutation will occur |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
def checkSameDataArrays(comment, resultedDA, expectedDA, update=True): | ||
""" | ||
This method compares two identical things | ||
@ In, comment, string, a comment printed out if it fails | ||
@ In, resultedDA, xr.DataArray, the resulted DataArray to be tested | ||
@ In, expectedDA, xr.DataArray, the expected DataArray | ||
@ In, update, bool, optional, if False then don't update results counter | ||
@ Out, res, bool, True if same | ||
""" | ||
res = resultedDA.identical(expectedDA) | ||
if update: | ||
if res: | ||
results["pass"] += 1 | ||
else: | ||
print("checking string", comment, '|', resultedDA, "!=", expectedDA) | ||
results["fail"] += 1 | ||
return res | ||
|
||
results = {'pass': 0, 'fail': 0} | ||
|
||
def createElement(tag,attrib={},text={}): | ||
""" | ||
Method to create a dummy xml element readable by the distribution classes | ||
@ In, tag, string, the node tag | ||
@ In, attrib, dict, optional, the attribute of the xml node | ||
@ In, text, dict, optional, the dict containing what should be in the xml text | ||
""" | ||
element = ET.Element(tag,attrib) | ||
element.text = text | ||
return element |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, it looks like it's a Wednesday morning topics
@@ -186,6 +198,7 @@ def inversionMutator(offSprings, distDict, **kwargs): | |||
__mutators['scrambleMutator'] = scrambleMutator | |||
__mutators['bitFlipMutator'] = bitFlipMutator | |||
__mutators['inversionMutator'] = inversionMutator | |||
__mutators['randomMutator'] = randomMutator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, added
if kwargs['locs'] == None: | ||
locs = list(set(randomUtils.randomChoice(list(np.arange(offSprings.data.shape[1])),size=2,replace=False))) | ||
locL = np.minimum(locs[0], locs[1]) | ||
locU = np.maximum(locs[0], locs[1]) | ||
else: | ||
locL = np.minimum(kwargs['locs'][0], kwargs['locs'][1]) | ||
locU = np.maximum(kwargs['locs'][0], kwargs['locs'][1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new function has been created
if kwargs['locs'] == None: | ||
locs = list(set(randomUtils.randomChoice(list(np.arange(offSprings.data.shape[1])),size=2,replace=False))) | ||
locs.sort() | ||
else: | ||
locs = [kwargs['locs'][0], kwargs['locs'][1]] | ||
locs.sort() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function locationsGenerator has been added
if kwargs['locs'] == None: | ||
locs = list(set(randomUtils.randomChoice(list(np.arange(offSprings.data.shape[1])),size=2,replace=False))) | ||
loc1 = locs[0] | ||
loc2 = locs[1] | ||
loc1 = np.minimum(locs[0], locs[1]) | ||
loc2 = np.maximum(locs[0], locs[1]) | ||
else: | ||
loc1 = kwargs['locs'][0] | ||
loc2 = kwargs['locs'][1] | ||
loc1 = np.minimum(kwargs['locs'][0], kwargs['locs'][1]) | ||
loc2 = np.maximum(kwargs['locs'][0], kwargs['locs'][1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed with new method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes look good.
Job Test qsubs sawtooth on cf931e9 : invalidated by @mandd |
Test are green, checklist is good. PR can be merged. |
Pull Request Description
What issue does this change request address? (Use "#" before the issue to link it, i.e., #42.)
Close #1953
close #1959
close #1976
What are the significant changes in functionality due to this change request?
For Change Control Board: Change Request Review
The following review must be completed by an authorized member of the Change Control Board.
<internalParallel>
to True.raven/tests/framework/user_guide
andraven/docs/workshop
) have been changed, the associated documentation must be reviewed and assured the text matches the example.