-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add Julia support to gprc4bmi #144
Conversation
To resolve: warning The version of Java (11.0.3) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
This reverts commit 4f1de4e.
grpc4bmi/bmi_julia_model.py
Outdated
Args: | ||
package: Name of package to install. | ||
""" | ||
jl.Pkg.add(package) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specific URLs and git branches can also be installed. See https://pkgdocs.julialang.org/v1/api/#Package-API-Reference
import Pkg
Pkg.add(name="Wflow", rev="BMI")
or
Pkg.add(url="https://github.com/JuliaLang/Example.jl", rev="master")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed install method and use jl.Pkg.add()
direct;ly.
Calling a bmi function in julia via a grpc python server from a grpc client causes the process to use 100% cpu and not return a response. Seems grpc and juliacall can not live together. |
Need to add handle_julia_exception from https://blog.esciencecenter.nl/10-examples-of-embedding-julia-in-c-c-66282477e62c to get better error Got error: 1.4142135623730951 [7] signal (11.1): Segmentation fault in expression starting at none:0 jl_lookup_generic_ at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2819 [inlined] ijl_apply_generic at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2936 jl_apply at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/julia.h:1880 [inlined] ijl_call1 at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/jlapi.c:230 main at /usr/local/bin/run_bmi_server (unknown line) __libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line) _start at /usr/local/bin/run_bmi_server (unknown line) Allocations: 2060272 (Pool: 2059240; Big: 1032); GC: 3 Segmentation fault
Now trying to write c wrapper around julia in https://github.com/eWaterCycle/grpc4bmi/tree/julia/test/heat-images/c-julia |
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Got it to work until it segfaults somewhere as seen in https://github.com/eWaterCycle/grpc4bmi/blob/julia/test/heat-images/c-julia/demo.ipynb. With following server output:
I think this has to do with grpc creating threads for each incoming request. If I tried to limit max threads to 2, but segfaults still happen, but less frequently. https://scientificcoder.com/extreme-multi-threading-c-and-julia-19-integration looks like what I need to use. I do not know how to make it run without segfaulting, maybe @abelsiqueira or @goord know a way? |
I can reproduce the error :) I tried some things for a couple of hours, but I've made no progress. Using
which means nothing to me. The other functions Then I tried PackageCompiler, but you need to define the functions as Overall, I don't have enough knowledge of the project, nor of C++, nor of Julia+C++ integration, nor threads, so at this point I am just randomly testing things. Let me know if you need a longer consultation to try to make this work, and sorry for not being more helpful. |
Thanks for looking into this. We will go for wrapping the Julia model directly in Python with juliacall without grpc in-between the Python client and model. @BSchilperoort you already have this working in https://github.com/eWaterCycle/pywflow, but it would be nice if BmiJulia class could be used there. |
I modified |
Hmm test gets stuck in test_subproc |
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shame that Julia doesn't play nice with gRPC 😞
The local model works well. I am able to use it for Wflow.jl, and haven't run into any issues anymore (except the init thing, see the comment).
jl.seval("import " + package4implementation) | ||
model = jl.seval(model_name) | ||
implementation = jl.seval(implementation_name) | ||
return BmiJulia(model, implementation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One problem with this: you cannot add this to an eWaterCycle LocalModel. That requires a callable class, i.e. one that is not initialized yet.
For Wflow.jl I had to do the following to make it work with eWaterCycle:
class WflowBmi(BmiJulia):
def __init__(self):
m = self.from_name("Wflow.Model", implementation_name="Wflow.BMI")
super().__init__(m.model, m.implementation)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, it made sense for grpc server from cli, but not as a super class.
Created #145
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing as it does not work, do we want to leave these files here? Do we want to attempt this again later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to keep it because it was a lot of work, and its already located in a nook in the repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking at it.
jl.seval("import " + package4implementation) | ||
model = jl.seval(model_name) | ||
implementation = jl.seval(implementation_name) | ||
return BmiJulia(model, implementation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, it made sense for grpc server from cli, but not as a super class.
Created #145
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to keep it because it was a lot of work, and its already located in a nook in the repo.
Refs #101