Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the py4cl2 Reference Manual, version 2.6.0, generated automatically by Declt version 3.0 "Montgomery Scott" on Tue Dec 22 14:46:03 2020 GMT+0.
• Introduction | What py4cl2 is all about | |
• Systems | The systems documentation | |
• Files | The files documentation | |
• Packages | The packages documentation | |
• Definitions | The symbols documentation | |
• Indexes | Concepts, functions, variables and data types |
This is a fork of bendudson/py4cl.
Detailed documentation is available on github-pages (could be a bit outdated).
Check the Releases section.
(ql:quickload :py4cl2 :silent t)
(py4cl2:defpymodule "numpy" nil :lisp-package "NP")
(py4cl2:defpymodule "scipy.integrate" nil :lisp-package "INTEGRATE")
;; Integrate some ODEs
(defparameter *data*
(integrate:odeint
:func (lambda (y time)
(list (aref y 1) ; dy[0]/dt = y[1]
(- (aref y 0)))) ; dy[1]/dt = -y[0]
:y-0 #(1.0 0.0) ; Initial state
:t (np:linspace :start 0.0 :stop (* 2 pi) :num 20)))
; Vector of times
; (array-dimensions *data*) => (20 2)
;; Make a plot, save and show it in a window
(py4cl2:defpymodule "matplotlib.pyplot" nil :lisp-package "PLT")
(plt:plot *data*)
(plt:xlabel "Time")
(plt:savefig "result.pdf")
(plt:show)
Great thanks to Ben Dudson for starting this project, and documenting it enough to make it more-buildable!
Next: Files, Previous: Introduction, Up: Top [Contents][Index]
The main system appears first, followed by any subsystem dependency.
• The py4cl2 system |
py4cl author: Ben Dudson <benjamin.dudson@york.ac.uk>
MIT
Some improvements over py4cl. py4cl is a library for interfacing with python libraries from common lisp, using streams to communicate with the python process.
Report the issues at https://github.com/digikar99/py4cl2/issues
(More) Documentation is available at https://digikar99.github.io/py4cl2/
2.6.0
py4cl2.asd (file)
Files are sorted by type and then listed depth-first from the systems components trees.
• Lisp files | ||
• Static files |
Next: Static files, Previous: Files, Up: Files [Contents][Index]
Next: The py4cl2/package․lisp file, Previous: Lisp files, Up: Lisp files [Contents][Index]
/home/quickref/quicklisp/dists/quicklisp/software/py4cl2-v2.6.0/py4cl2.asd
py4cl2 (system)
Next: The py4cl2/config․lisp file, Previous: The py4cl2․asd file, Up: Lisp files [Contents][Index]
python-code (file)
py4cl2 (system)
package.lisp
Next: The py4cl2/features․lisp file, Previous: The py4cl2/package․lisp file, Up: Lisp files [Contents][Index]
py4cl2 (system)
config.lisp
Next: The py4cl2/reader․lisp file, Previous: The py4cl2/config․lisp file, Up: Lisp files [Contents][Index]
py4cl2 (system)
features.lisp
Next: The py4cl2/writer․lisp file, Previous: The py4cl2/features․lisp file, Up: Lisp files [Contents][Index]
py4cl2 (system)
reader.lisp
Next: The py4cl2/python-process․lisp file, Previous: The py4cl2/reader․lisp file, Up: Lisp files [Contents][Index]
py4cl2 (system)
writer.lisp
Next: The py4cl2/lisp-classes․lisp file, Previous: The py4cl2/writer․lisp file, Up: Lisp files [Contents][Index]
py4cl2 (system)
python-process.lisp
Next: The py4cl2/callpython․lisp file, Previous: The py4cl2/python-process․lisp file, Up: Lisp files [Contents][Index]
py4cl2 (system)
lisp-classes.lisp
Next: The py4cl2/import-export․lisp file, Previous: The py4cl2/lisp-classes․lisp file, Up: Lisp files [Contents][Index]
py4cl2 (system)
callpython.lisp
Next: The py4cl2/do-after-load․lisp file, Previous: The py4cl2/callpython․lisp file, Up: Lisp files [Contents][Index]
py4cl2 (system)
import-export.lisp
Previous: The py4cl2/import-export․lisp file, Up: Lisp files [Contents][Index]
py4cl2 (system)
do-after-load.lisp
Previous: Lisp files, Up: Files [Contents][Index]
• The py4cl2/python-code file | ||
• The py4cl2/.config file |
Next: The py4cl2/․config file, Previous: Static files, Up: Static files [Contents][Index]
py4cl2 (system)
/home/quickref/quicklisp/dists/quicklisp/software/py4cl2-v2.6.0/py4cl.py
Previous: The py4cl2/python-code file, Up: Static files [Contents][Index]
do-after-load.lisp (file)
py4cl2 (system)
/home/quickref/quicklisp/dists/quicklisp/software/py4cl2-v2.6.0/.config
Next: Definitions, Previous: Files, Up: Top [Contents][Index]
Packages are listed by definition order.
• The py4cl2 package |
package.lisp (file)
Definitions are sorted by export status, category, package, and then by lexicographic order.
• Exported definitions | ||
• Internal definitions |
Next: Internal definitions, Previous: Definitions, Up: Definitions [Contents][Index]
• Exported special variables | ||
• Exported macros | ||
• Exported functions | ||
• Exported generic functions | ||
• Exported conditions |
Next: Exported macros, Previous: Exported definitions, Up: Exported definitions [Contents][Index]
(GETF *ARRAYFIERS* *ARRAY-TYPE*) should return a single argument function that converts the ARRAY into the required type.
config.lisp (file)
(GETF *ARRAYFIERS* *ARRAY-TYPE*) should return a single argument function that converts the ARRAY into the required type.
config.lisp (file)
Configuration variable used to store configuration values for PY4CL2. This variable should be manipulated using CONFIG-VAR and (SETF CONFIG-VAR).
config.lisp (file)
DEFPYMODULE avoids printing progress if this is T.
import-export.lisp (file)
A list of PY4CL2 features available on the system. (Support for :ARRAYS requires numpy and is only determinable after python process has started.)
features.lisp (file)
If non-NIL, then issues a WARNING on use of a feature unavailable on the platform. See PY4CL2:*INTERNAL-FEATURES* for the list of available features.
features.lisp (file)
Next: Exported functions, Previous: Exported special variables, Up: Exported definitions [Contents][Index]
callpython.lisp (file)
Defines a function which calls python
Example
(py4cl:pyexec "import math")
(py4cl:defpyfun "math.sqrt")
(math.sqrt 42) -> 6.4807405
Arguments:
FUN-NAME: name of the function in python, before import
PYMODULE-NAME: name of the module containing FUN-NAME
AS: name of the function in python, after import
LISP-FUN-NAME: name of the lisp symbol to which the function is bound*
LISP-PACKAGE: package (not its name) in which LISP-FUN-NAME will be interned
SAFETY: if T, adds an additional line in the function asking to import the
package or function, so that the function works even after PYSTOP is called.
However, this increases the overhead of stream communication, and therefore,
can reduce speed.
import-export.lisp (file)
Each ARG is supposed to be a 2-3 element list of
(pyfun-name pymodule-name) or (pyfun-name pymodule-name lisp-fun-name).
In addition, when ARG is a 2-element list, then, the first element can be
a list of python function names.
import-export.lisp (file)
Import a python module (and its submodules) lisp-package Lisp package(s).
Example:
(py4cl:defpymodule "math" :lisp-package "M")
(m:sqrt 4) ; => 2.0
"Package already exists." is returned if the package exists and :RELOAD
is NIL.
Arguments:
PYMODULE-NAME: name of the module in python, before importing
IMPORT-SUBMODULES: leave nil for purposes of speed, if you won’t use the
submodules
LISP-PACKAGE: lisp package, in which to intern (and export) the callables
RELOAD: whether to redefine and reimport
SAFETY: value of safety to pass to defpyfun; see defpyfun
SILENT: prints "status" lines when NIL
import-export.lisp (file)
Gets the output of the python program executed in FORMS-DECL in the form a string.
python-process.lisp (file)
Ensures that all values returned by python functions
and methods are kept in python, and only handles returned to lisp.
This is useful if performing operations on large datasets.
callpython.lisp (file)
Ensures that all values returned by python functions
and methods are kept in python, and only handles returned to lisp.
This is useful if performing operations on large datasets. Unlike
with-remote-objects, evaluates the last result and returns not just a handle.
callpython.lisp (file)
Next: Exported generic functions, Previous: Exported macros, Up: Exported definitions [Contents][Index]
callpython.lisp (file)
Returns the value associated with VAR in *CONFIG*.
Configuration variables include (all in PY4CL2 package):
- PYCMD: Path to the python binary to be used
- NUMPY-PICKLE-LOCATION: PY4CL2 uses pickled files to transfer large arrays between lisp
and python efficiently. These can have sizes exceeding 100MB. It is recommended that this
be set to path on a ram-disk. See [this](https://unix.stackexchange.com/questions/66329/creating-a-ram-disk-on-linux) for
instructions on creating a ram-disk on linux-based systems.
- NUMPY-PICKLE-LOWER-BOUND: The minimum size of the array for which PY4CL2 should use pickled files.
- USE-NUMCL-ARRAYS: NUMCL uses displaced arrays. If this variable is T and the system PY4CL2+NUMCL is loaded, arrays returned by python process are passed through NUMCL:ASARRAY before returning them to the user.
config.lisp (file)
(setf config-var) (function)
Sets the value of VAR to NEW-VALUE in *CONFIG*. For all but PYCMD, the values are saved to a configuration-file for persistence whenever they are changed. To persist PYCMD, call SAVE-CONFIG.
config.lisp (file)
config-var (function)
Makes a lisp FUNCTION available in python process as PYTHON-NAME
import-export.lisp (file)
Intended to be called first upon installation. Sets up default python command, and numpy pickle file and lower bounds.
config.lisp (file)
Load to *CONFIG* from /home/quickref/quicklisp/dists/quicklisp/software/py4cl2-v2.6.0/src/../.config
config.lisp (file)
config.lisp (file)
Calls FUN-NAME with ARGS as arguments. Arguments can be keyword based, or otherwise.
callpython.lisp (file)
Calls python eval on args; PYTHONIZEs arg if it satisfies PYTHONIZEP.
Eg.
> (let ((a 5)) (pyeval a "*" a))
25
callpython.lisp (file)
(setf pyeval) (function)
Set an expression to a value. Just adds "=" and the value
to the end of the expression. Note that the result is evaluated
with exec rather than eval.
Example:
(setf (pyeval "a") 2) ; python "a=2"
Can be useful for modifying a value directly in python.
callpython.lisp (file)
pyeval (function)
Calls python exec on args; PYTHONIZEs arg if it satisfies PYTHONIZEP.
callpython.lisp (file)
callpython.lisp (file)
callpython.lisp (file)
Issues a SIGINT command to the python process
python-process.lisp (file)
PYCALLs METHOD of OBJECT with ARGS
Examples:
> (pymethod "’hello {0}’" ’format "world")
"hello world"
> (pymethod ’(1 2 3) ’–len–)
3
Note: FUN-NAME is NOT PYTHONIZEd if it is a string.
callpython.lisp (file)
import-export.lisp (file)
import-export.lisp (file)
callpython.lisp (file)
Start a new python subprocess
This sets the global variable *python* to the process handle,
in addition to returning it.
COMMAND is a string with the python executable to launch e.g. "python"
By default this is is set to *PYTHON-COMMAND*
python-process.lisp (file)
Stop (Quit) the python process PROCESS
python-process.lisp (file)
Returns non-NIL if the python process is alive
(e.g. SBCL -> T, CCL -> RUNNING).
Optionally pass the process object returned by PYTHON-START
python-process.lisp (file)
If no python process is running, tries to start it. If still not alive, raises a condition.
python-process.lisp (file)
Return a list, using the result of python’s sys.version_info.
callpython.lisp (file)
Calls python eval on the concatenation of strings, as they are, without any pythonization or modification.
callpython.lisp (file)
(setf raw-pyeval) (function)
callpython.lisp (file)
raw-pyeval (function)
Calls python exec on the concatenation of strings, as they are, without any
pythonization or modification.
NOTE: Like usual, there are peculiarities to exec commands.
For instance,
import sys
def foo:
sys.stdout.write(’hello’)
foo()
will result in ’sys’ name not defined PYERROR.
callpython.lisp (file)
Save to /home/quickref/quicklisp/dists/quicklisp/software/py4cl2-v2.6.0/src/../.config from *CONFIG*
config.lisp (file)
Next: Exported conditions, Previous: Exported functions, Up: Exported definitions [Contents][Index]
Called when python accesses an object’s slot (__getattr__)
lisp-classes.lisp (file)
Called when python sets an object’s slot (__setattr__)
lisp-classes.lisp (file)
Convert an object into a string which can be written to stream. Default implementation creates a handle to an unknown Lisp object.
writer.lisp (file)
Handle ratios, using Python’s Fraction if available
A handle for a python object, stored in a dict in Python
Handle a function by converting to a callback object
The lisp function is stored in the same object store as other objects.
Convert hash-table to python map. Produces a string {key1:value1, key2:value2,}
One-to-one mapping between python name and lisp symbol names:
symbol : symbol-name : python-name
’foo-bar : "FOO-BAR" : foo_bar
’|Foo-Bar| : "Foo-Bar" : Foo_Bar
’*foo-bar* : "*FOO-BAR*" : FOO_BAR
t : "T" : True
nil : "NIL" : False
Convert a list. This leaves a trailing comma so that python evals a list with a single element as a tuple
Create string of the form "(1+2j".
If imaginary part is negative the output is of form "(1+-2j"
which is interpreted correctly by python (3.7.2).
Write a real number.
Note that python doesn’t handle ’d’,’f’, ’s’ or ’L’ exponent markers
Previous: Exported generic functions, Up: Exported definitions [Contents][Index]
callpython.lisp (file)
error (condition)
text (method)
:text
text (generic function)
callpython.lisp (file)
end-of-file (condition)
python-process (method)
:python-process
python-process (generic function)
callpython.lisp (file)
end-of-file (condition)
python-process (method)
:python-process
python-process (generic function)
python-process.lisp (file)
error (condition)
command (method)
:command
command (generic function)
Previous: Exported definitions, Up: Definitions [Contents][Index]
• Internal constants | ||
• Internal special variables | ||
• Internal macros | ||
• Internal functions | ||
• Internal generic functions | ||
• Internal structures |
Next: Internal special variables, Previous: Internal definitions, Up: Internal definitions [Contents][Index]
config.lisp (file)
Next: Internal macros, Previous: Internal constants, Up: Internal definitions [Contents][Index]
Internal variable used for coordinating between DEFPYMODULE and DEFPYFUN.
import-export.lisp (file)
A number which changes when python is started. This
is used to prevent garbage collection from deleting objects in the wrong
python session
python-process.lisp (file)
features.lisp (file)
A list of handles to be freed. This is used because garbage collection may occur in parallel with the main thread.
reader.lisp (file)
String pyexec-ed at the start of a DEFPYFUN when SAFETY is T.
import-export.lisp (file)
writer.lisp (file)
python-process.lisp (file)
Used for coordinating import statements from defpymodule while calling recursively
import-export.lisp (file)
writer.lisp (file)
Internal variable used by PYMODULE-IMPORT-STRING to determine the import string.
import-export.lisp (file)
writer.lisp (file)
Used for transferring multiple numpy-pickled arrays in one pyeval/exec/etc
writer.lisp (file)
python-process.lisp (file)
Most recently started python subprocess
python-process.lisp (file)
python-process.lisp (file)
python-process.lisp (file)
python-process.lisp (file)
Used by pyinterrupt to determine if python process is waiting for input, or
is busy processing.
A possible workaround is to use strace.
See https://askubuntu.com/questions/1118109/how-do-i-tell-if-a-command-is-running-or-waiting-for-user-input
python-process.lisp (file)
python-process.lisp (file)
Next: Internal functions, Previous: Internal special variables, Up: Internal definitions [Contents][Index]
import-export.lisp (file)
Next: Internal generic functions, Previous: Internal macros, Up: Internal definitions [Contents][Index]
callpython.lisp (file)
callpython.lisp (file)
Returns ((h e l l o) (W o r l d)), given (h e l l o W o r l d).
import-export.lisp (file)
Some builtin functions like ’sum’ do not take keyword args.
import-export.lisp (file)
Clear the *lisp-objects* object store, allowing them to be GC’d
writer.lisp (file)
Returns ((h e l l o) W o r l d), given (h e l l o W o r l d).
import-export.lisp (file)
reader.lisp (file)
import-export.lisp (file)
reader.lisp (file)
Delete pickled arrays, to free space.
reader.lisp (file)
Read response from python, loop to handle any callbacks
callpython.lisp (file)
callpython.lisp (file)
Remove an object with HANDLE from the hash table
writer.lisp (file)
reader.lisp (file)
import-export.lisp (file)
import-export.lisp (file)
Returns a list of two lists: PARAMETER-LIST and PASS_LIST
import-export.lisp (file)
import-export.lisp (file)
Get the lisp object corresponding to HANDLE
writer.lisp (file)
Converts NAME to a lisp-like name. Specifically:
1. Replaces underscores with hyphens.
2. CamelCase is converted to CAMEL-CASE
import-export.lisp (file)
reader.lisp (file)
Make a PYTHON-OBJECT struct with a finalizer.
This deletes the object from the dict store in python.
Uses trivial-garbage (public domain)
reader.lisp (file)
import-export.lisp (file)
features.lisp (file)
Store OBJECT and return a handle
writer.lisp (file)
import-export.lisp (file)
reader.lisp (file)
reader.lisp (file)
reader.lisp (file)
import-export.lisp (file)
Intended as an abstraction to RAW-PYEVAL and RAW_PYEXEC. Passes strings as they are, without any ’pythonize’ation.
callpython.lisp (file)
import-export.lisp (file)
Reads a string from a stream
Expects a line containing the number of chars following
e.g. ’5~%hello’
Returns the string or nil on error
reader.lisp (file)
Get a value from a stream
Currently works by reading a string then using read-from-string
reader.lisp (file)
Write a string to a stream, putting the length first
writer.lisp (file)
Write a value to a stream, in a format which can be read by the python subprocess as the corresponding python type
writer.lisp (file)
config.lisp (file)
Next: Internal structures, Previous: Internal functions, Up: Internal definitions [Contents][Index]
python-process.lisp (file)
callpython.lisp (file)
callpython.lisp (file)
callpython.lisp (file)
Previous: Internal generic functions, Up: Internal definitions [Contents][Index]
A handle for a python object
which couldn’t be translated into a Lisp value.
TYPE slot is the python type string
HANDLE slot is a unique key used to refer to a value in python.
reader.lisp (file)
structure-object (structure)
pythonize (method)
string
""
python-object-type (function)
(setf python-object-type) (function)
python-object-handle (function)
(setf python-object-handle) (function)
Previous: Definitions, Up: Top [Contents][Index]
• Concept index | ||
• Function index | ||
• Variable index | ||
• Data type index |
Next: Function index, Previous: Indexes, Up: Indexes [Contents][Index]
Jump to: | F L P S |
---|
Jump to: | F L P S |
---|
Next: Variable index, Previous: Concept index, Up: Indexes [Contents][Index]
Jump to: | %
(
B C D E F G I L M N O P R S T W |
---|
Jump to: | %
(
B C D E F G I L M N O P R S T W |
---|
Next: Data type index, Previous: Function index, Up: Indexes [Contents][Index]
Jump to: | *
+
C H P S T |
---|
Jump to: | *
+
C H P S T |
---|
Previous: Variable index, Up: Indexes [Contents][Index]
Jump to: | C P S |
---|
Jump to: | C P S |
---|