Skip to content

Conversation

@rafaqz
Copy link
Owner

@rafaqz rafaqz commented Jul 11, 2025

Closes #66

This PR adds Const wrappers to easily move between constant/forward parameters and variable parameters.

@bgroenks96 if you have some thoughts on this approach and if its useful that would help. Ive used all the param code in @eval loops to ensure Const and Param are essentially identical.

Needs tests

@rafaqz rafaqz requested a review from bgroenks96 July 11, 2025 01:02
@rafaqz
Copy link
Owner Author

rafaqz commented Jul 12, 2025

I forgot strip clashes with Base. Maybe we can just use Base.strip ?

But stripparams doesn't really make sense after this, or really even before as it strips the model too.

@bgroenks96
Copy link
Collaborator

bgroenks96 commented Jul 12, 2025

I forgot strip clashes with Base. Maybe we can just use Base.strip ?

I don't think it's a good idea to add dispatches to Base methods that are almost entirely unrelated. strip is not a generic method but is rather used specifically in the context of string processing. I would keep it as stripparams and maybe also stripconsts.

@bgroenks96
Copy link
Collaborator

Nice work, good to see this functionality finally added. In general, it looks good. I somehow feel like it's maybe not ideal for Const to have its own distinct type hierarchy via AbstractConst but I'm also not sure that there's any benefit to adding another level vs. just using Union types.

the `val` field, or a combination of `val` and `units` if a `units` field exists.
"""
function stripparams end
function strip end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not strip_params_and_consts or stripall?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes maybe stripall? - it actually unwraps any Model too so just params_and_consts still doesn't quite capture what it does. Just that strip would be really nice syntax, unfortunate that verb was wasted on string whitespace.

Currently I use stripparams everywhere but the name will be misleading after this, so I want it to break next release so it has to be changed.

allkeys = Tuple(union(map(keys, pars)...))
_expandkeys1(pars, Val{allkeys}())
end
Base.@assume_effects :foldable function _expandkeys1(pars, ::Val{Keys}) where Keys
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does @assume_effects actually do anything here? also does this lower bound us to Julia 1.11? I would be against that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it was only the annotations of code blocks that was added in 1.11... I don't remember, I haven't really used this macro.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its from 1.10. I think :foldable is so that map over Keys will always compile away.


params(m::AbstractModel) = params(parent(m))
stripparams(m::AbstractModel) = stripparams(parent(m))
strip(m::AbstractModel) = strip(parent(m))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in the main thread, I would suggest not doing this.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we just need a good verb to replace it

@rafaqz
Copy link
Owner Author

rafaqz commented Jul 13, 2025

You may be right maybe we should make AbstractParam and AbstractConst part of the same heirarchy ? I'm not sure what we would call the supertype.

@bgroenks96
Copy link
Collaborator

I think it's hard to come up with a common base type because constants are actually parameters... they are just parameters that we don't want to change.

I would also actually expect stripparams to remove Const wrappers for this reason. Maybe the solution is therefore for AbstractConst to be a subtype of AbstractParam but then make param types subtype AbstractVariable or AbstractVariableParam or something like that?

@bgroenks96
Copy link
Collaborator

I honestly cannot think of a use case where I would want to do stripparams but leave the constant wrappers in place. I would always want to remove both.

@rafaqz
Copy link
Owner Author

rafaqz commented Jul 15, 2025

Yes absolutely. So Param should actually be Var then constants and variables are all parameters.

@rafaqz
Copy link
Owner Author

rafaqz commented Jul 16, 2025

Seriously considering this change, we can make Param an alias for Var. It saves a few characters and keeps the language consistent

@bgroenks96
Copy link
Collaborator

So Param should actually be Var then constants and variables are all parameters.

Alternatively, Param <: AbstractVar <: AbstractParam and Const <: AbstractConst <: AbstractParam?

But I'm OK with both approaches, I think.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Const wrapper that acts just like a Param but explicitly isnt one

3 participants