Skip to content

@def name … end true (trace mode) prints the parsed model twice #344

Description

@ocots

Context

Found while making OptimalControl's docs/src/modelling/abstract-syntax.md executable
(control-toolbox/OptimalControl.jl#913). The page has a !!! hint block demonstrating
trace mode; once executed, its output shows the parsed model twice.

Reproduce

using OptimalControl   # CTParser 0.9.4-beta, CTBase 0.30.2-beta, CTModels 0.19.2-beta

c(t) = 1.0

@def damped_integrator begin
    tf ∈ R, variable
    t ∈ [0, tf], time
    x = (q, v) ∈ R², state
    u ∈ R, control
    q̇ = v(t)
    v̇ = u(t) - c(t)
    ẋ(t) == [q̇, v̇]
    ∫(u(t)^2) → min
end true

Output (abridged — the whole block is printed twice, identical apart from gensym numbers):

variable: tf, dim: 1
time: t, initial time: 0, final time: var"tf##4005"[1]
state: x, dim: 2
control: u, dim: 1
alias: q̇ = (x[2])(t)
alias: v̇ = (var"u##4006"[1])(t) - c(t)
dynamics: ∂(x)(t) == [(x[2])(t), (var"u##4006"[1])(t) - c(t)]
objective (Lagrange): ∫((var"u##4006"[1])(t) ^ 2) → min
variable: tf, dim: 1
time: t, initial time: 0, final time: var"tf##4025"[1]
state: x, dim: 2
control: u, dim: 1
alias: q̇ = (x[2])(t)
alias: v̇ = (var"u##4029"[1])(t) - c(t)
dynamics: ∂(x)(t) == [(x[2])(t), (var"u##4029"[1])(t) - c(t)]
objective (Lagrange): ∫((var"u##4029"[1])(t) ^ 2) → min

Expected

The trace is printed once.

Impact

Cosmetic, but noisy in the docs and in interactive use — a reader could think the double
output signals a problem with their definition.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions