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

Convert Dict{Any,Any} to Dict{Symbol,Float64} for pyrms compatibility + formatting #212

Merged
merged 2 commits into from
May 13, 2023

Conversation

hwpang
Copy link
Contributor

@hwpang hwpang commented May 13, 2023

This is needed for pyrms compatability, see ReactionMechanismGenerator/pyrms#6.
Python string gets converted to String and runs into "expected Symbol, got a value of type String" error.
I tried the trick mentioned in JuliaPy/pyjulia#156, but when the symbol is contained in a dictionary, it still gets converted to a String during python to Julia conversion.

@codecov
Copy link

codecov bot commented May 13, 2023

Codecov Report

Merging #212 (a3409bb) into main (78b0518) will decrease coverage by 0.03%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main     #212      +/-   ##
==========================================
- Coverage   49.83%   49.81%   -0.03%     
==========================================
  Files          31       31              
  Lines        7900     7904       +4     
==========================================
  Hits         3937     3937              
- Misses       3963     3967       +4     
Impacted Files Coverage Δ
src/ThreadedSensitivities.jl 71.21% <0.00%> (-4.60%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

# Convert Dict{Any,Any} to Dict{Symbol, Float64}
# Needed for pyrms compatability
# Python string gets converted to String and runs into expected Symbol, got a value of type String error
if odekwargs isa Dict{Any,Any}
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. I don't think these kwargs are all symbols mapped to floats so if someone tries to turn on an option that isn't a float I think this will crash
  2. Can we instead do this the julian way and write a Dict{Any,Any} specific method that just converts the dictionary to Dict{Symbol,Any} and then calls the main method (which I think would need made specific to Dict{Symbol,T})?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, I fixed it. I remove the Float64() and the type of the new dictionary should be inferred automatically.

Copy link
Contributor Author

@hwpang hwpang May 13, 2023

Choose a reason for hiding this comment

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

I tried using convert to convert Dict{Any,Any} to Dict{Symbol,Any}, but it doesn't work.

ERROR: MethodError: Cannot `convert` an object of type String to an object of type Symbol
Closest candidates are:
  convert(::Type{T}, ::T) where T at Base.jl:61
  Symbol(::String) at boot.jl:489
  Symbol(::AbstractString) at strings/basic.jl:228

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh wait I misunderstood what you meant. I will fix it now

Copy link
Collaborator

@mjohnson541 mjohnson541 left a comment

Choose a reason for hiding this comment

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

This looks good to me, but can you squash?

allow nonfloat64 value

Julian style

Allow different typing for odekwargs and senskwargs
@hwpang
Copy link
Contributor Author

hwpang commented May 13, 2023

@mjohnson541 Squashed the commits related to dictionary typing!

@hwpang hwpang requested a review from mjohnson541 May 13, 2023 21:30
@mjohnson541 mjohnson541 merged commit 0d8574c into main May 13, 2023
2 of 4 checks passed
@mjohnson541 mjohnson541 deleted the debug_threadedsa branch May 13, 2023 21:32
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.

None yet

2 participants