Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ All notable changes to CTParser will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### 🐛 Bug Fixes

- **Trace mode (`@def name … end true`) no longer prints the parsed model twice** ([#344](https://github.com/control-toolbox/CTParser.jl/issues/344)). When the `:exa` backend is active, `def_fun` parses the definition a second time to build the ExaModels artifact; that second pass was inheriting the `log` flag and re-emitting the whole trace. It now runs with `log=false`.

## [0.9.4-beta] - 2026-08-30

### ✅ Compatibility
Expand Down
4 changes: 3 additions & 1 deletion src/onepass.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,9 @@ function def_fun(e; log=false)
end

if is_active_backend(:exa)
build_exa = def_exa(e; log=log)
# log=false: the :fun pass above already emitted the trace; a second one here
# would print the whole parsed model twice (#344)
build_exa = def_exa(e; log=false)
code = concat(code, :($pref.build($p_ocp; build_examodel=($build_exa))))
else
code = concat(code, :($pref.build($p_ocp)))
Expand Down
27 changes: 27 additions & 0 deletions test/test_onepass_fun.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,33 @@ function test_onepass_fun()
end true
@test initial_time(o) == 0
@test final_time(o, [0, 2]) == 2

# trace mode prints the parsed model once, not once per active backend (#344)
was_exa = is_active_backend(:exa)
was_exa || activate_backend(:exa)
try
trace = mktemp() do path, io
redirect_stdout(io) do
CTParser.def_fun(
:(begin
tf ∈ R, variable
t ∈ [0, tf], time
x = (q, v) ∈ R², state
u ∈ R, control
ẋ(t) == [v(t), u(t)]
∫(u(t)^2) → min
end);
log=true,
)
end
flush(io)
read(path, String)
end
@test count("objective (Lagrange)", trace) == 1
@test count("state: x, dim: 2", trace) == 1
finally
was_exa || deactivate_backend(:exa)
end
end

# ---------------------------------------------------------------
Expand Down
Loading