Skip to content

Commit

Permalink
Kpandl/python sdk doc 1 (#293)
Browse files Browse the repository at this point in the history
* getting started with python sdk documentation

* improve python sdk doc

* transpiler description

* minor changes

* revert change
  • Loading branch information
kpandl authored Oct 10, 2023
1 parent 8aaf0d3 commit b45ddae
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 1 deletion.
16 changes: 15 additions & 1 deletion documentation/00_sdk_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The Aleo SDK is divided into three Typescript/Javascript packages
<a href="https://www.npmjs.com/package/@aleohq/sdk"> <img alt="Aleo SDK" src="https://img.shields.io/npm/l/%40aleohq%2Fsdk?label=NPM%20-%20Aleo%20SDK&labelColor=green&color=blue" /></a>


The official Aleo SDK providing Javascript/Typescript tools for creating zero knowledge app.
The official Aleo SDK providing Javascript/Typescript tools for creating zero knowledge apps.

### ⚡ Build your own app

Expand Down Expand Up @@ -69,6 +69,20 @@ NodeJS is functional.

Source: [`sdk/wasm`](https://github.com/AleoHQ/sdk/tree/testnet3/wasm)

## 4. Aleo Python SDK - Zero Knowledge Algorithms in Python and Zero Knowledge Machine Learning

The official Aleo Python SDK providing tools for creating zero knowledge apps. It consists of two separate libraries:

* The **aleo** library, which uses foreign function interfaces to bring snarkVM functionalities to Python.
* The **zkml** library, which transpiles scikit-learn machine learning models into Leo programs for inference.

Both libraries are in an early development stage. They can be installed through `pip install aleo` respectively `pip install zkml`. The
[documentation on the aleo library](./sdk/python/00_aleo_sdk.md) and the [documentation on the zkml library](./sdk/python/01_zkml_transpiler.md) provide more information on installation and usage.

<!-- markdown-link-check-disable -->
Source: [`python-sdk`](https://github.com/AleoHQ/python-sdk)
<!-- markdown-link-check-enable -->

## 📚 Documentation

#### [API Documentation](https://developer.aleo.org)
Expand Down
62 changes: 62 additions & 0 deletions documentation/sdk/python/00_aleo_sdk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
id: aleo-sdk
title: Aleo SDK
sidebar_label: Aleo SDK
---

<!-- markdown-link-check-disable -->
[![github]](https://github.com/AleoHQ/python-sdk/tree/master/sdk)
<!-- markdown-link-check-enable -->

[github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github

[**aleo on PyPI**](https://pypi.org/project/aleo/)

Aleo Python bindings for building zero-knowledge applications.

This project uses `PyO3` and `Maturin` to provide a Python library named `aleo` that binds to `snarkVM` Rust functionalities. The resulting `aleo` library can be easily installed and used within Python. The project is at an early stage. At the moment, only Mac OS 11 or newer on Apple Silicon is supported - support for other operating systems will follow. If you are using another operating system, you may be able to build the library yourself following the instructions below.

Supported functionalities currently include:
* Private key generation

## Usage
The `aleo` Python library is available on [PyPI](https://pypi.org/project/aleo/) for installation.

### Installation
Ensure you have Python 3.11 or newer installed. If your operating system is supported, you can install the library from pip:

```bash
pip3 install aleo
```

<!-- markdown-link-check-disable -->
Alternatively, you can also install from a `.whl` file, either from the [GitHub repository](https://github.com/AleoHQ/python-sdk/tree/master/sdk/target/wheels), or by building it yourself. For the installation, use a command like this:
<!-- markdown-link-check-enable -->

```bash
pip3 install aleo-0.0.3-cp311-cp311-macosx_11_0_arm64.whl
```

Note: On some systems, you may need to use `pip` instead of `pip3`.

### Example use
You can import the library, generate a private key object, and print it as a string as in the following example:
```Python
import aleo
private_key = aleo.PrivateKey()
print(private_key.to_string())
```

<!-- markdown-link-check-disable -->
### Build Instructions
To build it, first clone the [GitHub repository](https://github.com/AleoHQ/python-sdk/tree/master/sdk). Then, run the following command:
```bash
bash build.sh
```
<!-- markdown-link-check-enable -->

After successful building, you will find a new `.whl` file in the `target/wheels` directory that you can install using the command from above.

## Building Python Apps

Further documentation and tutorials as to how to use the `aleo` Python library will follow soon.
82 changes: 82 additions & 0 deletions documentation/sdk/python/01_zkml_transpiler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
id: zkml-transpiler
title: zkml transpiler
sidebar_label: zkml Transpiler
---

<!-- markdown-link-check-disable -->
[![github]](https://github.com/AleoHQ/python-sdk/tree/master/zkml)
<!-- markdown-link-check-enable -->

[github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github

[**zkml on PyPI**](https://pypi.org/project/zkml/)

Aleo transpiler for building zero-knowledge machine learning applications.

This project provides a Python library named `zkml` that transpiles `scikit-learn` machine learning models into a `Leo` project for inference. The resulting leo project can then be run and executed from Python. The project is at an early stage.

Supported functionalities currently include:
* Decision tree classifiers

## Usage
The `zkml` Python library is available on [PyPI](https://pypi.org/project/zkml/) for installation.

### Prerequisites
#### Python
Ensure you have 3.9.6 or newer installed.
- Verify with:
```bash
python3 --version
```
- If not installed, follow the instructions [here](https://wiki.python.org/moin/BeginnersGuide/Download).

#### Leo
Ensure you have Leo version 1.9.3 or newer installed.
- Verify with:
```bash
leo --version
```
- If necessary, update:
```bash
leo update
```
- Installation guide: [Leo Installation](./../../leo/01_installation.md)

### Installation

You can install the `zkml` Python library from PyPI using the following command:
```bash
pip3 install zkml
```

<!-- markdown-link-check-disable -->
Note: On some systems, you may need to use `pip` instead of `pip3`.
Alternatively, you can also install through the `.whl` file or in editable mode from the [GitHub repository](https://github.com/AleoHQ/python-sdk/tree/master/zkml).
<!-- markdown-link-check-enable -->

### Usage

<!-- markdown-link-check-disable -->
Below is a brief description of the classes and functions provided by the library. Detailed documentation is in progress and will be available soon.
We encourage you to also check out the [examples on GitHub](https://github.com/AleoHQ/python-sdk/tree/master/zkml/examples).
<!-- markdown-link-check-enable -->

* In a first step, you can receive an object of the class `zkml.LeoTranspiler(model, validation_data)`
* For the `model` parameter, pass the trained scikit-learn model
* For the `validation_data` parameter, pass the training or validation dataset. While this parameter is not strictly required, we recommend using it. The dataset is used to compute a fixed-point scaling factor and the required Leo integer types. Using the parameter helps to ensure numerical stability in the inference computation. The larger the dataset, the better.
* In a second step, you can start the transpilation process through `leo_transpiler.to_leo(path, project_name, model_as_input)`
* For the `path` parameter, pass the path where the new leo project should be stored in
* For the `project_name` parameter, pass the desired name of the leo project.
* The Boolean `model_as_input` parameter is optional and by default `False`. If set to `False`, the model parameters (i.e., thresholds, weights, biases) are hardcoded in the Leo code. If set to `True`, these model parameters are treated as additional circuit inputs.
* After transpiling, you can run the computation of the Leo project through `leo_transpiler.run(input)`, and receive an object of class `LeoComputation`
* For the `input` parameter, pass the inference data sample or dataset
* Similarly, after transpiling, you can execute the Leo project through `leo_transpiler.execute(input)`, and receive an object of class `ZeroKnowledgeProof`
* For the `input` parameter, pass the inference data sample or dataset

## Building Python Apps

<!-- markdown-link-check-disable -->
Please check out the [examples on GitHub](https://github.com/AleoHQ/python-sdk/tree/master/zkml/examples).
Further documentation and tutorials as to how to use the `zkml` Python library will follow soon.
<!-- markdown-link-check-enable -->

0 comments on commit b45ddae

Please sign in to comment.