Skip to content

Commit

Permalink
Merge pull request #2764 from Vipul-Cariappa/kernel-final
Browse files Browse the repository at this point in the history
Jupyter Kernel
  • Loading branch information
certik authored Jul 8, 2024
2 parents f414b0f + b48e4e9 commit d26ce3a
Show file tree
Hide file tree
Showing 14 changed files with 1,012 additions and 42 deletions.
74 changes: 59 additions & 15 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,28 @@ jobs:
key:
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('ci/environment.yml') }}

- uses: conda-incubator/setup-miniconda@v2
- uses: mamba-org/setup-[email protected]
with:
miniconda-version: "latest"
auto-update-conda: true
environment-file: ci/environment.yml
python-version: ${{ matrix.python-version }}
use-only-tar-bz2: true
create-args: >-
python=${{ matrix.python-version }}
cmake=3.21.1
- name: Install Windows Conda Packages
if: contains(matrix.os, 'windows')
shell: bash -e -l {0}
run: conda install m2-bison=3.0.4 cmake=3.21.1
run: micromamba install --freeze-installed m2-bison=3.0.4 m2-filesystem

- name: Install Linux / macOS Conda Packages
if: contains(matrix.os, 'ubuntu') || contains(matrix.os, 'macos')
shell: bash -e -l {0}
run: conda install bison=3.4 nodejs=18
run: micromamba install --freeze-installed bison=3.4 nodejs=18

- name: Conda info
shell: bash -e -l {0}
run: |
conda info
conda list
micromamba info
micromamba list
- name: Setup Platform (Linux)
if: contains(matrix.os, 'ubuntu')
Expand Down Expand Up @@ -87,9 +86,9 @@ jobs:
if: contains(matrix.os, 'windows')
shell: cmd
run: |
set CONDA_INSTALL_LOCN=C:\\Miniconda3
call %CONDA_INSTALL_LOCN%\Scripts\activate.bat
call conda activate test
set MAMBA_INSTALL_LOCN=C:\\Users\runneradmin\micromamba
call %MAMBA_INSTALL_LOCN%\Scripts\activate.bat
call micromamba activate lp
set LFORTRAN_CMAKE_GENERATOR=Ninja
set WIN=1
set MACOS=0
Expand All @@ -107,9 +106,9 @@ jobs:
if: contains(matrix.os, 'windows')
shell: cmd
run: |
set CONDA_INSTALL_LOCN=C:\\Miniconda3
call %CONDA_INSTALL_LOCN%\Scripts\activate.bat
call conda activate test
set MAMBA_INSTALL_LOCN=C:\\Users\runneradmin\micromamba
call %MAMBA_INSTALL_LOCN%\Scripts\activate.bat
call micromamba activate lp
set LFORTRAN_CMAKE_GENERATOR=Ninja
set WIN=1
set MACOS=0
Expand Down Expand Up @@ -497,6 +496,51 @@ jobs:
cd integration_tests
./run_tests.py -b cpython c_py
build_jupyter_kernel:
name: Build Jupyter Kernel
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: mamba-org/setup-micromamba@v1
with:
environment-file: ci/environment.yml
create-args: >-
jupyter
nlohmann_json
python=3.10
bison=3.4
xeus=5.1.0
xeus-zmq=3.0.0
- uses: hendrikmuhs/ccache-action@main
with:
variant: sccache
key: ${{ github.job }}-${{ matrix.os }}

- name: Build LPython with Kernel
shell: bash -e -l {0}
run: |
./build0.sh
export CXXFLAGS="-Werror"
cmake . -GNinja \
-DCMAKE_BUILD_TYPE=Debug \
-DWITH_LLVM=yes \
-DWITH_XEUS=yes \
-DCMAKE_PREFIX_PATH="$CONDA_PREFIX" \
-DCMAKE_INSTALL_PREFIX="$CONDA_PREFIX"
ninja install
ctest --output-on-failure
jupyter kernelspec list --json
- name: Test Kernel
shell: bash -e -l {0}
run: |
ctest --output-on-failure
upload_tarball:
name: Upload Tarball
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ src/libasr/wasm_visitor.h
src/libasr/pass/intrinsic_function_registry_util.h
src/libasr/config.h
share/jupyter/kernels/fortran/kernel.json
share/jupyter/kernels/lpython/kernel.json
src/runtime/*.o.empty.c
python_ast.py
python_ast.h
Expand Down
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,14 @@ endif()
# XEUS (Fortran kernel)
set(WITH_XEUS no CACHE BOOL "Build with XEUS support")
if (WITH_XEUS)
find_package(xeus 0.24.1 REQUIRED)
find_package(xeus 5.1.0 REQUIRED)
find_package(xeus-zmq 3.0.0 REQUIRED)
set(HAVE_LFORTRAN_XEUS yes)

# Generate kernel.json with correct paths
configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/share/jupyter/kernels/fortran/kernel.json.in"
"${CMAKE_CURRENT_BINARY_DIR}/share/jupyter/kernels/fortran/kernel.json"
"${CMAKE_CURRENT_SOURCE_DIR}/share/jupyter/kernels/lpython/kernel.json.in"
"${CMAKE_CURRENT_BINARY_DIR}/share/jupyter/kernels/lpython/kernel.json"
)

# Configuration and data directories for Jupyter and LFortran
Expand Down
23 changes: 11 additions & 12 deletions ci/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ channels:
- defaults
dependencies:
- llvmdev=11.1.0
- toml=0.10.2
- pytest=7.2.0
- jupyter=1.0.0
- xeus=1.0.1
- xtl=0.7.4
- nlohmann_json=3.9.1
- cppzmq=4.7.1
- jupyter_kernel_test=0.4.4
- xeus=5.1.0
- xeus-zmq=3.0.0
- xonsh=0.13.3
- re2c=2.2
- numpy=1.23.4
- rapidjson
- nlohmann_json
- toml
- pytest
- jupyter
- jupyter_kernel_test
- re2c
- numpy
- zlib
- zstd
- ninja=1.11.0
- rapidjson=1.1.0
- ninja
# - bison=3.4 [not win]
# - m2-bison=3.4 [win]
67 changes: 67 additions & 0 deletions doc/src/developers_example.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "c86338ac-53ca-4115-8c5a-8bf8a5c7113e",
"metadata": {},
"outputs": [],
"source": [
"%%showast\n",
"def add(x: i32, y: i32) -> i32:\n",
" return x + y"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "23834b08-2f3f-45e7-a1ce-21a9fd4e5117",
"metadata": {},
"outputs": [],
"source": [
"%%showasr\n",
"def add(x: i32, y: i32) -> i32:\n",
" return x + y"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ec7426b4-e2e5-416c-bcae-9bb9c8926c9b",
"metadata": {},
"outputs": [],
"source": [
"%%showllvm\n",
"def sub(x: i32, y: i32) -> i32:\n",
" return add(x, -y)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "716c56ef-8210-4daf-aa23-96b385801014",
"metadata": {},
"outputs": [],
"source": [
"%%showasm\n",
"def mul(x: i32, y: i32) -> i32:\n",
" return x * y"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "LPython",
"language": "python",
"name": "lpython"
},
"language_info": {
"file_extension": ".f90",
"mimetype": "text/x-python",
"name": "python",
"version": "2018"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
134 changes: 134 additions & 0 deletions examples/example_notebook.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "e87300c2-64ed-4636-8448-591f36faba29",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello, LPython\n"
]
}
],
"source": [
"print(\"Hello, LPython\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "dfcac851-7b49-4065-8c64-4a31658249f7",
"metadata": {},
"outputs": [],
"source": [
"def add(x: i32, y: i32) -> i32:\n",
" return x + y"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "09213386-84d5-4e7c-83ba-c3b027f765dd",
"metadata": {},
"outputs": [],
"source": [
"def sub(x: i32, y: i32) -> i32:\n",
" return x - y"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "a4b49fd3-bf17-4287-9d5e-60f14ebc9a0f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"add(2, 3)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "d6f4961f-7f0c-45a6-9bf8-e549e97098b0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-1"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sub(2, 3)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "398fd4be-d7cc-4912-8aa1-880aa58b37ab",
"metadata": {},
"outputs": [],
"source": [
"@dataclass\n",
"class MyClass:\n",
" x: i32\n",
" y: f64\n",
" z: str"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "628f0b7d-09a6-49de-a0e6-2f6c664f2ba2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"12 2.45000000000000000e+01 LPython\n"
]
}
],
"source": [
"x: MyClass = MyClass(12, 24.5, \"LPython\")\n",
"print(x)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "LPython",
"language": "python",
"name": "lpython"
},
"language_info": {
"file_extension": ".f90",
"mimetype": "text/x-python",
"name": "python",
"version": "2018"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
2 changes: 1 addition & 1 deletion integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ RUN(NAME test_logical_compare LABELS cpython llvm llvm_jit) # TODO: Ad
RUN(NAME test_logical_assignment LABELS cpython llvm llvm_jit) # TODO: Add C backend after fixing issue #2708
RUN(NAME vec_01 LABELS cpython llvm llvm_jit c NOFAST)
RUN(NAME test_str_comparison LABELS cpython llvm llvm_jit c wasm)
RUN(NAME test_bit_length LABELS cpython llvm llvm_jit c)
RUN(NAME test_bit_length LABELS cpython c) # FIXME: This test fails on llvm & llvm_jit
RUN(NAME str_to_list_cast LABELS cpython llvm llvm_jit c)
RUN(NAME cast_01 LABELS cpython llvm llvm_jit c)
RUN(NAME cast_02 LABELS cpython llvm llvm_jit c)
Expand Down
10 changes: 10 additions & 0 deletions share/jupyter/kernels/lpython/kernel.json.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"display_name": "LPython",
"argv": [
"@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@/lpython",
"kernel",
"-f",
"{connection_file}"
],
"language": "python"
}
Loading

0 comments on commit d26ce3a

Please sign in to comment.