-
Notifications
You must be signed in to change notification settings - Fork 323
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
Investigate usage of Python libraries #7388
Comments
Per @wdanilo request I did an experiment. With 2023.2.1-nightly.2023.8.28 version I can run: from Standard.Base import all
foreign python random_array s = """
import numpy
return numpy.random.normal(size=s)
main =
IO.println "Running main..."
arr = random_array 100
IO.println "Got an array with length: "+arr.length.to_text
IO.println "Array: "+arr.to_text
IO.println "Done" and I get following output:
So yes, we can use |
To reproduce the above experiment, we need to create a virtual environment for Graal Python:
Then we need to follow instructions on using venv inside of Java programs which leads to following diff: diff --git engine/runner/src/main/scala/org/enso/runner/ContextFactory.scala engine/runner/src/main/scala/org/enso/runner/ContextFactory.s
cala
index 0faff393e0..30c757b4f2 100644
--- engine/runner/src/main/scala/org/enso/runner/ContextFactory.scala
+++ engine/runner/src/main/scala/org/enso/runner/ContextFactory.scala
@@ -81,6 +81,7 @@ class ContextFactory {
new DebuggerSessionManagerEndpoint(repl, peer)
} else null
}
+ .option("python.Executable", "/tmp/gpy/bin/graalpy")
.option(
RuntimeOptions.LOG_LEVEL,
JavaLoggingLogHandler.getJavaLogLevelFor(logLevel).getName
diff --git engine/runtime-language-epb/src/main/java/org/enso/interpreter/epb/node/ForeignEvalNode.java engine/runtime-language-epb/src/ma
in/java/org/enso/interpreter/epb/node/ForeignEvalNode.java
index 3e8bef5ca7..67f4b276c5 100644
--- engine/runtime-language-epb/src/main/java/org/enso/interpreter/epb/node/ForeignEvalNode.java
+++ engine/runtime-language-epb/src/main/java/org/enso/interpreter/epb/node/ForeignEvalNode.java
@@ -147,6 +149,11 @@ public class ForeignEvalNode extends RootNode {
Source source =
Source.newBuilder(code.getLanguage().getTruffleId(), head + indentLines, "").build();
EpbContext context = EpbContext.get(this);
+ var src = Source.newBuilder("python", """
+ import site
+ """, "enso.py").build();
+ var initSite = context.getEnv().parsePublic(src);
+ initSite.call();
CallTarget ct = context.getEnv().parsePublic(source);
ct.call();
Object fn = context.getEnv().importSymbol("polyglot_enso_python_eval"); The patch tells Graal Python to use I am not sure how to make this process user friendly, however? |
How-to document is ready for your review! |
Jaroslav Tulach reports a new STANDUP for yesterday (2023-08-28): Progress: - Use
Next Day: Integrate the |
Jaroslav Tulach reports a new STANDUP for yesterday (2023-08-29): Progress: - Verify installation of
Next Day: Bugfixing & planning |
Jaroslav Tulach reports a new STANDUP for yesterday (2023-08-30): Progress: -
Next Day: Bugfixing
|
Want to investigate how to bring in numpy into Enso.
How can we use the function of numpy on an Enso values.
Goal is to create a sample where we compute the cumulative normal using
numpy.random.normal
.Should be a function we can call from Enso and get the result back as an Enso number.
Eventually we want a guide on how to use libraries for Python, Java and JavaScript as an end user.
The text was updated successfully, but these errors were encountered: