-
Notifications
You must be signed in to change notification settings - Fork 259
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
I2338 if no explicit name given to a Problem, assign one automatically #2368
Conversation
…tests that have problem names in their errors and regex matching is needed
…uded the Problem name and so the asserts did not work any more. The Problem name changes because there is a global counter that is used to create the names and the counter does not get reset between tests
openmdao/core/problem.py
Outdated
@@ -138,8 +144,30 @@ def __init__(self, model=None, driver=None, comm=None, name=None, **options): | |||
""" | |||
Initialize attributes. | |||
""" | |||
global _problem_counter |
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.
Do you also need to global _problem_names
since you are appending to it?
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 point. Fixed.
openmdao/core/problem.py
Outdated
|
||
# Code to give non-empty names to Problems so that they can be | ||
# referenced from command line tools (e.g. check) that accept a Problem argument | ||
_problem_counter += 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.
Do we actually need _problem_counter
, if the number of problems is always the length of _problem_names
?
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.
Also a great point. Will modify code to do that
openmdao/core/problem.py
Outdated
else: | ||
raise ValueError(f"The problem name '{name}' already exists") | ||
else: # No name given: look for a name, of the form, 'problemN', that hasn't been used yet | ||
_name = f"problem{_problem_counter}" |
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 think I understand the logic here now. If we are the second problem, but "problem2" is taken, we just start with "problem2.1", and keep working until we find one that isn't taken.
…roblem_names instead
Summary
Currently, if the user doesn't provide an explicit name for a Problem, the name is the empty string. If a model has sub problems, and the user wants to use one of the command line tools that take problem name as an argument, there is no way to indicate which Problem to apply the command to.
This PR assigns default values to Problems that are explicitly given a name.
Related Issues
Backwards incompatibilities
None
New Dependencies
None