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

Remove unused var opts in _setup_var_data, avoid potential memory waste #3086

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions openmdao/components/meta_model_structured_comp.py
Expand Up @@ -144,10 +144,6 @@ def _setup_var_data(self):
Instantiate surrogates for the output variables that use the default surrogate.
"""
interp_method = self.options['method']

opts = {}
if 'interp_options' in self.options:
opts = self.options['interp_options']
for name, train_data in self.training_outputs.items():
self.interps[name] = InterpND(method=interp_method,
points=self.inputs, values=train_data,
Expand Down
41 changes: 40 additions & 1 deletion openmdao/utils/units.py
Expand Up @@ -867,8 +867,47 @@ def _find_unit(unit, error=False):
PhysicalUnit
The actual unit object
"""
if isinstance(unit, str):
# Special handling for 's' and 'h' in the unit string
def simplify_time_units(unit_str):
# Split the unit string by multiplication and division
units = re.split(r'(\*|/)', unit_str)

# Create a dictionary to keep track of unit powers
unit_powers = {}
current_operation = '*'
for u in units:
if u in ['*', '/']:
current_operation = u
else:
# Adjust the power according to the operation
power = 1 if current_operation == '*' else -1
if u in unit_powers:
unit_powers[u] += power
else:
unit_powers[u] = power

# Simplify 's' and 'h' if both are present
if 's' in unit_powers and 'h' in unit_powers:
min_power = min(abs(unit_powers['s']), abs(unit_powers['h']))
unit_powers['s'] -= min_power * (1 if unit_powers['s'] > 0 else -1)
unit_powers['h'] -= min_power * (1 if unit_powers['h'] > 0 else -1)

# Reconstruct the unit string
new_units = []
for u, power in unit_powers.items():
if power != 0:
# Add the unit and its power (if not 1)
new_units.append(f"{u}^{power}" if power != 1 else u)

# Join the units with multiplication
simplified_unit_str = "*".join(new_units)

# Replace powers of -1 with division
simplified_unit_str = re.sub(r'\^(-1)', '/', simplified_unit_str)
return simplified_unit_str

if isinstance(unit, str):
unit = simplify_time_units(unit)
# Deal with 'as' for attoseconds
reg1 = re.compile(r'\bas\b')
unit = re.sub(reg1, 'as_', unit)
Expand Down