Skip to content

Commit

Permalink
Merge pull request #96 from NillionNetwork/0.6.0
Browse files Browse the repository at this point in the history
0.6.0
  • Loading branch information
oceans404 authored Sep 5, 2024
2 parents 127c5a7 + 34d8bb2 commit c63ec5e
Show file tree
Hide file tree
Showing 9 changed files with 626 additions and 819 deletions.
1 change: 1 addition & 0 deletions docs/_operations-table.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
| [Reveal](/nada-by-example/reveal) <br/> (convert a private<br/> value into a public value) | `x.reveal()` | `P ← S.reveal()` |
| [Equality](/nada-by-example/equality) | `x == y` | `S ← S == S`,<br/> `S ← S == P`,<br/> `S ← P == S`,<br/> `P ← P == P` |
| [Public Output Equality](/nada-by-example/equality) <br/> (publicly output if two secrets are equal) | `x.public_equals(y)` | `P ← S.public_equals(S)` |
| [Not](/nada-by-example/not) | `~bool` | `S ← ~S`,<br/> `P ← ~P` |
4 changes: 2 additions & 2 deletions docs/nada-by-example/first-program.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ https://github.com/NillionNetwork/nada-by-example/blob/main/src/addition.py#L4-L

### Inputs

An `Input` is a value provided to a Nada program by a specific party. Inputs are wrapped with one of the following `Public` or `Secret` data types:
An `Input` is a value provided to a Nada program by a specific party. Inputs are wrapped with one of the following `Public` or `Secret` modes:

| `Public` | `Secret` |
| ----------------------- | ----------------------- |
Expand All @@ -62,7 +62,7 @@ https://github.com/NillionNetwork/nada-by-example/blob/main/src/addition.py#L7-L

### Operations

An operation is a computation performed on inputs to produce a result. In Nada, operations can be performed on both public and secret data types. Check out the full list of available [Nada operations here](/nada-by-example/nada-operations).
An operation is a computation performed on inputs to produce a result. In Nada, operations can be performed on both public and secret modes. Check out the full list of available [Nada operations here](/nada-by-example/nada-operations).

The addition program involves one operation, addition, to sum the 2 secret inputs.

Expand Down
8 changes: 4 additions & 4 deletions docs/nada-by-example/nada-data-types.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import NadaDataTypesTable from '../\_data-types-table.mdx';

# Primitive Data Types
# Primitive Modes and Data Types

This chart shows the primitive data types available in Nada. Each data type links to example Nada programs.
This chart displays the primitive data types available in Nada, categorized by mode. The modes link to Nada program examples for each data type.

<NadaDataTypesTable/>

[Secret](/nada-by-example/secret-data-type) and [Public](/nada-by-example/public-data-type) data types are used to specify user inputs to a Nada program.
[Secret](/nada-by-example/secret-data-type) and [Public](/nada-by-example/public-data-type) modes specify whether user inputs to a Nada program are treated as secret (private) or public data.

[Literals](/nada-by-example/literal-data-type) can only be used within a Nada program.
[Literals](/nada-by-example/literal-data-type) are constants that can only be used within a Nada program and are not tied to specific user inputs.
29 changes: 29 additions & 0 deletions docs/nada-by-example/not.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Not

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import TestProgram from '@site/src/components/TestProgram/index';

The NOT operator, represented by the tilde symbol (~), is used in the Nada DSL to invert or negate a boolean value. When applied to a boolean expression, the ~ operator flips its value—turning True to False and False to True.

<Tabs>

<TabItem value="program" label="Nada program" default>
```python reference showGithubLink
https://github.com/NillionNetwork/nada-by-example/blob/main/src/not.py
```
</TabItem>

<TabItem value="tie" label="Test 1">
```yaml reference showGithubLink
https://github.com/NillionNetwork/nada-by-example/blob/main/tests/not_test_1.yaml
```
</TabItem>
<TabItem value="rock" label="Test 2">
```yaml reference showGithubLink
https://github.com/NillionNetwork/nada-by-example/blob/main/tests/not_test_2.yaml
```
</TabItem>
</Tabs>

<TestProgram programName="not" testFileName="not_test_1"/>
53 changes: 53 additions & 0 deletions docs/nada-by-example/shuffle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Shuffle

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import TestProgram from '@site/src/components/TestProgram/index';


## Simple Shuffle

This example uses the [nada-numpy](/nada-numpy-introduction) shuffle implementation to shuffle an array of four secret integers and return the shuffled values. This process preserves the original elements but places them in a different order.

