Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser: prefix functional primitives #212

Open
jbcaillau opened this issue Aug 5, 2024 · 6 comments
Open

Parser: prefix functional primitives #212

jbcaillau opened this issue Aug 5, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@jbcaillau
Copy link
Member

jbcaillau commented Aug 5, 2024

To avoid conflicts with other packages (ex. ExaModels), prefix before macro expansion: e.g. OptimalControl.constraint!(...)

@jbcaillau jbcaillau self-assigned this Aug 5, 2024
@ocots
Copy link
Member

ocots commented Aug 6, 2024

Attention, une fois le using OptimalControl fait, il faudra qualifier (ou préfixer) avec OptimalControl.

julia> using OptimalControl

julia> methods(CTBase.constraint!)
ERROR: UndefVarError: `CTBase` not defined
Stacktrace:
 [1] top-level scope
   @ REPL[2]:1

julia> methods(OptimalControl.constraint!)
# 1 method for generic function "constraint!" from CTBase:
 [1] constraint!(ocp::CTBase.OptimalControlModel{T, V}, type::Symbol; rg, f, lb, ub, label) where {T<:CTBase.TimeDependence, V<:CTBase.VariableDependence}
     @ ~/.julia/packages/CTBase/fDnnG/src/model.jl:550

julia> using CTBase
 │ Package CTBase not found, but a package named CTBase is available from a registry. 
 │ Install package?
 │   (@v1.10) pkg> add CTBase 
 └ (y/n/o) [y]: y
   Resolving package versions...
    Updating `~/.julia/environments/v1.10/Project.toml`
  [54762871] + CTBase v0.11.3
  No Changes to `~/.julia/environments/v1.10/Manifest.toml`

julia> methods(CTBase.constraint!)
# 1 method for generic function "constraint!" from CTBase:
 [1] constraint!(ocp::OptimalControlModel{T, V}, type::Symbol; rg, f, lb, ub, label) where {T<:TimeDependence, V<:VariableDependence}
     @ ~/.julia/packages/CTBase/fDnnG/src/model.jl:550

(@v1.10) pkg> rm CTBase
    Updating `~/.julia/environments/v1.10/Project.toml`
  [54762871] - CTBase v0.11.3
  No Changes to `~/.julia/environments/v1.10/Manifest.toml`

(@v1.10) pkg> 

@jbcaillau
Copy link
Member Author

@ocots right. prefix by OptimalControl (functional primitives are exported, until now).

@ocots ocots added the bug Something isn't working label Aug 22, 2024
@jbcaillau
Copy link
Member Author

@ocots second thoughts: what is the good solution here?

  • the user will use OptimalControl, not CTBase
  • we still need to be able to test the abstract inside CTBase (we could import OptimalControl for this, though...)

Bref. Is it OK to import CTBase from within OptimalControl so that the user generated code like CTBase.state!(...) is OK?

@ocots
Copy link
Member

ocots commented Aug 29, 2024

@ocots second thoughts: what is the good solution here?

  • the user will use OptimalControl, not CTBase
  • we still need to be able to test the abstract inside CTBase (we could import OptimalControl for this, though...)

Bref. Is it OK to import CTBase from within OptimalControl so that the user generated code like CTBase.state!(...) is OK?

This is the problem. I think that it won't work :-(

@jbcaillau
Copy link
Member Author

@ocots two ways?

  • generate code prefixed by OptimalControl, and import OptimalControl in CTBase.jl tests (remains internal), thanks to the fact that OptimalControl.jl reexports the requested getters
  • another way would be to prefix à la main the CTBase routines by creating aliases such as OptimalControl_time!(...), etc.

NB.

  • also update
    export __OCPModel # redirection to Model to avoid confusion with other Model functions from other packages. Due to @def macro
  • and probably the same thing in OptimalControl.jl

@ocots
Copy link
Member

ocots commented Aug 30, 2024

For OptimalControl.jl its here: https://github.com/control-toolbox/OptimalControl.jl/blob/main/src%2FOptimalControl.jl#L55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants