Giter Club home page Giter Club logo

iracket's Introduction

IRacket

IRacket is a Racket kernel for Jupyter. IRacket enables interactive notebook-style programming with Racket.

Requirements

  • Racket
  • Jupyter
  • ZeroMQ
    • on Debian/Ubuntu Linux: install the libzmq5 package
    • on RedHat/Fedora (Linux): install the zeromq package
    • on MacOS with Homebrew: run brew install zmq
    • on Windows, automatically installed by Racket's zeromq-r-lib package
    • for other systems, see http://zeromq.org

Installation

First install the iracket package:

raco pkg install iracket

Then register the iracket kernel with Jupyter:

raco iracket install

Using Jupyter with Racket

Run the Jupyter notebook server as you usually do, e.g.

jupyter notebook

and create a new notebook with the Racket kernel, or open examples/getting-started.ipynb in the iracket source directory.

Examples

See the examples subdirectory for example notebooks.

Acknowledgments

The first version of IRacket was by Theo Giannakopoulos (then at BAE Systems), for the PPAML program.

iracket's People

Contributors

agoose77 avatar gregr avatar mpcjanssen avatar rmculpepper avatar tgiannak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

iracket's Issues

Kernel not found in Mac OS due to issue with libzmq

I have both Racket and Jupyter installations running fine with even after installing zeromq with the commands given, I'm getting the following error on Mac OS Mojave :

[I 22:28:50.853 NotebookApp] Kernel started: 683b7f31-d457-4c9d-9f2b-14997b30c92e, name: racket
Kernel starting.
zmq-socket: could not find libzmq library
  error: "ffi-lib: couldn't open \"libzmq.5.dylib\" (dlopen(libzmq.5.dylib, 6): image not found)"
  context...:
   /Users/priteshshrivastava/Library/Racket/7.6/pkgs/zeromq-r-lib/main.rkt:222:0: zmq-socket
   /Applications/Racket/collects/racket/contract/private/arrow-val-first.rkt:555:3
   /Users/priteshshrivastava/Library/Racket/7.6/pkgs/iracket/private/jupyter.rkt:324:2: serve
   /Users/priteshshrivastava/Library/Racket/7.6/pkgs/iracket/private/jupyter.rkt:321:0: call-with-services
   /Users/priteshshrivastava/Library/Racket/7.6/pkgs/iracket/iracket.rkt:12:0: start-kernel
   (submod "/Users/priteshshrivastava/Library/Racket/7.6/pkgs/iracket/iracket.rkt" main): [running body]
   temp35_0
   for-loop
   run-module-instance!

iRacket Kernel memory leak on windows11 (10 MB/s)

I installed the iracket kernel in my jupyter notebook and after running the first racket code the memory usage increased.
image
And 2 minutes later without running any code or doing anything at all:
image

(Screenshot taken in resource monitor because the process is not listed in task manager).
I experienced the issue on a managed windows 10 client and on my windows 11 pc (Version 23H2, OS Build 22631.3007).
It grew till my ram was used up and then my explorer lagged and nearly crashed.

I installed the same setup under an ubuntu 22.04 LTS release without experiencing any memory leaks
For more questions just hit me up :)

Cannot find jupyter executable

kerwin@XUHENGXIAO D:\Program Files\Racket
$ raco iracket install
Warning: found different racket.exe command in executable search path
found in search path: "D:\Program Files\Racket\.\racket.exe"
currently executing: "D:\Program Files\Racket\racket.exe"
Cannot find jupyter executable.

kerwin@XUHENGXIAO D:\Program Files\Racket
$ jupyter --version
jupyter core : 4.6.3
jupyter-notebook : 6.0.3
qtconsole : 4.7.5
ipython : 7.16.1
ipykernel : 5.3.2
jupyter client : 6.1.3
jupyter lab : 2.1.4
nbconvert : 5.6.1
ipywidgets : 7.5.1
nbformat : 5.0.7
traitlets : 4.3.3

To eval or not to eval

In Geiser document, there's a section To eval or not to eval. The main idea is to facilitate incremental development. by allowing users to evaluate code inside the context where it is defined (instead of top-level). This effectively re-defines the bindings in-place. This approach of course has some cons, but I think this is useful to provide the option.

I also noticed the recent update to the document here about "the hopeless top-level", so probably you already have some idea about whether this is desirable. The re-definition involving macros is of course trickier, re-definition of functions should be relatively smooth.

I think the way Geiser implemented this is completely on racket/scheme side, by keeping aware of namespace and context for evaluation. In Jupyter, different notebooks and file editors can be associated with the same kernel session. Thus I think this may be implementable. I'm looking into this, but I'm not sure when I can figure it out.

What do you think about this?

Jupyter notebook app failed to restart KernelRestarter

I've installed the zeromq and iracket packages on my Mac. But when I run the jupyter server, the jupyter notebook app fails to start and connect the KernelRestarter. I think it is because something goes wrong with zeromq. Please see the log attached. Could u tell me how to fix it? Thank you for your help in advance.

