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

Implement module level (and possibly class-level) loading #840

Open
rocky opened this issue Apr 24, 2023 · 0 comments
Open

Implement module level (and possibly class-level) loading #840

rocky opened this issue Apr 24, 2023 · 0 comments
Labels
enhancement New feature or request performance Something is slow and you have an idea of how to fix it

Comments

@rocky
Copy link
Member

rocky commented Apr 24, 2023

Add autoload mechanism to speed up start up time allowing and allow load time to be distributed over the execution of functions/features needed.

Starting with GNU-emacs as an example (in Lisp syntax):

(autoload FUNCTION FILE &optional DOCSTRING INTERACTIVE TYPE)

In our case, FILE would be a Python module import, e.g. builtin.mathics.quanum_mechanics or even a Mathics3 module name like pymathics.graph.

We do not need the optional DOCSTRING, INTERACTIVE, or TYPE. Docstring comes from the loaded module. The other optional parameters I don't think are applicable here. As for FUNCTION we would probably collect all of the builtin-functions (class names) into one module-level autoload.

Related is that inside the module we can have additional autoloaded rules written in Mathics3 that are currently in the autoload/rules directory, e.g. autoload/rules/Limit.m which might be moved down under a new calculus directory. Or maybe is put inside autoload/rules/calculus.m. We can decided this based on speed of loading and number of rules in each file.

The mechanism for doing this might be having a shadow autoload structure that mirrors the mathics.builtin structure. For example, we currently have an autoload directory which currently has Mathics3 code with extension .m. So Python code can be put there as well.

For module-level autoload:

# inside  mathics.autoload.__init__.py: 
autoload =  {
"quantum_mechanics.angular":  ["ClebschGoradan", "PauliMatrix", "SixJSymbol", "ThreeJSymbol"],
"distance.clusters":  ["ClusteringComponents", "FindClusters", "Nearest"],
# ...
}

For a class-level autoload:

class DiceDissimilarity(_BooleanDissimilarity):
    autoload = True

Describe alternatives you've considered

Also related bit different is reorganizing the code and the definitions part so that we can load a Python Pickle fragment of various attributes, e.g. Function Rewrite Rules Symbols, and Definition headers.

WMA DumpSave seems to be the WMA equivalent of this.

See also https://reference.wolfram.com/language/workflow/CreateAPackageFile.html

Implementation Suggestion
The way an autoload mechanism works (in GNU Emacs) is that boilerplate code is added for the autoloaded object which performs the loading and overwrites the code portion.

@rocky rocky added enhancement New feature or request performance Something is slow and you have an idea of how to fix it labels Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request performance Something is slow and you have an idea of how to fix it
Projects
None yet
Development

No branches or pull requests

1 participant