brocksam / pycollo

General-purpose optimal control, trajectory optimisation and parameter optimisation using direct collocation
https://brocksam.github.io/pycollo/
MIT License
8 stars 3 forks source link

Option to assign numerical value to parameter_variables #75

Open jtheinen opened 1 year ago

jtheinen commented 1 year ago

For the sake of writing the code logically within pycollo, would it be possible to assign numerical values to parameter_variables? Such that the user throw in all single value parameters (optimized or not) in the description of the OCP.

Whenever the bound would be set to a single value, the parameter variable should be treated as a variable that has a numerical value assigned through aux data.

Whenever the bound is set to a range [0,1], the parameter variable will be optimized. Just like how an initial value would be handled (either bound or single value)

Whenever auxiliary data is assigned, parameter variables will be treated as a constant numerical value.

What happens now when parameter variable is assigned with aux data:

Minimal Reproduction

problem = pycollo.OptimalControlProblem( name="Simple Block Slide", parameter_variables= (m,mu,g) )

problem.auxiliary_data = { m: 1, mu: 1, g: 1 }

(same error output when removing following two lines) problem.bounds.parameter_variables = [[1,1.1], [1,1.1], [1,1.1]] problem.guess.parameter_variables = [1, 1, 1]

Solution

remove "parameter_variables= (m,mu,g)"

Error msg

https://github.com/brocksam/pycollo/blob/6e01d6c6300856408c942830cf78b4f2ea3fc049/pycollo/optimal_control_problem.py#L334 https://github.com/brocksam/pycollo/blob/6e01d6c6300856408c942830cf78b4f2ea3fc049/pycollo/backend.py#L76 https://github.com/brocksam/pycollo/blob/6e01d6c6300856408c942830cf78b4f2ea3fc049/pycollo/backend.py#L308 https://github.com/brocksam/pycollo/blob/6e01d6c6300856408c942830cf78b4f2ea3fc049/pycollo/backend.py#L547 UnboundLocalError: cannot access local variable 'backend_sym' where it is not associated with a value