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: support components with fully-qualified names with @mtkmodel #2330

Conversation

thazhemadam
Copy link
Member

With the @named macro, we could use fully-qualified names for components (for instance, while importing components from the MTKStdLib). However, trying to do the same with @mtkmodel,

@mtkmodel Model begin
     @components begin
          resistor = ModelingToolkitStandardLibrary.Electrical.Resistor(R = 1)
          ...
     end
     ...
end

throws the following error.

ERROR: LoadError: MethodError: Cannot `convert` an object of type Expr to an object of type Symbol

Closest candidates are:
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:84
  Symbol(::Any...)
   @ Base strings/basic.jl:229

Fix this and support fully qualified names by considering the fully-qualifed name's Expr while parsing components.

@baggepinnen
Copy link
Contributor

closes #2289

@ven-k
Copy link
Member

ven-k commented Oct 27, 2023

Can you add a test?

@thazhemadam
Copy link
Member Author

Can you add a test?

Refactored the existing test code a bit to test this functionality as well in b1e7a0e.

@thazhemadam thazhemadam force-pushed the at/fix-model-parsing-mtkmodel-from-libs branch 2 times, most recently from dd965f6 to 0a6a4c8 Compare December 7, 2023 18:16
With the `@named` macro, we could use fully-qualified names for
components. However, trying to do the same with `@mtkmodel`,
```
@mtkmodel Model begin
     @components begin
          resistor = ModelingToolkitStandardLibrary.Electrical.Resistor(R = 1)
          ...
     end
     ...
end
```
throws the following error.
```
ERROR: LoadError: MethodError: Cannot `convert` an object of type Expr to an object of type Symbol

Closest candidates are:
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:84
  Symbol(::Any...)
   @ Base strings/basic.jl:229
```

Fix this and support fully qualified names by considering the
fully-qualifed name's Expr while parsing components.
Refactor out `Pin` and `Ground` into a mock-module `MyMockModule`, so
we can use `MyMockModule` and see if `@mtkmodel` works with
components that have fully-qualified names (i.e., `MyMockModule.Ground`).
@thazhemadam thazhemadam force-pushed the at/fix-model-parsing-mtkmodel-from-libs branch from 0a6a4c8 to d0b2e33 Compare December 7, 2023 18:20
@ChrisRackauckas ChrisRackauckas merged commit ce7eed0 into SciML:master Dec 7, 2023
18 of 20 checks passed
@thazhemadam thazhemadam deleted the at/fix-model-parsing-mtkmodel-from-libs branch December 8, 2023 06:50
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.

4 participants