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

feat: implementation of new SymbolicIndexingInterface #2345

Merged
merged 1 commit into from
Dec 12, 2023

Conversation

AayushSabharwal
Copy link
Member

No description provided.

@AayushSabharwal AayushSabharwal marked this pull request as draft November 3, 2023 10:16
[getfield(sys, :iv)]
#Treat the result as a vector of symbols always
function SymbolicIndexingInterface.is_variable(sys::AbstractSystem, sym)
if unwrap(sym) isa Int # [x, 1] coerces 1 to a Num
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems really ugly.

Copy link
Member Author

@AayushSabharwal AayushSabharwal Nov 16, 2023

Choose a reason for hiding this comment

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

Yeah it is. It's the only way I could find to cover all the cases

  • we need the isa Int check because [x, 1] wraps 1 in a Num (e.g. sol(1.0, idxs=[1, x])
  • The next one is necessary since sol[x + y] is a possibility, and getname errors on x+y
  • The getname case is necessary for namespaced variables

Copy link
Contributor

Choose a reason for hiding this comment

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

what does unwrap do?

Copy link
Member Author

Choose a reason for hiding this comment

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

It gets the value inside a Num, which is usually either a SymbolicUtils.BasicSymbolic for symbolic variables or a number in the case of something like Num(1)

@@ -224,8 +224,12 @@ function SymbolicIndexingInterface.variable_symbols(sys::AbstractSystem)
end

function SymbolicIndexingInterface.is_parameter(sys::AbstractSystem, sym)
usym = unwrap(sym)
if unwrap(sym) isa Int
Copy link
Contributor

Choose a reason for hiding this comment

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

usym

return unwrap(sym) in 1:length(parameters(sys))
return usym in 1:length(parameters(sys))
end
if istree(usym) && operation(usym) != getindex
Copy link
Contributor

Choose a reason for hiding this comment

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

return !istree(usym) || operation(usym) == getindex

@AayushSabharwal AayushSabharwal marked this pull request as ready for review November 27, 2023 11:02
@ChrisRackauckas ChrisRackauckas merged commit 05710fe into SciML:master Dec 12, 2023
1 of 18 checks passed
@AayushSabharwal AayushSabharwal deleted the as/indexing-rework branch February 29, 2024 12:11
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.

3 participants