Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

moso

moso provides a %%moso cell magic that lets you build up a Mojo program across multiple notebook cells. All %%moso cells are collected, compiled, and run together as a single Mojo script. The last collected cell is wrapped in def main() raises:.

moso primarily supports SolveIt (from Answer.ai) because it allows the tool to identify which cell is currently executing. In a standard Jupyter Notebook environment, the magic simply collects all cells containing %%moso.

Learn more

Install

Install from PyPI:

pip install moso

Or install an editable checkout for local development:

pip install -e .

Usage

SolveIt

from moso.core import *
setup_moso()

Jupyter Notebook

from moso.core import *
setup_moso(nb_path='path/to/your/notebook.ipynb')

Then write Mojo code in %%moso cells. Earlier %%moso cells are treated as reusable definitions, and the final cell is wrapped in def main() raises::

%%moso
def add(a: Int, b: Int) -> Int:
    return a + b
%%moso
print(add(40, 2))

For example, check which GPU Mojo can see:

%%moso
from std.gpu.host import DeviceContext

var ctx = DeviceContext()
print(ctx.name())

Remote execution

Pass an SSH host and command template if Mojo runs on another machine. In a Jupyter notebook, include the notebook path so moso can collect the %%moso cells from the file on disk:

from moso.core import *

setup_moso(
    host="user@host",
    cmd="cd ~/mojo-gpu-puzzles && /root/.pixi/bin/pixi run mojo run {path}",
    nb_path="/path/to/your/notebook.ipynb",
)

How it works

filter_moso strips the %%moso lines, concatenates previous cells, and wraps the current cell in a main() (or the last cell in standard Jupyter Notebook). setup_moso registers the IPython cell magic and runs the generated source either locally or over SSH.

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages