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

Refactored the Radau transcription to avoid the use of StateIndependentsComp #1117

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3504d68
Added RadauNew transcription which is imported into dymos.transcripti…
robfalck Oct 4, 2024
c542feb
Missed a few imports in __init__
robfalck Oct 4, 2024
d100b60
remove unfinished gausslobatto refactor from this PR
robfalck Oct 4, 2024
d6b5c78
renamed BirkhoffCollocationComp to BirkhoffDefectComp
robfalck Oct 4, 2024
0aa416d
joss tests passing
robfalck Oct 5, 2024
14d3132
Renamed components.
robfalck Oct 5, 2024
1ff08a2
radau_iter_group test passes for both vectorized and scalar ODE
robfalck Oct 10, 2024
8360471
progress on radau_new...isolated iter group works with vectorized sta…
robfalck Oct 15, 2024
e8a4958
Removed some outdated docstrings
robfalck Oct 24, 2024
ab39055
more work on radau iter group
robfalck Oct 24, 2024
9a20011
Merge branch 'master' of https://github.com/OpenMDAO/dymos into radau…
robfalck Nov 1, 2024
85b9e7c
Tests passing for Radau with compressed transcription enabled.
robfalck Nov 1, 2024
0e36491
RadauNew works with change to AutoIVC promotion, but will not run cuu…
robfalck Nov 4, 2024
b50c4e4
allow dymos to connect phase final time (t_final) to targets in the O…
robfalck Nov 4, 2024
256527d
Added missing radau boundary group.
robfalck Nov 6, 2024
ef123b8
Merge branch 't_final_targets' into radau_refactor
robfalck Nov 6, 2024
19aee52
added t_final_targets to time options dictionary
robfalck Nov 6, 2024
1b705c2
Merge branch 't_final_targets' into radau_refactor
robfalck Nov 6, 2024
d25c0cf
working on updates to control interp to remove ContinuityComp
robfalck Nov 8, 2024
f63d00b
Merge branch 'master' of https://github.com/OpenMDAO/dymos into radau…
robfalck Nov 15, 2024
6b9a34f
Added a new ControlComp that computes control continuity defects. Rad…
robfalck Nov 16, 2024
ce649d8
Birkhoff now uses input resids comp. Fixed issues with RadauNew when …
robfalck Nov 18, 2024
06b5ea1
Merge branch 'master' of https://github.com/OpenMDAO/dymos into radau…
robfalck Nov 18, 2024
ec57b5d
control_comp now handles constraints on control continuity and rate c…
robfalck Nov 18, 2024
1b597b7
control comp cleanup
robfalck Nov 18, 2024
287dd7c
use endpoint component for initial and final boundary constraints in …
robfalck Nov 19, 2024
48536cf
Merge branch 'master' of https://github.com/OpenMDAO/dymos into radau…
robfalck Dec 10, 2024
4fc3050
Fixed an issue with the new ControlComp and Radau with compressed tra…
robfalck Dec 10, 2024
05e455c
Fixed an issue with time promotion in the new Radau implementation.
robfalck Dec 10, 2024
dddce58
cleanup
robfalck Dec 11, 2024
8bada94
Fixed BenchmarkRacecar to use set_xxx_val
robfalck Jan 8, 2025
9587358
Merge branch 'master' of https://github.com/OpenMDAO/dymos into radau…
robfalck Jan 8, 2025
b3485cc
Removed old test that does not apply to new Radau method
robfalck Jan 8, 2025
81011ba
Try installing lapack before pyoptsparse. Temporarily disabled parall…
robfalck Jan 8, 2025
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
2 changes: 1 addition & 1 deletion dymos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


from .phase import Phase, AnalyticPhase
from .transcriptions import GaussLobatto, Radau, ExplicitShooting, Analytic, Birkhoff
from .transcriptions import GaussLobatto, Radau, ExplicitShooting, Analytic, Birkhoff, RadauDeprecated
from .transcriptions.grid_data import GaussLobattoGrid, RadauGrid, UniformGrid, BirkhoffGrid
from .trajectory.trajectory import Trajectory
from .run_problem import run_problem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_brachistochrone_static_gravity(self):
fix_initial=True, fix_final=False, solve_segments=False)

phase.add_control('theta', targets=['theta'],
continuity=True, rate_continuity=True,
continuity=False, rate_continuity=False,
units='deg', lower=0.01, upper=179.9)

