Skip to content

Commit

Permalink
Merge pull request #188 from moorepants/unique-h
Browse files Browse the repository at this point in the history
Use a more unique symbol for h internally, fixes #162.
  • Loading branch information
moorepants committed Jul 15, 2024
2 parents 436e1dc + 37caeec commit ca22e2a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion opty/direct_collocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ def __init__(self, equations_of_motion, state_symbols,
self.time_interval_symbol = node_time_interval
self._variable_duration = True
else:
self.time_interval_symbol = sm.Symbol('h', real=True)
self.time_interval_symbol = sm.Symbol('h_opty', real=True)
self._variable_duration = False
self.node_time_interval = node_time_interval

Expand Down
24 changes: 15 additions & 9 deletions opty/tests/test_direct_collocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,30 @@ def test_pendulum():
interval_value = duration / (num_nodes - 1)

# Symbolic equations of motion
I, m, g, d, t = sym.symbols('Ix, m, g, d, t')
# NOTE : h, real=True is used as a regression test for
# https://github.com/csu-hmc/opty/issues/162
# NOTE : Ix is used because NumPy 2.0 uses I in the C API.
I, m, g, h, t = sym.symbols('Ix, m, g, h, t', real=True)
theta, omega, T = sym.symbols('theta, omega, T', cls=sym.Function)

state_symbols = (theta(t), omega(t))
specified_symbols = (T(t),)

eom = sym.Matrix([theta(t).diff() - omega(t),
I*omega(t).diff() + m*g*d*sym.sin(theta(t)) - T(t)])
I*omega(t).diff() + m*g*h*sym.sin(theta(t)) - T(t)])

# Specify the known system parameters.
par_map = OrderedDict()
par_map[I] = 1.0
par_map[m] = 1.0
par_map[g] = 9.81
par_map[d] = 1.0
par_map[h] = 1.0

# Specify the objective function and it's gradient.
obj_func = sym.Integral(T(t)**2, t)
obj, obj_grad = create_objective_function(obj_func, state_symbols,
specified_symbols, tuple(),
num_nodes,
node_time_interval=interval_value)
obj, obj_grad = create_objective_function(
obj_func, state_symbols, specified_symbols, tuple(), num_nodes,
node_time_interval=interval_value, time_symbol=t)

# Specify the symbolic instance constraints, i.e. initial and end
# conditions.
Expand All @@ -55,6 +57,7 @@ def test_pendulum():
Problem(obj, obj_grad, eom, state_symbols, num_nodes, interval_value,
known_parameter_map=par_map,
instance_constraints=instance_constraints,
time_symbol=t,
bounds={T(t): (-2.0, 2.0)},
show_compile_output=True)

Expand All @@ -77,6 +80,7 @@ def test_Problem():
state_symbols,
2,
interval_value,
time_symbol=t,
bounds={x: (-10.0, 10.0),
f: (-8.0, 8.0),
m: (-1.0, 1.0),
Expand Down Expand Up @@ -130,7 +134,8 @@ def setup_method(self):
num_collocation_nodes=4,
node_time_interval=self.interval_value,
known_parameter_map=par_map,
known_trajectory_map=traj_map)
known_trajectory_map=traj_map,
time_symbol=t)

def test_init(self):

Expand Down Expand Up @@ -863,7 +868,8 @@ def setup_method(self):
num_collocation_nodes=4,
node_time_interval=self.interval_value,
known_parameter_map=par_map,
instance_constraints=instance_constraints)
instance_constraints=instance_constraints,
time_symbol=t)

def test_init(self):

Expand Down

0 comments on commit ca22e2a

Please sign in to comment.