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

Allow parameter shape to be given as None, rather than just _unspecified #970

Merged
merged 3 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _make_problem(self, tx):
phase.add_boundary_constraint('x', loc='final', equals=10.0)
phase.add_path_constraint('pc = y-x/2-1', lower=0.0)

phase.add_parameter('g', opt=False, units='m/s**2', val=9.80665, include_timeseries=True)
phase.add_parameter('g', opt=False, units='m/s**2', val=9.80665, shape=None, include_timeseries=True)

phase.add_objective('time_phase', loc='final', scaler=10)

Expand Down
6 changes: 3 additions & 3 deletions dymos/phase/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

import openmdao.api as om
from ..utils.misc import _unspecified
from ..utils.misc import _unspecified, _none_or_unspecified


class ControlOptionsDictionary(om.OptionsDictionary):
Expand Down Expand Up @@ -224,7 +224,7 @@ def check_valid_shape(name, value):
Shape to check, should be a Iterable, Number, list, or tuple.
"""
if name == 'shape':
if value is not _unspecified and not isinstance(value, (Iterable, Number, list, tuple)):
if value not in _none_or_unspecified and not isinstance(value, (Iterable, Number, list, tuple)):
raise ValueError(f"Option '{name}' with value {value} is not valid.")


Expand Down Expand Up @@ -284,7 +284,7 @@ def __init__(self, read_only=False):
self.declare(name='val', types=(Iterable, np.ndarray, Number), default=0.0,
desc='The default value of the parameter in the phase.')

self.declare(name='shape', check_valid=check_valid_shape, default=_unspecified,
self.declare(name='shape', check_valid=check_valid_shape, default=_unspecified, allow_none=True,
desc='The shape of the parameter.')

self.declare(name='lower', types=(Iterable, Number), default=None,
Expand Down