phase.add_parameter('g', targets=['g'], static_target=True, opt=False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def brachistochrone_min_time(transcription='gauss-lobatto', num_segments=8, tran
# can't fix final position if you're solving the segments

phase.add_state('pos', fix_initial=True, fix_final=fix_final,
solve_segments=solve_segments, ref=[1, 1])
solve_segments=solve_segments)
#
phase.add_state('v', fix_initial=True, fix_final=False, solve_segments=solve_segments)
#
Expand All @@ -66,7 +66,7 @@ def brachistochrone_min_time(transcription='gauss-lobatto', num_segments=8, tran
# Minimize time at the end of the phase
phase.add_objective('time', loc='final', scaler=10)

p.model.linear_solver = om.DirectSolver()
p.model.linear_solver = om.DirectSolver(assemble_jac=False)
Copy link
Member

Choose a reason for hiding this comment

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

Does this test have problems with assembled-jac now?

p.setup(check=True, force_alloc_complex=force_alloc_complex)

phase.set_time_val(initial=0.0, duration=1.8016)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import unittest

from numpy.testing import assert_almost_equal

import dymos.examples.brachistochrone.test.ex_brachistochrone as ex_brachistochrone
Expand All @@ -9,7 +10,7 @@
OPT, OPTIMIZER = set_pyoptsparse_opt('SNOPT', fallback=True)


@use_tempdirs
# @use_tempdirs
Copy link
Member

@Kenneth-T-Moore Kenneth-T-Moore Nov 15, 2024

Choose a reason for hiding this comment

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

Probably want to uncomment here and other places.

class TestBrachistochroneExample(unittest.TestCase):

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
from openmdao.utils.general_utils import set_pyoptsparse_opt, printoptions
from openmdao.utils.testing_utils import use_tempdirs

import dymos
import dymos.examples.brachistochrone.test.ex_brachistochrone_vector_states as ex_brachistochrone_vs
from dymos.utils.testing_utils import assert_check_partials

OPT, OPTIMIZER = set_pyoptsparse_opt('SNOPT')


@use_tempdirs
# @use_tempdirs
class TestBrachistochroneVectorStatesExample(unittest.TestCase):

def assert_results(self, p):
Expand Down Expand Up @@ -45,36 +46,45 @@ def assert_results(self, p):

def assert_partials(self, p):
with printoptions(linewidth=1024, edgeitems=100):
cpd = p.check_partials(method='cs', compact_print=True)
cpd = p.check_partials(method='cs', compact_print=True,
show_only_incorrect=True)#, out_stream=None)
assert_check_partials(cpd)
# p.check_totals(method='cs', compact_print=False)

def test_ex_brachistochrone_vs_radau_compressed(self):
ex_brachistochrone_vs.SHOW_PLOTS = True
p = ex_brachistochrone_vs.brachistochrone_min_time(transcription='radau-ps',
compressed=True,
force_alloc_complex=True,
run_driver=False)
run_driver=True)
p.run_driver()
self.assert_partials(p)

def test_ex_brachistochrone_vs_radau_uncompressed(self):
ex_brachistochrone_vs.SHOW_PLOTS = True
p = ex_brachistochrone_vs.brachistochrone_min_time(transcription='radau-ps',
compressed=False,
force_alloc_complex=True,
run_driver=True)
self.assert_results(p)
self.assert_partials(p)
with dymos.options.temporary(include_check_partials=True):
p = ex_brachistochrone_vs.brachistochrone_min_time(transcription='radau-ps',
num_segments=3,
transcription_order=3,
compressed=False,
force_alloc_complex=True,
dynamic_simul_derivs=False,
run_driver=False)
# self.assert_results(p)
import numpy as np
with np.printoptions(linewidth=100_000, edgeitems=100_000):
self.assert_partials(p)

def test_ex_brachistochrone_vs_gl_compressed(self):
ex_brachistochrone_vs.SHOW_PLOTS = True
p = ex_brachistochrone_vs.brachistochrone_min_time(transcription='gauss-lobatto',
compressed=True,
force_alloc_complex=True,
run_driver=True)

self.assert_results(p)
self.assert_partials(p)
with dymos.options.temporary(include_check_partials=True):
p = ex_brachistochrone_vs.brachistochrone_min_time(transcription='gauss-lobatto',
compressed=True,
force_alloc_complex=True,
run_driver=True)

self.assert_results(p)
self.assert_partials(p)

def test_ex_brachistochrone_vs_gl_uncompressed(self):
ex_brachistochrone_vs.SHOW_PLOTS = True
Expand Down
4 changes: 2 additions & 2 deletions dymos/phase/analytic_phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def add_control(self, name, units=_unspecified, desc=_unspecified, opt=_unspecif
This option is invalid if opt=False.
targets : Sequence of str or None
Targets in the ODE to which this control is connected.
In the future, if left _unspecified (the default), the phase control will try to connect to an ODE input
If left _unspecified (the default), the phase control will try to connect to an ODE input
of the same name. Set targets to None to prevent this.
rate_targets : Sequence of str or None
The targets in the ODE to which the control rate is connected.
Expand Down Expand Up @@ -212,7 +212,7 @@ def set_control_options(self, name, units=_unspecified, desc=_unspecified, opt=_
This option is invalid if opt=False.
targets : Sequence of str or None
Targets in the ODE to which this control is connected.
In the future, if left _unspecified (the default), the phase control will try to connect to an ODE input
If left _unspecified (the default), the phase control will try to connect to an ODE input
of the same name. Set targets to None to prevent this.
rate_targets : Sequence of str or None
The targets in the ODE to which the control rate is connected.
Expand Down
12 changes: 6 additions & 6 deletions dymos/phase/phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def add_state(self, name, units=_unspecified, shape=_unspecified,
targets : str or Sequence of str
The path to the targets of the state variable in the ODE system. If given
this will override the value given by the @declare_state decorator on the ODE.
In the future, if left _unspecified (the default), the phase variable will try to connect to an ODE input
If left _unspecified (the default), the phase variable will try to connect to an ODE input
of the same name. Set targets to None to prevent this.
val : ndarray
The default value of the state at the state discretization nodes of the phase.
Expand Down Expand Up @@ -353,7 +353,7 @@ def set_state_options(self, name, units=_unspecified, shape=_unspecified,
targets : str or Sequence of str
The path to the targets of the state variable in the ODE system. If given
this will override the value given by the @declare_state decorator on the ODE.
In the future, if left _unspecified (the default), the phase variable will try to connect to an ODE input
If left _unspecified (the default), the phase variable will try to connect to an ODE input
of the same name. Set targets to None to prevent this.
val : ndarray
The default value of the state at the state discretization nodes of the phase.
Expand Down Expand Up @@ -556,7 +556,7 @@ def add_control(self, name, order=_unspecified, units=_unspecified, desc=_unspec
This option is invalid if opt=False.
targets : Sequence of str or None
Targets in the ODE to which this control is connected.
In the future, if left _unspecified (the default), the phase control will try to connect to an ODE input
If left _unspecified (the default), the phase control will try to connect to an ODE input
of the same name. Set targets to None to prevent this.
rate_targets : Sequence of str or None
The targets in the ODE to which the control rate is connected.
Expand Down Expand Up @@ -677,7 +677,7 @@ def set_control_options(self, name, order=_unspecified, units=_unspecified, desc
This option is invalid if opt=False.
targets : Sequence of str or None
Targets in the ODE to which this control is connected.
In the future, if left _unspecified (the default), the phase control will try to connect to an ODE input
If left _unspecified (the default), the phase control will try to connect to an ODE input
of the same name. Set targets to None to prevent this.
rate_targets : Sequence of str or None
The targets in the ODE to which the control rate is connected.
Expand Down Expand Up @@ -1077,7 +1077,7 @@ def add_parameter(self, name, val=_unspecified, units=_unspecified, opt=False,
The unit-reference value of the parameter for the optimizer.
targets : Sequence of str or None
Targets in the ODE to which this parameter is connected.
In the future, if left _unspecified (the default), the phase parameter will try to connect to an ODE input
If left _unspecified (the default), the phase parameter will try to connect to an ODE input
of the same name. Set targets to None to prevent this.
shape : Sequence of int
The shape of the parameter.
Expand Down Expand Up @@ -1147,7 +1147,7 @@ def set_parameter_options(self, name, val=_unspecified, units=_unspecified, opt=
The unit-reference value of the parameter for the optimizer.
targets : Sequence of str or None
Targets in the ODE to which this parameter is connected.
In the future, if left _unspecified (the default), the phase parameter will try to connect to an ODE input
If left _unspecified (the default), the phase parameter will try to connect to an ODE input
of the same name. Set targets to None to prevent this.
shape : Sequence of int
The shape of the parameter.
Expand Down
3 changes: 2 additions & 1 deletion dymos/transcriptions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .analytic.analytic import Analytic
from .explicit_shooting import ExplicitShooting
from .pseudospectral.gauss_lobatto import GaussLobatto
from .pseudospectral.radau_pseudospectral import Radau
from .pseudospectral.radau_pseudospectral import Radau as RadauDeprecated
Copy link
Member

@Kenneth-T-Moore Kenneth-T-Moore Nov 15, 2024

Choose a reason for hiding this comment

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

I wonder if it would be better to rename the module to radau_deprecated, just to alleviate confusion when viewing the file in the future. Then radau_new can become radau_pseudospectral. Otherwise, kind of mixing paradigms here.

from .pseudospectral.birkhoff import Birkhoff
from .pseudospectral.radau_new import RadauNew as Radau
2 changes: 0 additions & 2 deletions dymos/transcriptions/pseudospectral/birkhoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ def configure_time(self, phase):
src_idxs = self.grid_data.subset_node_indices['all']
phase.connect(name, [f'ode_all.{t}' for t in targets], src_indices=src_idxs,
flat_src_indices=True)
src_idxs = om.slicer[[0, -1], ...]
phase.connect(name, [f'boundary_vals.{t}' for t in targets], src_indices=src_idxs)

for name, targets in [('t_initial', options['t_initial_targets']),
('t_duration', options['t_duration_targets'])]:
Expand Down
4 changes: 3 additions & 1 deletion dymos/transcriptions/pseudospectral/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from .state_independents import StateIndependentsComp
from .control_endpoint_defect_comp import ControlEndpointDefectComp
from .gauss_lobatto_interleave_comp import GaussLobattoInterleaveComp
from .birkhoff_collocation_comp import BirkhoffCollocationComp
from .birkhoff_defect_comp import BirkhoffDefectComp
from .birkhoff_iter_group import BirkhoffIterGroup
from .birkhoff_boundary_group import BirkhoffBoundaryGroup
from .radau_iter_group import RadauIterGroup
from .radau_boundary_group import RadauBoundaryGroup
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def compute(self, inputs, outputs, discrete_inputs=None, discrete_outputs=None):

class BirkhoffBoundaryGroup(om.Group):
"""
Class definition for the BirkhoffBoundaryEvalGroup.
Class definition for the BirkhoffBoundaryGroup.

This group accepts values for initial and final times, states, controls, and parameters
and evaluates the ODE with those in order to compute the boundary values and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
from dymos.utils.birkhoff import birkhoff_matrix


class BirkhoffCollocationComp(om.ExplicitComponent):
class BirkhoffDefectComp(om.ExplicitComponent):
"""
Class definition for the BirkhoffCollocationComp.
Class definition for the BirkhoffDefectComp.

BirkhoffCollocationComp computes the generalized defects of a segment for implicit collocation.
BirkhoffDefectComp computes the generalized defects of a segment for implicit collocation.
There are four defects to be evaluated; state, state rate, initial state, and final state.
The state defect is the difference between the state value design variables and the state rate
design variables.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np
import openmdao.api as om

from .birkhoff_collocation_comp import BirkhoffCollocationComp
from .birkhoff_state_resid_comp import BirkhoffStateResidComp
from .birkhoff_defect_comp import BirkhoffDefectComp
from .input_resids_comp import InputResidsComp

from ...grid_data import GridData
from ....phase.options import TimeOptionsDictionary
Expand Down Expand Up @@ -53,13 +53,13 @@ def setup(self):
self.add_subsystem('ode_all', subsys=ode_class(num_nodes=nn, **ode_init_kwargs))

self.add_subsystem('collocation_comp',
subsys=BirkhoffCollocationComp(grid_data=gd,
subsys=BirkhoffDefectComp(grid_data=gd,
state_options=state_options,
time_units=time_options['units']),
promotes_inputs=['*'], promotes_outputs=['*'])

if any([opts['solve_segments'] in ('forward', 'backward') for opts in state_options.values()]):
self.add_subsystem('states_balance_comp', subsys=BirkhoffStateResidComp(),
self.add_subsystem('states_balance_comp', subsys=InputResidsComp(),
promotes_inputs=['*'], promotes_outputs=['*'])

def _configure_desvars(self, name, options):
Expand Down

This file was deleted.

Loading
Loading