Skip to content
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

Test jupyter support #2763

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b1567d8
Implement Jupyter kernel
Vipul-Cariappa Jul 6, 2024
8eda48b
Test Kernel; presently it only builds, we should add tests later
Vipul-Cariappa Jul 6, 2024
627ba51
fix CI
Vipul-Cariappa Jul 6, 2024
3e85b2f
fix CI
Vipul-Cariappa Jul 6, 2024
217343a
fix CI
Vipul-Cariappa Jul 6, 2024
732b5ed
fix CI
Vipul-Cariappa Jul 6, 2024
66f8fc3
CI fix
Vipul-Cariappa Jul 6, 2024
89ba508
CI: Do not modify other jobs
certik Jul 6, 2024
3a55d86
Hide python_kernel behind ifdef
certik Jul 6, 2024
ec94d15
Keep xeus in ci/environment.yml
certik Jul 6, 2024
16f00af
Use micromamba
certik Jul 6, 2024
506a6be
Add xeus-zmq
certik Jul 6, 2024
8362c91
Disable conda info
certik Jul 6, 2024
91eb84e
CI: update Windows build commands
certik Jul 6, 2024
e6574c4
CI: switch to micromamba, update xeus
certik Jul 6, 2024
eed485e
Use lp
certik Jul 6, 2024
d1e230a
Use the old xeus
certik Jul 6, 2024
34613d7
Use xonsh 0.16.0
certik Jul 6, 2024
0c3b95b
Fix Windows test
certik Jul 6, 2024
d1dc5f0
Use latest version
certik Jul 6, 2024
e73253e
Pin the packages
certik Jul 6, 2024
ae16656
Do not upgrade installed packages
certik Jul 6, 2024
e4fa09a
List
certik Jul 6, 2024
81beb7c
Pin packages
certik Jul 6, 2024
ba8a13c
Fix nlohmann_json
certik Jul 6, 2024
1c77ac5
X
certik Jul 6, 2024
c8a80c3
zstd
certik Jul 6, 2024
2ed3ac2
downgrade
certik Jul 6, 2024
e69e069
Pin zstd, zlib
certik Jul 6, 2024
9ec6d6d
X
certik Jul 6, 2024
de257f5
Merge branch 'main' into ci_mamba
certik Jul 6, 2024
d8ea743
XX comment out failing tests
certik Jul 8, 2024
9c5b8ec
XX disable a failing integration test
certik Jul 8, 2024
766e5a6
Merge branch 'ci_mamba' into ci_kernel
certik Jul 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 69 additions & 24 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,38 @@ jobs:
with:
fetch-depth: 0

- name: Cache conda
uses: actions/cache@v3
env:
CACHE_NUMBER: 0
with:
path: ~/conda_pkgs_dir
key:
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('ci/environment.yml') }}

- uses: conda-incubator/setup-miniconda@v2
# - name: Cache conda
# uses: actions/cache@v3
# env:
# CACHE_NUMBER: 0
# with:
# path: ~/conda_pkgs_dir
# key:
# ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('ci/environment.yml') }}

- 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 }}
zstd=1.5.2
zlib=1.2.13

- 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 cmake=3.21.1

- 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 +87,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 +107,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 +497,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
7 changes: 3 additions & 4 deletions ci/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ dependencies:
- 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
- xeus=5.1.0
- xeus-zmq=3.0.0
- nlohmann_json=3.11.3
- jupyter_kernel_test=0.4.4
- xonsh=0.13.3
- re2c=2.2
Expand Down
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)
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
Loading