Closed Peter230655 closed 4 weeks ago
Simpler example that raises the error:
from collections import OrderedDict
import numpy as np
import sympy as sym
import matplotlib.pyplot as plt
from opty.direct_collocation import Problem
duration = 1.0
num_nodes = 100
interval = duration / (num_nodes - 1)
mu, p, t = sym.symbols('mu, p, t')
y1, y2, T = sym.symbols('y1, y2, T', cls=sym.Function)
state_symbols = (y1(t), y2(t))
constant_symbols = (mu, p)
eom = sym.Matrix([y1(t).diff(t) - y2(t),
y2(t).diff(t) - mu**2 * y1(t) + (mu**2 + p**2) *
sym.sin(p * T(t))])
par_map = OrderedDict()
par_map[mu] = 60.0
time = np.linspace(0.0, 1.0, num_nodes)
y1_m = np.sin(np.pi * time) + np.random.normal(scale=0.05, size=len(time))
y2_m = np.pi * np.cos(np.pi * time) + np.random.normal(scale=0.05,
size=len(time))
def obj(free):
return interval * np.sum((y1_m - free[:num_nodes])**2)
def obj_grad(free):
grad = np.zeros_like(free)
grad[:num_nodes] = 2.0 * interval * (free[:num_nodes] - y1_m)
return grad
instance_constraints = (y1(0.0), y2(0.0) - np.pi)
prob = Problem(obj, obj_grad,
eom, state_symbols,
num_nodes, interval,
known_parameter_map=par_map,
known_trajectory_map={T(t): time},
instance_constraints=instance_constraints,
time_symbol=t,
integration_method='midpoint')
initial_guess = np.random.randn(prob.num_free)
prob.plot_trajectories(initial_guess)
I tried an optimization without any unknown trajectories, but only an unknown symbol to be minimized. I got an error from plot_trajectories, see below.
I appended the program below the error message.
this is the program: ( note, it does yet not work in the sense, that opty does not find a solution)