<Tabs>

<TabItem value="program" label="Nada program" default>
```python reference showGithubLink
https://github.com/NillionNetwork/nada-by-example/blob/main/src/shuffle_simple.py
```
</TabItem>

<TabItem value="test" label="Test">
```yaml reference showGithubLink
https://github.com/NillionNetwork/nada-by-example/blob/main/tests/shuffle_simple_test.yaml
```
</TabItem>
<TabItem value="nada_test" label="nada-test">
```python reference showGithubLink
https://github.com/NillionNetwork/nada-by-example/blob/main/tests/shuffle_simple_test.py
```
</TabItem>
</Tabs>

<TestProgram programName="shuffle_simple" testFileName="shuffle_simple_test"/>

## More Shuffle Examples

This example demonstrates how the [nada-numpy](/nada-numpy-introduction) shuffling operation supports multiple data types, including Rational, SecretRational, PublicInteger, and SecretInteger. Shuffling can be applied using two approaches: the `shuffle()` function or the built-in `.shuffle()` method on arrays.

<Tabs>

<TabItem value="program" label="Nada program" default>
```python reference showGithubLink
https://github.com/NillionNetwork/nada-by-example/blob/main/src/shuffle.py
```
</TabItem>

<TabItem value="test" label="Test">
```yaml reference showGithubLink
https://github.com/NillionNetwork/nada-by-example/blob/main/tests/shuffle_test.yaml
```
</TabItem>
</Tabs>

<TestProgram programName="shuffle" testFileName="shuffle_test"/>
100 changes: 100 additions & 0 deletions docs/nada-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# nada-test: Nada Testing Framework

