Mahmoud Abduljawad
Mahmoud Abduljawad
MModular
Created by Mahmoud Abduljawad on 9/17/2023 in #questions
How to store PythonObject in DynamicVector?
This looks like a progress :mojo: I knew the answer would be in using pointers but didn't know how to put in code.
6 replies
MModular
Created by Mahmoud Abduljawad on 9/17/2023 in #questions
How to store PythonObject in DynamicVector?
Yes. The problem isn't whether dv is immutable or not, it is that PythonObject is not "passable".
6 replies
MModular
Created by Dawn's Knight on 9/16/2023 in #questions
Python bug
Agree.
30 replies
MModular
Created by Dawn's Knight on 9/16/2023 in #questions
Python bug
While this doesn't happen so much in the wild, it still does to a certain percentage the prompted the PSF to consider a PEP for it.
30 replies
MModular
Created by Dawn's Knight on 9/16/2023 in #questions
Python bug
I wouldn't suggest this publicly without adding a reference to what that is and what it means. For those reading: https://peps.python.org/pep-0668/ Since many OS depend on Python for system tasks, installing certain packages on default environment could result in conflicts that break the OS itself. For that, this feature was introduced to prevent PIP from modifying default environment. Few others have already made it by using venv and modifying mojo config to point to venv, which is safer on the OS.
30 replies
MModular
Created by Sai Tej on 9/13/2023 in #questions
please add support for spacy and fastapi
at this stage
I'm sure I read somewhere that Mojo is targeting improving performance on Python modules ran in Mojo. Is that why you ended your comment with that, or am I hallucinating?
13 replies
MModular
Created by Arctic on 9/15/2023 in #questions
Plans for a package manager?
One thing to take into consideration for Mojo package manager when it happens is supply-chain attacks which were used recently in PyPI.
26 replies
MModular
Created by Mahmoud Abduljawad on 9/9/2023 in #questions
How to pass Mojo function to Python in Python interop?
13 replies
MModular
Created by __qqlalksdfnq__ on 9/11/2023 in #questions
Can I use Python library like huggingface transformer?
You can always try importing any Python library from Mojo and see the aftermath of it:
from python.python import Python
fn main():
let transformers = Python.import_module("transformers")
from python.python import Python
fn main():
let transformers = Python.import_module("transformers")
9 replies
MModular
Created by Helehex on 9/11/2023 in #questions
Running twice gives error
This is one interesting case that reminds me of early days of rust becoming mainstream and many users still confused about how ownership and borrow works in it. This conversation here could be elaborated to become a full insightful look at the same with Mojo. Do it, @TeamPuzel.
109 replies
MModular
Created by Mahmoud Abduljawad on 9/9/2023 in #questions
How to pass Mojo function to Python in Python interop?
I see, @Jack Clayton. I'm trying to offload some of the logic from Python to Mojo to compare performance gains in such cases. Of course this is the simplest explanation, however, I was hoping to start building a sample web application with Mojo built on top of AIOHTTP which won't be possible at the moment due to this limitation. Do I need to open an issue to track this?
13 replies
MModular
Created by Mahmoud Abduljawad on 9/9/2023 in #questions
How to pass Mojo function to Python in Python interop?
Error:
hello.mojo:37:11: error: invalid call to '__call__': argument #1 cannot be converted from 'fn() raises -> None' to 'PythonObject'
hello.do(print_arg1)
~~~~~~~~^~~~~~~~~~~~
hello.mojo:1:1: note: function declared here
# ===----------------------------------------------------------------------=== #
^
mojo: error: failed to parse the provided Mojo
hello.mojo:37:11: error: invalid call to '__call__': argument #1 cannot be converted from 'fn() raises -> None' to 'PythonObject'
hello.do(print_arg1)
~~~~~~~~^~~~~~~~~~~~
hello.mojo:1:1: note: function declared here
# ===----------------------------------------------------------------------=== #
^
mojo: error: failed to parse the provided Mojo
13 replies
MModular
Created by Mahmoud Abduljawad on 9/9/2023 in #questions
How to pass Mojo function to Python in Python interop?
# hello.mojo
from python.python import (
Python,
_destroy_python,
_init_python,
)
from python.object import PythonObject

def print_arg1() -> None:
Python.add_to_path(".")
let hello = Python.import_module("hello")
let my_class = hello.MyClass("Hello, world from Mojo!")
print(my_class.arg1)

def main():
Python.add_to_path(".")
let hello = Python.import_module("hello")
let my_class = hello.MyClass("Hello, world from Python!")
print(my_class)
hello.do(my_class.print_arg1)
hello.do(print_arg1)
# hello.mojo
from python.python import (
Python,
_destroy_python,
_init_python,
)
from python.object import PythonObject

def print_arg1() -> None:
Python.add_to_path(".")
let hello = Python.import_module("hello")
let my_class = hello.MyClass("Hello, world from Mojo!")
print(my_class.arg1)

def main():
Python.add_to_path(".")
let hello = Python.import_module("hello")
let my_class = hello.MyClass("Hello, world from Python!")
print(my_class)
hello.do(my_class.print_arg1)
hello.do(print_arg1)
13 replies
MModular
Created by Mahmoud Abduljawad on 9/9/2023 in #questions
How to pass Mojo function to Python in Python interop?
# hello.py
from typing import Callable

class MyClass:
def __init__(self, arg1: str):
self.arg1 = arg1

def print_arg1(self) -> None:
print(self.arg1)

def do(func: Callable) -> None:
func()

if __name__ == "__main__":
MyClass("Hello, world!").print_arg1()
# hello.py
from typing import Callable

class MyClass:
def __init__(self, arg1: str):
self.arg1 = arg1

def print_arg1(self) -> None:
print(self.arg1)

def do(func: Callable) -> None:
func()

if __name__ == "__main__":
MyClass("Hello, world!").print_arg1()
13 replies
MModular
Created by Mahmoud Abduljawad on 9/9/2023 in #questions
How to pass Mojo function to Python in Python interop?
This is another example where this fails:
13 replies
MModular
Created by Mahmoud Abduljawad on 9/9/2023 in #questions
How to pass Mojo function to Python in Python interop?
The function returns an object created by python lib, effectively, PythonObject. If I set the return type of function as such, marshalling fails.
13 replies