[NotebookApp] Kernel started: c******9, name: racket
Kernel starting.
zmq-socket: could not find libzmq library
error: "ffi-lib: could not load foreign library\n path: libzmq.5.dylib\n system error: dlopen(libzmq.5.dylib, 0x0006): tried: 'libzmq.5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibzmq.5.dylib' (no such file), '/usr/lib/libzmq.5.dylib' (no such file, not in dyld cache), 'libzmq.5.dylib' (no such file), '/usr/lib/libzmq.5.dylib' (no such file, not in dyld cache)"
context...:
/Applications/Racket/collects/racket/contract/private/arrow-val-first.rkt:555:3
/Users/Username/Library/Racket/8.7/pkgs/iracket/private/jupyter.rkt:324:2: serve
/Users/Username/Library/Racket/8.7/pkgs/iracket/private/jupyter.rkt:321:0: call-with-services
/Users/Username/Library/Racket/8.7/pkgs/iracket/iracket.rkt:12:0: start-kernel
body of (submod "/Users/Username/Library/Racket/8.7/pkgs/iracket/iracket.rkt" main)

Access disallowed by code inspector to protected variable

I'm trying to create a new module language and provide all racket bindings (except that using my own #%app). However, evaluating the following code in a jupyter cell:

(module my-module racket
  (provide 
   (all-from-out racket)))

throws error:

?: access disallowed by code inspector to protected variable
  from module: '#%futures
  at: futures-enabled?

libzmq-5 not found on Apple M1 silicon

It seems that iracket is searching for zeromq-5, but the current tagged release is for Apple M1 (and possibly everything else) is 4.3.4. In any event, the kernel won't start after I did

raco pkg install iracket
raco iracket install
jupyter lab build

These commands appear to succeed, though I did get a warning about libzmg-5.dylib on the initial raco pkg iracket install command. I could not copy the text nor reproduce the error after installing iracket again via the sequence:

raco pkg remove iracket
raco pkg install iracket

jupyter lab fails as follows once I pick the iracket kernel and attempt to evaluate a cell containing #lang iracket/lang:

[I 2023-02-22 12:35:26.790 ServerApp] AsyncIOLoopKernelRestarter: restarting kernel (5/5), new random ports
Kernel starting.
zmq-socket: could not find libzmq library
  error: "ffi-lib: could not load foreign library\n  path: libzmq.5.dylib\n  system error: dlopen(libzmq.5.dylib, 0x0006): tried: 'libzmq.5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibzmq.5.dylib' (no such file), '/usr/lib/libzmq.5.dylib' (no such file, not in dyld cache), 'libzmq.5.dylib' (no such file), '/usr/lib/libzmq.5.dylib' (no such file, not in dyld cache)"
  context...:
   /Applications/Racket v8.8/collects/racket/contract/private/arrow-val-first.rkt:555:3
   /Users/brian/Library/Racket/8.8/pkgs/iracket/private/jupyter.rkt:324:2: serve
   /Users/brian/Library/Racket/8.8/pkgs/iracket/private/jupyter.rkt:321:0: call-with-services
   /Users/brian/Library/Racket/8.8/pkgs/iracket/iracket.rkt:12:0: start-kernel
   body of (submod "/Users/brian/Library/Racket/8.8/pkgs/iracket/iracket.rkt" main)

https://github.com/zeromq/libzmq/tags

Rendering HTML in cell output

The python kernel supports outputing HTML via the IPython.display module:

from IPython.core.display import display, HTML
display(HTML('<h1>Hello, world!</h1>'))

In Julia, one can do the same thing via (from this post):

display("text/html", "<script>alert('hello')</script>")

I see iracket already supported rendering images, but I'm not sure how it is implemented. Maybe expose some API for HTML rendering? My use case is to generate some file links for downloading.

Language "deinprogramm": Record definition does not work

define-record-working.txt
Hello, I am working with the language "deinprogramm" (see textbook "Schreibe dein Programm" by Mike Sperber and Herbert Klaeren). The attached code snippet works perfectly in the Editor window of DrRacket.

But in the Jupyter/iRacket environment
(define-record computer make-computer ...)
provokes the error message:
make-computer: unbound identifier;
also, no #%top syntax transformer is bound
in: make-computer

I tried the attached code snippet in the REPL window of DrRacket and got the same error message.

Do you have an explanation for this behaviour?

Optionally start the kernel with a trusted sandbox

I use Jupyter as my REPL of choice running om my local machine. In this case the current sandbox configuration (especially sandbox-security-guard) is too limited. For example, network requests are not allowed.
Would it be possible to add an argument while starting the kernel to start a trusted sandbox instead?

Can't use with Rosette, seemingly because it can't start subprocesses

When I try to use Rosette with iRacket, I get an error when Rosette tries to launch z3:

