7.2.2. Calling the Python APIs - 5.2 English - 57404

AOCL User Guide (57404)

Document ID
57404
Release Date
2025-12-29
Version
5.2 English

The AOCL-DA Python package comes with several example scripts. To locate them, the following commands can be run in your Python interpreter.

from aoclda.examples import info

info.examples_path()
info.examples_list()

Alternatively, from your command prompt the command python -m aocl.examples.info will print the same information.

For existing scikit-learn users, you can “patch” your python code to use AOCL-DA where it is available by inserting the following lines prior to your scikit-learn import lines:

from aoclda.sklearn import skpatch, undo_skpatch
skpatch()

You can switch back to standard scikit-learn using

undo_skpatch()

Note that after calling undo_skpatch, you must reimport scikit-learn.

The skpatch and undo_skpatch functions can also be called with string or list arguments, specifying which scikit-learn package should be patched, for example:

skpatch("PCA")
skpatch(["LinearRegression", "Ridge"])

Alternatively, you can use the aoclda.sklearn module from the command line, without making any changes to your own code:

python -m aoclda.sklearn your_python_script.py
python -m aoclda.sklearn -m your_python_module

For scikit-learn classes that use n_jobs to specify the number of threads, instead use the OMP_NUM_THREADS environment variable to control the number of threads used by AOCL-DA.

Note that only a subset of the AOCL-DA functionality is available in this manner. For a full list of the supported classes and methods, please refer to the API guide at https://docs.amd.com/r/en-US/68552-AOCL-api-guide/AOCL-Data-Analytics. If, after patching, you attempt to call scikit-learn class member functions which have not been implemented in AOCL-DA, then a RuntimeError will be thrown. Note that Python support on Windows is currently experimental with certain functionality (the nonlinear least squares and LBFGSB solvers) not available.