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

I2338 if no explicit name given to a Problem, assign one automatically #2368

Merged
merged 5 commits into from
Dec 7, 2021

Conversation

hschilling
Copy link
Member

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

…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
@coveralls
Copy link

coveralls commented Dec 6, 2021

Coverage Status

Coverage decreased (-0.4%) to 89.147% when pulling 5d8a867 on hschilling:I2338-problem-name-default into d01fd52 on OpenMDAO:master.

@@ -138,8 +144,30 @@ def __init__(self, model=None, driver=None, comm=None, name=None, **options):
"""
Initialize attributes.
"""
global _problem_counter
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Fixed.


# 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
Copy link
Member

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?

Copy link
Member Author

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

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}"
Copy link
Member

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.

@swryan swryan merged commit 1e71044 into OpenMDAO:master Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set Problem name automatically if user doesn't set it
5 participants