subprocess: `execute' access denied for /usr/local/Cellar/minimal-racket/8.1/share/racket/pkgs/rosette/rosette/solver/smt/../../../bin/z3
  context...:
   /usr/local/Cellar/minimal-racket/8.1/share/racket/pkgs/rosette/rosette/solver/smt/server.rkt:58:0: server-start
   /usr/local/Cellar/minimal-racket/8.1/share/racket/pkgs/rosette/rosette/solver/smt/base-solver.rkt:92:0: solver-check
   /usr/local/Cellar/minimal-racket/8.1/share/racket/pkgs/rosette/rosette/query/core.rkt:157:2: guess
   /usr/local/Cellar/minimal-racket/8.1/share/racket/pkgs/rosette/rosette/query/core.rkt:151:0: cegis
   /usr/local/Cellar/minimal-racket/8.1/share/racket/pkgs/rosette/rosette/query/core.rkt:129:6
   body of top-level

Is there a way to allow the kernel to start subprocesses?

Error in installation on Windows 10 -

I've tried to provide the path of the Jupyter exe file using the following command:

(base) PS C:\Windows\system32> jupyter --data-dir
> C:\Users\yashi\AppData\Roaming\jupyter

Then, I've tried to register IRacket with Jupyter using the --jupyter-exe flag:

PS C:\Windows\system32> raco iracket install --jupyter-exe C:\Users\yashi\AppData\Roaming\jupyter          
> Received non-zero exit code from jupyter command.

error

i can run in racket , but not jupyter .

; 如下的这个在racket里会正常,但在jupyter里会造成死机。
(require racket)

;(define (delay exp)
; (lambda () exp))
; ;(memo-proc (lambda ()
; ; exp)))
;
;(define (force delayed-object)
; (delayed-object))
;
;(define (memo-proc proc)
; (let ((already-run? false) (result false))
; (lambda ()
; (if (not already-run?)
; (begin (set! result (proc))
; (set! already-run? true)
; result)
; result))))

(define (delay ex)
(lambda () ex))

(define (force delayed-object)
(delayed-object))

(define (stream-car stream) (car stream))

(define (stream-cdr stream) (force (cdr stream)))

; this won't work as a simple function
;(define (cons-stream a b)
; (cons a (delay b)))

; This is scheme syntax for macro
; http://stackoverflow.com/questions/5610480/scheme-sicp-r5rs-why-is-delay-not-a-special-form
(define-syntax cons-stream
(syntax-rules ()
[(cons-stream x y) (cons x (delay y))]))

(define the-empty-stream '())

(define (stream-null? stream)
(null? stream))

(define (stream-filter pred stream)
(cond ((stream-null? stream) the-empty-stream)
((pred (stream-car stream))
(cons-stream (stream-car stream)
(stream-filter pred (stream-cdr stream))))
(else (stream-filter pred (stream-cdr stream)))))

(define (stream-ref s n)
(if (stream-null? s) the-empty-stream
(if (= n 0)
(stream-car s)
(stream-ref (stream-cdr s) (- n 1)))))

(define (stream-map proc . argstreams)
(if (stream-null? (car argstreams))
the-empty-stream
(cons-stream (apply proc (map stream-car argstreams))
(apply stream-map
(cons proc (map stream-cdr argstreams))))))

(define (stream-for-each proc s)
(if (stream-null? s)
'done
(begin (proc (stream-car s))
(stream-for-each proc (stream-cdr s)))))

; Neil, 2012-05-10
(define (stream-subseq stream a b)
(cond ((stream-null? stream) the-empty-stream)
((= a b) the-empty-stream)
((> a b) the-empty-stream)
(else (cons-stream (stream-ref stream a)
(stream-subseq stream (+ a 1) b)))))

(define (display-line x)
(newline)
(display x))

(define (display-stream s)
(stream-for-each display-line s))

; examples
;(let ((x (delay (+ 1 2))))
; (for ([i (in-range 1 10)])
; (display (force x))))
;
(define (integers-starting-from n)
(cons-stream n (integers-starting-from (+ n 1))))

(define integers
(integers-starting-from 1))

;(display-line (stream-ref integers 0))
(let ((x (stream-subseq integers 10000 10010)))
(display-stream x))

(define odd-numbers
(stream-filter odd? integers))

(display-stream (stream-subseq odd-numbers 50 60))

;(let ((x (cons-stream 1 (cons-stream 2 '(3)))))
; (display-stream x))

(define (stream-add s n)
(stream-map (lambda (x)
(+ x n)) s))

(define (add-streams s1 s2)
(stream-map + s1 s2))

(define fib
(cons-stream 1
(cons-stream 1
(add-streams fib
(stream-cdr fib)))))

(display-stream (stream-subseq fib 150 160))

(define (divisible? x y)
(= (remainder x y) 0))

(divisible? 10 2)

(define (sieve stream)
(cons-stream
(stream-car stream)
(sieve (stream-filter
(lambda (x)
(not (divisible? x (stream-car stream))))
(stream-cdr stream)))))

(define primes
(sieve (integers-starting-from 2)))

(display-stream (stream-subseq primes 1000 1010))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.