[nada-test](https://pypi.org/project/nada-test) is a powerful and flexible testing framework for Nada programs. It enables developers to write dynamic tests that are generated at runtime, offering more flexibility than traditional YAML test files.

#### Features

- Dynamic test generation at runtime
- Easy-to-write test functions using Python
- Seamless integration with `nada` projects
- Support for both standalone usage and integration with pytest
- Flexible input and output specification for test cases

## Installation

You can install [nada-test](https://pypi.org/project/nada-test) in a Nada project using pip:

```bash
pip install nada-test
```

## Setup

To use nada-test as your test framework, you’ll need to configure it in your nada-project.toml file. This allows the nada test command to automatically run your tests using the nada-test framework. Here’s how you can set it up:

<Tabs>
<TabItem value="basic" label="Basic configuration" default>
Add the following to your nada-project.toml file to set nada-test as your default test runner and point it to the ./tests directory:
```toml
[test_framework.nada-test]
command = "nada-test ./tests"
```

This setup ensures that all tests inside the ./tests directory will be executed when you run nada test.
</TabItem>

<TabItem value="custom" label="Custom test directories">
If you have tests in multiple directories, you can specify them in the configuration as well:

```toml
[test_framework.nada-test]
command = "nada-test ./custom_tests ./more_tests"
```

This allows you to organize your tests across different directories, and nada test will run all tests from the specified paths.
</TabItem>
</Tabs>


## Writing tests

You can use nada-test to write both functional and class-based tests for your programs. Tests are decorated with `@nada_test(program="program_name")` to specify which program is being tested. Below are two examples showing how to test a basic addition program.

Tests should be written in a Python file located in the directory you specified during the setup (e.g., ./tests or any custom test directory). Below are examples of how to test a basic addition program using both styles.

### Functional style test

<Tabs>
<TabItem value="test" label="nada-test file" default>
```python reference showGithubLink
https://github.com/NillionNetwork/nada-by-example/blob/main/tests/addition_test.py#L4-L11
```
</TabItem>

<TabItem value="program" label="Nada program">
```python reference showGithubLink
https://github.com/NillionNetwork/nada-by-example/blob/main/src/addition.py
```
</TabItem>
</Tabs>

### Class-based test


<Tabs>
<TabItem value="test" label="nada-test file" default>
```python reference showGithubLink
https://github.com/NillionNetwork/nada-by-example/blob/main/tests/addition_test.py#L13-L21
```
</TabItem>

<TabItem value="program" label="Nada program">
```python reference showGithubLink
https://github.com/NillionNetwork/nada-by-example/blob/main/src/addition.py
```
</TabItem>
</Tabs>


## Running tests

After writing your tests in the specified directories, you can run them using the following command:

```
nada test
```

This will execute all the tests configured in your nada-project.toml file. The output will show you the results of your test suite.
168 changes: 168 additions & 0 deletions sidebar-nada-by-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
module.exports = [
{
type: 'html',
className: 'sidebar-title',
value: 'Nada by Example',
defaultStyle: true,
},
{
type: 'doc',
label: 'Introduction',
id: 'nada-by-example',
},
'nada-by-example/first-program',
{
type: 'doc',
label: 'How to Run Examples',
id: 'nada-by-example-quickstart',
},
'nada-by-example/debugging',
{
type: 'link',
label: 'Ask a Nada Question',
href: 'https://github.com/orgs/NillionNetwork/discussions/categories/q-a',
},
{
type: 'html',
className: 'sidebar-title',
value: 'Nada Program Examples',
defaultStyle: true,
},
{
type: 'category',
label: 'Primitive Data Types',
link: {
type: 'doc',
id: 'nada-by-example/nada-data-types',
},
items: [
'nada-by-example/secret-data-type',
'nada-by-example/public-data-type',
'nada-by-example/literal-data-type',
],
},
{
type: 'category',
label: 'Nada Operations',
link: {
type: 'doc',
id: 'nada-by-example/nada-operations',
},
items: [
'nada-by-example/addition',
'nada-by-example/subtraction',
'nada-by-example/multiplication',
'nada-by-example/division',
'nada-by-example/power',
'nada-by-example/modulo',
'nada-by-example/shift-left',
'nada-by-example/shift-right',
'nada-by-example/probabilistic-truncation',
'nada-by-example/comparison',
'nada-by-example/equality',
'nada-by-example/not',
'nada-by-example/if-else',
'nada-by-example/reveal',
],
},
'nada-by-example/list-comprehensions',
'nada-by-example/for-loop',
'nada-by-example/helper-function',
'nada-by-example/reduce',
'nada-by-example/random-number',
'nada-by-example/linear-scan',
'nada-by-example/shuffle',
'nada-by-example/square-root',
'nada-by-example/cube-root',
'nada-by-example/arg-max',
'nada-by-example/variance',
'nada-by-example/standard-deviation',
'nada-by-example/cardio-risk',
'nada-by-example/voting',
'nada-by-example/r-p-s',
{
type: 'link',
label: 'Request an Example',
href: 'https://github.com/nillionnetwork/nada-by-example/issues/new/choose',
},
{
type: 'html',
className: 'sidebar-title',
value: 'Examples with Nada Libraries',
defaultStyle: true,
},
{
type: 'category',
label: 'Nada AI',
collapsible: true,
collapsed: false,
link: {
type: 'doc',
id: 'nada-by-example/nada-ai',
},
items: [
{
type: 'link',
label: 'Linear Regression',
href: 'https://github.com/NillionNetwork/nada-ai/tree/main/examples/linear_regression',
},
{
type: 'link',
label: 'Neural Network',
href: 'https://github.com/NillionNetwork/nada-ai/tree/main/examples/neural_net',
},
{
type: 'link',
label: 'Complex Model',
href: 'https://github.com/NillionNetwork/nada-ai/tree/main/examples/complex_model',
},
{
type: 'link',
label: 'Time Series',
href: 'https://github.com/NillionNetwork/nada-ai/tree/main/examples/time_series',
},
{
type: 'link',
label: 'Spam Detection',
href: 'https://github.com/NillionNetwork/nada-ai/tree/main/examples/spam_detection',
},
{
type: 'link',
label: 'Convolutional Neural Network',
href: 'https://github.com/NillionNetwork/nada-ai/tree/main/examples/conv_net',
},
],
},
{
type: 'category',
label: 'Nada Numpy',
collapsible: true,
collapsed: false,
link: {
type: 'doc',
id: 'nada-by-example/nada-numpy',
},
items: [
{
type: 'link',
label: 'Dot Product',
href: 'https://github.com/NillionNetwork/nada-numpy/tree/main/examples/dot_product',
},
{
type: 'link',
label: 'Matrix Multiplication',
href: 'https://github.com/NillionNetwork/nada-numpy/tree/main/examples/matrix_multiplication',
},
{
type: 'link',
label: 'Broadcasting',
href: 'https://github.com/NillionNetwork/nada-numpy/tree/main/examples/broadcasting',
},
{
type: 'link',
label: 'Rational Numbers',
href: 'https://github.com/NillionNetwork/nada-numpy/tree/main/examples/rational_numbers',
},
],
},
];
Loading

0 comments on commit c63ec5e

Please sign in to comment.