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

[DEFECT] A lot of tests that uses constraint return Floats as return arg of function. #2053

Open
3 of 13 tasks
aalfonsi opened this issue Feb 3, 2023 · 3 comments
Open
3 of 13 tasks

Comments

@aalfonsi
Copy link
Collaborator

aalfonsi commented Feb 3, 2023

Thank you for the defect report

Defect Description

A lot of tests that uses constraint return Floats as return arg of function. E.g.:

def constraint(x,y):
  condition = 25.
  g = condition - ((x+5.)**2 + (y+5.)**2)
  return g

def constrain(self):
  """
    Constrain calls the constraint function.
    @ In, self, object, RAVEN container
    @ Out, explicitConstrain, float, positive if the constraint is satisfied
           and negative if violated.
  """
  explicitConstrain = constraint(self.x,self.y)
  return explicitConstrain

since in the code the Constraint are evaluated as boolean, this form of the constraint is Always true, making this test not testing what it wants to test (the constraint is never violated)

Steps to Reproduce

In RavenSampled.py

modify lines where the constraint functions are evaluated with a check for boolean (and run the test suite)

e.g.
from

okay = impConstraint.evaluate('implicitConstraint', inputs)

to

      okay = impConstraint.evaluate('implicitConstraint', inputs)
      try:
        okay = utils.interpretBoolean(okay)
      except:
       self.raiseAnError(RuntimeError,f'Implicit constraint "{impConstraint.name}" '
        'must return a boolean (boolean-like). Got "{okay}"!')

and

from

okay = constrain.evaluate('constrain', inputs)

to

      okay = constrain.evaluate('constrain', inputs)
      try:
        okay = utils.interpretBoolean(okay)
      except:
       self.raiseAnError(RuntimeError,f'Functional constraint "{constraint.name}" '
        'must return a boolean (boolean-like). Got "{okay}"!')

Expected Behavior

that the constrain is evaluated and that the code errors out if no boolean are returned

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?
@aalfonsi
Copy link
Collaborator Author

aalfonsi commented Feb 3, 2023

I checked the code again. The Genetic Algorithm overloads the constrain function and it expects a float as constrain (positive=> violated, negative not)... This is against what it is written in the manual.

@wangcj05
Copy link
Collaborator

@JunyungKim Could you update the manual to resolve the confusion? and add a check in the GA code to make sure the constrain returns are float instead of boolean?

@cbroman-usnctech
Copy link

Bumping this issue to keep it alive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants