Issue running the vector_addition example

Hello, I followed instructions in GitHub - modular/modular: The Modular Platform (includes MAX & Mojo)

pip install modular

When I run the vector additition example under modular/examples/custom_ops/kernels, I get this error:

mojo run vector_addition.mojo
/home/lab/username/modular/examples/custom_ops/kernels/vector_addition.mojo:74:2: error: ‘VectorAddition’ has no ‘compiler’ member
@compiler.register(“vector_addition”)
^~~~~~~~
/home/lab/username/venv/bin/mojo: error: failed to parse the provided Mojo source module

Mojo version is

mojo --version
Mojo 25.5.0 (573c06a4)

I notice that many examples also fail to compile. For example,

~/username/modular/examples/mojo$ mojo run mandelbrot.mojo
/home/lab/username/modular/examples/mojo/mandelbrot.mojo:15:42: error: module ‘info’ does not contain ‘simd_width_of’
from sys.info import num_physical_cores, simd_width_of
^
/home/lab/username/modular/examples/mojo/mandelbrot.mojo:55:41: error: no matching function in initialization
var t = SIMDDType.bool, simd_width
~~~~~~~~~~~~~~~~~~^

nbody:

mojo run nbody.mojo
/home/lab/username/modular/examples/mojo/nbody.mojo:28:15: error: ‘Planet’ has no ‘ImplicitlyCopyable’ member
struct Planet(ImplicitlyCopyable, Movable):

Sorry you have installation issues. Please first check if the Packages | Modular are met. Then the main branch is tracking the nightly releases and pip install modular installs the latest stable Packages | Modular version which is currently 25.5. So

git clone https://github.com/modular/modular
cd modular
git checkout modular/v25.5
cd modular/examples/mojo

For pip, it’s highly recommended to use virtual environment so

# make sure no env is active
python -m venv venv
source venv/bin/activate
python -m pip install modular

The modular package is a meta-package that includes everything such as mojo-compiler , mojo (dev dependencies such as formater, LSP etc.) and max

Now check mojo –-version should match the tag Mojo 25.5.0 (573c06a4)

Then run

mojo mandelbrot.mojo 
Number of physical cores: 12
Vectorized: 11.305873239436618 ms
Parallelized: 2.309573 ms
Parallel speedup: 4.895222294093592

For the custom_ops examples, the kernels are meant to be used with max python graph api so we can run the vector addition example via (cd custom_ops)

python vector_addition.py

outputs like

Left-hand-side values:
[0.37531552 0.16229668 0.39715832 0.6472096  0.20262577 0.4971949
 0.24008769 0.9813841  0.37782624 0.37180763]

Right-hand-side values:
[0.925224   0.32441604 0.32967967 0.30302358 0.36905172 0.57079685
 0.35871768 0.14324683 0.10780976 0.15608703]

Graph result:
[1.3005395  0.48671272 0.726838   0.95023316 0.5716775  1.0679917
 0.59880537 1.1246309  0.485636   0.5278947 ]

Expected result:
[1.3005395  0.48671272 0.726838   0.95023316 0.5716775  1.0679917
 0.59880537 1.1246309  0.485636   0.5278947 ]

Generally for best environment and package/dependency management experience we recommend to use either pixi or uv.

With pixi there’s no need to manually handing venv, python version etc. For example in the case of custom_ops can do pixi run vector_addition where pixi handles everything correctly here.

If you’re interested about GPU programming in Mojo, please check out GitHub - modular/mojo-gpu-puzzles: Learn GPU Programming in Mojo🔥 by Solving Puzzles .

Thanks for your response.

My system meets requirements. I followed above instructions.

root@compute-system:/mnt/nvme/deepaku/modular_test# git clone https://github.com/modular/modular
Cloning into 'modular'...
remote: Enumerating objects: 231880, done.
remote: Counting objects: 100% (155/155), done.
remote: Compressing objects: 100% (57/57), done.
remote: Total 231880 (delta 132), reused 98 (delta 98), pack-reused 231725 (from 3)
Receiving objects: 100% (231880/231880), 109.37 MiB | 8.17 MiB/s, done.
Resolving deltas: 100% (179786/179786), done.
root@compute-system:/mnt/nvme/deepaku/modular_test# cd modular/
root@compute-system:/mnt/nvme/deepaku/modular_test/modular# git checkout modular/v25.5
Branch 'modular/v25.5' set up to track remote branch 'modular/v25.5' from 'origin'.
Switched to a new branch 'modular/v25.5'
root@compute-system:/mnt/nvme/deepaku/modular_test/modular# cd examples/mojo/
root@compute-system:/mnt/nvme/deepaku/modular_test/modular/examples/mojo# python3 --version
Python 3.10.18
root@compute-system:/mnt/nvme/deepaku/modular_test/modular/examples/mojo# python3 -m venv venv

(venv) root@compute-system:/mnt/nvme/deepaku/modular_test/modular/examples/mojo# python -m pip install modular

mojo version returned 0.25.6.0

(venv) root@compute-system:/mnt/nvme/deepaku/modular_test/modular/examples/mojo# mojo --version
Mojo 0.25.6.0 (06be5aab)

I get this error on the example under modular/examples/mojo/

(venv) root@compute-system:/mnt/nvme/deepaku/modular_test/modular/examples/mojo# mojo mandelbrot.mojo
/mnt/nvme/deepaku/modular_test/modular/examples/mojo/mandelbrot.mojo:23:36: error: cannot pass 'DType' value, expected 'AnyTrivialRegType' in call parameter
alias simd_width = 2 * simdwidthof[float_type]()

But the example under gpu-functions ran fine.

mojo ./gpu-functions/mandelbrot.mojo
...................................,,,,c@8cc,,,.............
...............................,,,,,,cc8M @Mjc,,,,..........
............................,,,,,,,ccccM@aQaM8c,,,,,........
..........................,,,,,,,ccc88g.o. Owg8ccc,,,,......
.......................,,,,,,,,c8888M@j,    ,wMM8cccc,,.....
.....................,,,,,,cccMQOPjjPrgg,   OrwrwMMMjjc,....
..................,,,,cccccc88MaP  @            ,pGa.g8c,...
...............,,cccccccc888MjQp.                   o@8cc,..
..........,,,,c8jjMMMMMMMMM@@w.                      aj8c,,.
.....,,,,,,ccc88@QEJwr.wPjjjwG                        w8c,,.
....,,,,,cccccMMjwQ       EpQ                         .8c,,,
....,,,cc888MrajwJ                                   MMcc,,,
.cc88jMMM@@jaG.                                     oM8cc,,,
....8jMMM@@jaG.                                     oM8cc,,,
....,,,cc888MrajwJ                                   MMcc,,,
....,,,,,cccccMMjwQ       EpQ                         .8c,,,
.....,,,,,,ccc88@QEJwr.wPjjjwG                        w8c,,.
..........,,,,c8jjMMMMMMMMM@@w.                      aj8c,,.
...............,,cccccccc888MjQp.                   o@8cc,..
..................,,,,cccccc88MaP  @            ,pGa.g8c,...
.....................,,,,,,cccMQOEjjPrgg,   OrwrwMMMjjc,....
.......................,,,,,,,,c8888M@j,    ,wMM8cccc,,.....
..........................,,,,,,,ccc88g.o. Owg8ccc,,,,......
............................,,,,,,,ccccM@aQaM8c,,,,,........
...............................,,,,,,cc8M @Mjc,,,,..........

We just pushed new packages, so it looks like your pip install modular is now using the 0.25.6 version of mojo , and as a result you’ll want refresh the modular repository and check out the modular/v25.6 branch to match the new version of Mojo.

We’ve migrated the Mojo numbering from 25.50.25.6 to prepare for eventual semantic version of the language.