mentat-collective / road-to-reality

The Road to Reality essay and newsletter source. A journey through computational physics, from eval/apply to the Einstein field equations.
https://reality.mentat.org
MIT License
90 stars 10 forks source link

REPL workflow via Calva #7

Open fbreuer opened 1 year ago

fbreuer commented 1 year ago

I tried starting a REPL via Calva. I run the jack-in command and chose "deps.edn" as project type and "repl" as alias. (These may well not be the right choices.) I then got the following exception (after lots of apparently successful downloads). (I also ran bb tasks beforehand):

Syntax error macroexpanding at (emmy/expression/compile.cljc:1:1).
        at clojure.lang.Compiler.load(Compiler.java:7665)
        at clojure.lang.RT.loadResourceScript(RT.java:381)
        at clojure.lang.RT.loadResourceScript(RT.java:372)
        at clojure.lang.RT.load(RT.java:459)
        at clojure.lang.RT.load(RT.java:424)
        at clojure.core$load$fn__6908.invoke(core.clj:6161)
        at clojure.core$load.invokeStatic(core.clj:6160)
        at clojure.core$load.doInvoke(core.clj:6144)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at clojure.core$load_one.invokeStatic(core.clj:5933)
        at clojure.core$load_one.invoke(core.clj:5928)
        at clojure.core$load_lib$fn__6850.invoke(core.clj:5975)
        at clojure.core$load_lib.invokeStatic(core.clj:5974)
        at clojure.core$load_lib.doInvoke(core.clj:5953)
        at clojure.lang.RestFn.applyTo(RestFn.java:142)
        at clojure.core$apply.invokeStatic(core.clj:669)
        at clojure.core$load_libs.invokeStatic(core.clj:6016)
        at clojure.core$load_libs.doInvoke(core.clj:6000)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.core$apply.invokeStatic(core.clj:669)
        at clojure.core$require.invokeStatic(core.clj:6038)
        at clojure.core$require.doInvoke(core.clj:6038)
        at clojure.lang.RestFn.invoke(RestFn.java:1789)
        at emmy.numerical.quadrature$eval48699$loading__6789__auto____48700.invoke(quadrature.cljc:3)
        at emmy.numerical.quadrature$eval48699.invokeStatic(quadrature.cljc:3)
        at emmy.numerical.quadrature$eval48699.invoke(quadrature.cljc:3)
        at clojure.lang.Compiler.eval(Compiler.java:7194)
        at clojure.lang.Compiler.eval(Compiler.java:7183)
        at clojure.lang.Compiler.load(Compiler.java:7653)
        at clojure.lang.RT.loadResourceScript(RT.java:381)
        at clojure.lang.RT.loadResourceScript(RT.java:372)
        at clojure.lang.RT.load(RT.java:459)
        at clojure.lang.RT.load(RT.java:424)
        at clojure.core$load$fn__6908.invoke(core.clj:6161)
        at clojure.core$load.invokeStatic(core.clj:6160)
        at clojure.core$load.doInvoke(core.clj:6144)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at clojure.core$load_one.invokeStatic(core.clj:5933)
        at clojure.core$load_one.invoke(core.clj:5928)
        at clojure.core$load_lib$fn__6850.invoke(core.clj:5975)
        at clojure.core$load_lib.invokeStatic(core.clj:5974)
        at clojure.core$load_lib.doInvoke(core.clj:5953)
        at clojure.lang.RestFn.applyTo(RestFn.java:142)
        at clojure.core$apply.invokeStatic(core.clj:669)
        at clojure.core$load_libs.invokeStatic(core.clj:6016)
        at clojure.core$load_libs.doInvoke(core.clj:6000)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.core$apply.invokeStatic(core.clj:669)
        at clojure.core$require.invokeStatic(core.clj:6038)
        at clojure.core$require.doInvoke(core.clj:6038)
        at clojure.lang.RestFn.invoke(RestFn.java:703)
        at emmy.mechanics.lagrange$eval48165$loading__6789__auto____48166.invoke(lagrange.cljc:3)
        at emmy.mechanics.lagrange$eval48165.invokeStatic(lagrange.cljc:3)
        at emmy.mechanics.lagrange$eval48165.invoke(lagrange.cljc:3)
        at clojure.lang.Compiler.eval(Compiler.java:7194)
        at clojure.lang.Compiler.eval(Compiler.java:7183)
        at clojure.lang.Compiler.load(Compiler.java:7653)
        at clojure.lang.RT.loadResourceScript(RT.java:381)
        at clojure.lang.RT.loadResourceScript(RT.java:372)
        at clojure.lang.RT.load(RT.java:459)
        at clojure.lang.RT.load(RT.java:424)
        at clojure.core$load$fn__6908.invoke(core.clj:6161)
        at clojure.core$load.invokeStatic(core.clj:6160)
        at clojure.core$load.doInvoke(core.clj:6144)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at clojure.core$load_one.invokeStatic(core.clj:5933)
        at clojure.core$load_one.invoke(core.clj:5928)
        at clojure.core$load_lib$fn__6850.invoke(core.clj:5975)
        at clojure.core$load_lib.invokeStatic(core.clj:5974)
        at clojure.core$load_lib.doInvoke(core.clj:5953)
        at clojure.lang.RestFn.applyTo(RestFn.java:142)
        at clojure.core$apply.invokeStatic(core.clj:669)
        at clojure.core$load_libs.invokeStatic(core.clj:6016)
        at clojure.core$load_libs.doInvoke(core.clj:6000)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.core$apply.invokeStatic(core.clj:669)
        at clojure.core$require.invokeStatic(core.clj:6038)
        at clojure.core$require.doInvoke(core.clj:6038)
        at clojure.lang.RestFn.invoke(RestFn.java:805)
        at emmy.mechanics.hamilton$eval48159$loading__6789__auto____48160.invoke(hamilton.cljc:3)
        at emmy.mechanics.hamilton$eval48159.invokeStatic(hamilton.cljc:3)
        at emmy.mechanics.hamilton$eval48159.invoke(hamilton.cljc:3)
        at clojure.lang.Compiler.eval(Compiler.java:7194)
        at clojure.lang.Compiler.eval(Compiler.java:7183)
        at clojure.lang.Compiler.load(Compiler.java:7653)
        at clojure.lang.RT.loadResourceScript(RT.java:381)
        at clojure.lang.RT.loadResourceScript(RT.java:372)
        at clojure.lang.RT.load(RT.java:459)
        at clojure.lang.RT.load(RT.java:424)
        at clojure.core$load$fn__6908.invoke(core.clj:6161)
        at clojure.core$load.invokeStatic(core.clj:6160)
        at clojure.core$load.doInvoke(core.clj:6144)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at clojure.core$load_one.invokeStatic(core.clj:5933)
        at clojure.core$load_one.invoke(core.clj:5928)
        at clojure.core$load_lib$fn__6850.invoke(core.clj:5975)
        at clojure.core$load_lib.invokeStatic(core.clj:5974)
        at clojure.core$load_lib.doInvoke(core.clj:5953)
        at clojure.lang.RestFn.applyTo(RestFn.java:142)
        at clojure.core$apply.invokeStatic(core.clj:669)
        at clojure.core$load_libs.invokeStatic(core.clj:6016)
        at clojure.core$load_libs.doInvoke(core.clj:6000)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.core$apply.invokeStatic(core.clj:669)
        at clojure.core$require.invokeStatic(core.clj:6038)
        at clojure.core$require.doInvoke(core.clj:6038)
        at clojure.lang.RestFn.invoke(RestFn.java:3894)
        at emmy.env$eval34092$loading__6789__auto____34093.invoke(env.cljc:3)
        at emmy.env$eval34092.invokeStatic(env.cljc:3)
        at emmy.env$eval34092.invoke(env.cljc:3)
        at clojure.lang.Compiler.eval(Compiler.java:7194)
        at clojure.lang.Compiler.eval(Compiler.java:7183)
        at clojure.lang.Compiler.load(Compiler.java:7653)
        at clojure.lang.RT.loadResourceScript(RT.java:381)
        at clojure.lang.RT.loadResourceScript(RT.java:372)
        at clojure.lang.RT.load(RT.java:459)
        at clojure.lang.RT.load(RT.java:424)
        at clojure.core$load$fn__6908.invoke(core.clj:6161)
        at clojure.core$load.invokeStatic(core.clj:6160)
        at clojure.core$load.doInvoke(core.clj:6144)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at clojure.core$load_one.invokeStatic(core.clj:5933)
        at clojure.core$load_one.invoke(core.clj:5928)
        at clojure.core$load_lib$fn__6850.invoke(core.clj:5975)
        at clojure.core$load_lib.invokeStatic(core.clj:5974)
        at clojure.core$load_lib.doInvoke(core.clj:5953)
        at clojure.lang.RestFn.applyTo(RestFn.java:142)
        at clojure.core$apply.invokeStatic(core.clj:669)
        at clojure.core$load_libs.invokeStatic(core.clj:6016)
        at clojure.core$load_libs.doInvoke(core.clj:6000)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.core$apply.invokeStatic(core.clj:669)
        at clojure.core$require.invokeStatic(core.clj:6038)
        at clojure.core$require.doInvoke(core.clj:6038)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at user$eval34086.invokeStatic(user.clj:7)
        at user$eval34086.invoke(user.clj:7)
        at clojure.lang.Compiler.eval(Compiler.java:7194)
        at clojure.lang.Compiler.load(Compiler.java:7653)
        at clojure.lang.RT.loadResourceScript(RT.java:381)
        at clojure.lang.RT.loadResourceScript(RT.java:368)
        at clojure.lang.RT.maybeLoadResourceScript(RT.java:364)
        at clojure.lang.RT.doInit(RT.java:486)
        at clojure.lang.RT.init(RT.java:467)
        at clojure.main.main(main.java:38)
Caused by: java.io.FileNotFoundException: Could not locate sci/core__init.class, sci/core.clj or sci/core.cljc on classpath.
        at clojure.lang.RT.load(RT.java:462)
        at clojure.lang.RT.load(RT.java:424)
        at clojure.core$load$fn__6908.invoke(core.clj:6161)
        at clojure.core$load.invokeStatic(core.clj:6160)
        at clojure.core$load.doInvoke(core.clj:6144)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at clojure.core$load_one.invokeStatic(core.clj:5933)
        at clojure.core$load_one.invoke(core.clj:5928)
        at clojure.core$load_lib$fn__6850.invoke(core.clj:5975)
        at clojure.core$load_lib.invokeStatic(core.clj:5974)
        at clojure.core$load_lib.doInvoke(core.clj:5953)
        at clojure.lang.RestFn.applyTo(RestFn.java:142)
        at clojure.core$apply.invokeStatic(core.clj:669)
        at clojure.core$load_libs.invokeStatic(core.clj:6016)
        at clojure.core$load_libs.doInvoke(core.clj:6000)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.core$apply.invokeStatic(core.clj:669)
        at clojure.core$require.invokeStatic(core.clj:6038)
        at clojure.core$require.doInvoke(core.clj:6038)
        at clojure.lang.RestFn.invoke(RestFn.java:2088)
        at emmy.expression.compile$eval48707$loading__6789__auto____48708.invoke(compile.cljc:3)
        at emmy.expression.compile$eval48707.invokeStatic(compile.cljc:3)
        at emmy.expression.compile$eval48707.invoke(compile.cljc:3)
        at clojure.lang.Compiler.eval(Compiler.java:7194)
        at clojure.lang.Compiler.eval(Compiler.java:7183)
        at clojure.lang.Compiler.load(Compiler.java:7653)
        ... 144 more
Calling `mentat.clerk-utils.build/halt!` on shutdown...
Jack-in process exited. Status: 1
fbreuer commented 1 year ago

Note the problem is different if I jack in using other options. So first would be good to clarify which project type and alias I should choose.

fbreuer commented 1 year ago

Ok, the solution is to select type = deps.edn and alias :nextjournal/clerk and not :repl.

This gets me to a functioning repl. Doing (user/serve!) from there leads to a long build process that then ends here:

; [:mentat.clerk-utils.build.shadow/clerk] Build completed. (1319 files, 1317 compiled, 0 warnings, 229.64s)
; 
; Execution error (NoSuchFileException) at sun.nio.fs.UnixException/translateToIOException (UnixException.java:92).
; /Users/felix/Dropbox/Dev/Macro/macro-notes/2023-05-19%20Sam%20Ritchie/road-to-reality/src/reality/viewer.clj

with stacktrace

sun.nio.fs.UnixException/translateToIOException (UnixException.java:92)
sun.nio.fs.UnixException/rethrowAsIOException (UnixException.java:106)
sun.nio.fs.UnixFileSystemProvider/newByteChannel (UnixFileSystemProvider.java:218)
java.nio.file.Files/newByteChannel (Files.java:380)
java.nio.file.Files/readAllBytes (Files.java:3287)
babashka.fs/read-all-bytes (fs.cljc:612)
babashka.fs/read-all-bytes (fs.cljc:609)
nextjournal.clerk.analyzer/analyze-file (analyzer.clj:371)
nextjournal.clerk.analyzer/analyze-file (analyzer.clj:369)
nextjournal.clerk.analyzer/build-graph (analyzer.clj:540)
clojure.core.protocols/iter-reduce (protocols.clj:49)
clojure.core.protocols/fn (protocols.clj:75)
clojure.core.protocols/fn (protocols.clj:13)
clojure.core/reduce (core.clj:6886)
clojure.core/reduce (core.clj:6868)
nextjournal.clerk.analyzer/build-graph (analyzer.clj:534)
nextjournal.clerk.analyzer/build-graph (analyzer.clj:517)
nextjournal.clerk.eval/+eval-results (eval.clj:245)
nextjournal.clerk.eval/+eval-results (eval.clj:241)
nextjournal.clerk/show! (clerk.clj:58)
nextjournal.clerk/show! (clerk.clj:22)
mentat.clerk-utils.build/serve! (build.clj:77)
mentat.clerk-utils.build/serve! (build.clj:49)
user/serve! (user.clj:61)
user/serve! (user.clj:54)
user/serve! (user.clj:59)
user/serve! (user.clj:54)
user/eval62427 (NO_SOURCE_FILE:29)
clojure.lang.Compiler/eval (Compiler.java:7194)
clojure.core/eval (core.clj:3215)
clojure.core/eval (core.clj:3211)
nrepl.middleware.interruptible-eval/evaluate (interruptible_eval.clj:87)
clojure.core/apply (core.clj:667)
clojure.core/with-bindings* (core.clj:1990)
nrepl.middleware.interruptible-eval/evaluate (interruptible_eval.clj:87)
clojure.main/repl (main.clj:437)
clojure.main/repl (main.clj:458)
clojure.main/repl (main.clj:368)
nrepl.middleware.interruptible-eval/evaluate (interruptible_eval.clj:84)
nrepl.middleware.interruptible-eval/evaluate (interruptible_eval.clj:56)
nrepl.middleware.interruptible-eval/interruptible-eval (interruptible_eval.clj:152)
nrepl.middleware.session/session-exec (session.clj:218)
nrepl.middleware.session/session-exec (session.clj:217)
java.lang.Thread/run (Thread.java:1589)
fbreuer commented 1 year ago

I should add that the file it is complaining about is in fact present.

fbreuer commented 1 year ago

Ok I figured it out. The issue is with spaces in the path. Somewhere along the above stack trace spaces get escaped " " -> "%20", but babashka.fs does not handle %20 as a space. Probably an easy fix if one knows where to look in this very deep stack trace.

fbreuer commented 1 year ago

There was one more issue. For some reason when using (user/serve!) I would always see the index page and never the introduction, no matter whether I was navigating to localhost:7777 or localhost:7777/essays/reality/introduction or variations thereof. I don't think this had anything to do with spaces in paths, as this occurred after I had moved the repo to a different location without spaces in paths.

Workaround has been to instead start clerk with (user/serve! {:index "essays/reality/introduction.md"}) so that I see the first essay on the index.

fbreuer commented 1 year ago

In summary, all problems figured-out on my end, but the following three follow-ups may be useful:

  1. Add comment to readme to start Calva with "deps.edn" and ":nextjournal/clerk"
  2. Make sure escaping of spaces in paths is handled consistently
  3. Ensure (user/serve!) does keep the user stuck on the index page