Skip to content

Commit a3ff011

Browse files
Latest experimental (#47)
* chore: updated examples yaml files to support new format * chore: fix Nada Numpy client update * fix: tests not added to battery of tests * chore: updated broadcasting example to latest version * feat: updated commons folder * feat: translated all examples network interaction * fix: poetry.lock update * Remove is-zero check * feat: added linear regression example * chore: Added linear-regression example * chore: version bump to 0.3.0 * chore: various fixes and readd zero-check * fix: fix README.md back to public version --------- Co-authored-by: Mathias Leys <mathias.leys@nillion.com>
1 parent 342a411 commit a3ff011

File tree

82 files changed

+3843
-1641
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+3843
-1641
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/NillionNetwork/nada-numpy/test.yml?style=for-the-badge&logo=python&logoColor=white&link=https%3A%2F%2Fgithub.com%2FNillionNetwork%2Fnada-numpy%2Factions%2Fworkflows%2Ftest.yml&link=https%3A%2F%2Fgithub.com%2FNillionNetwork%2Fnada-numpy%2Factions%2Fworkflows%2Ftest.yml)
55
![GitHub Release](https://img.shields.io/github/v/release/NillionNetwork/nada-numpy?sort=date&display_name=release&style=for-the-badge&logo=dependabot&label=LATEST%20RELEASE&color=0000FE&link=https%3A%2F%2Fpypi.org%2Fproject%2Fnada-numpy&link=https%3A%2F%2Fpypi.org%2Fproject%2Fnada-numpy)
66

7-
7+
# WARNING: THIS VERSION DOES NOT INSTALL `nada_dsl` and `py_nillion_client` by default as it needs to be installed by `nilup`.
88
Nada-Numpy is a Python library designed for algebraic operations on NumPy-like array objects on top of Nada DSL and Nillion Network. It provides a simple and intuitive interface for performing various algebraic computations, including dot products, element-wise operations, and stacking operations, while supporting broadcasting similar to NumPy arrays.
99

1010
## Features

examples/broadcasting/main.py

Lines changed: 89 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,91 +3,133 @@
33
import os
44
import sys
55

6-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
6+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
77

88
import asyncio
99

1010
import numpy as np
1111
import py_nillion_client as nillion
12+
from common.utils import compute, store_program, store_secret_array
13+
from config import DIM
14+
from cosmpy.aerial.client import LedgerClient
15+
from cosmpy.aerial.wallet import LocalWallet
16+
from cosmpy.crypto.keypairs import PrivateKey
1217
from dotenv import load_dotenv
13-
from nillion_python_helpers import (create_nillion_client, getNodeKeyFromFile,
14-
getUserKeyFromFile)
18+
from nillion_python_helpers import (create_nillion_client,
19+
create_payments_config, get_quote,
20+
get_quote_and_pay, pay_with_quote)
21+
from py_nillion_client import NodeKey, UserKey
1522

1623
import nada_numpy.client as na_client
17-
# Import helper functions for creating nillion client and getting keys
18-
from examples.broadcasting.config import DIM
19-
from examples.common.utils import compute, store_program, store_secret_array
2024

21-
# Load environment variables from a .env file
22-
load_dotenv()
25+
home = os.getenv("HOME")
26+
load_dotenv(f"/workspaces/ai/.nillion-testnet.env")
2327

2428

2529
# Main asynchronous function to coordinate the process
2630
async def main() -> None:
2731
"""Main nada program"""
2832

29-
print(f"USING: {DIM} dims")
30-
3133
cluster_id = os.getenv("NILLION_CLUSTER_ID")
32-
userkey = getUserKeyFromFile(os.getenv("NILLION_USERKEY_PATH_PARTY_1"))
33-
nodekey = getNodeKeyFromFile(os.getenv("NILLION_NODEKEY_PATH_PARTY_1"))
34+
grpc_endpoint = os.getenv("NILLION_NILCHAIN_GRPC")
35+
chain_id = os.getenv("NILLION_NILCHAIN_CHAIN_ID")
36+
seed = "my_seed"
37+
userkey = UserKey.from_seed((seed))
38+
nodekey = NodeKey.from_seed((seed))
3439
client = create_nillion_client(userkey, nodekey)
3540
party_id = client.party_id
3641
user_id = client.user_id
42+
3743
party_names = na_client.parties(3)
3844
program_name = "broadcasting"
3945
program_mir_path = f"target/{program_name}.nada.bin"
4046

41-
# Store the program
47+
# Create payments config and set up Nillion wallet with a private key to pay for operations
48+
payments_config = create_payments_config(chain_id, grpc_endpoint)
49+
payments_client = LedgerClient(payments_config)
50+
payments_wallet = LocalWallet(
51+
PrivateKey(bytes.fromhex(os.getenv("NILLION_NILCHAIN_PRIVATE_KEY_0"))),
52+
prefix="nillion",
53+
)
54+
55+
##### STORE PROGRAM
56+
print("-----STORE PROGRAM")
57+
4258
program_id = await store_program(
43-
client, user_id, cluster_id, program_name, program_mir_path
59+
client,
60+
payments_wallet,
61+
payments_client,
62+
user_id,
63+
cluster_id,
64+
program_name,
65+
program_mir_path,
4466
)
4567

46-
# Create and store secrets for two parties
68+
##### STORE SECRETS
69+
print("-----STORE SECRETS")
4770
A = np.ones([DIM])
4871
C = np.ones([DIM])
49-
A_store_id = await store_secret_array(
72+
73+
# Create a permissions object to attach to the stored secret
74+
permissions = nillion.Permissions.default_for_user(client.user_id)
75+
permissions.add_compute_permissions({client.user_id: {program_id}})
76+
77+
# Create a secret
78+
store_id_A = await store_secret_array(
5079
client,
80+
payments_wallet,
81+
payments_client,
5182
cluster_id,
5283
program_id,
53-
party_id,
54-
party_names[0],
5584
A,
5685
"A",
5786
nillion.SecretInteger,
87+
1,
88+
permissions,
5889
)
59-
C_store_id = await store_secret_array(
90+
91+
store_id_C = await store_secret_array(
6092
client,
93+
payments_wallet,
94+
payments_client,
6195
cluster_id,
6296
program_id,
63-
party_id,
64-
party_names[0],
6597
C,
6698
"C",
6799
nillion.SecretInteger,
100+
1,
101+
permissions,
68102
)
69103

104+
# Create and store secrets for two parties
105+
70106
B = np.ones([DIM])
71107
D = np.ones([DIM])
72-
B_store_id = await store_secret_array(
108+
109+
store_id_B = await store_secret_array(
73110
client,
111+
payments_wallet,
112+
payments_client,
74113
cluster_id,
75114
program_id,
76-
party_id,
77-
party_names[1],
78115
B,
79116
"B",
80117
nillion.SecretInteger,
118+
1,
119+
permissions,
81120
)
82-
D_store_id = await store_secret_array(
121+
122+
store_id_D = await store_secret_array(
83123
client,
124+
payments_wallet,
125+
payments_client,
84126
cluster_id,
85127
program_id,
86-
party_id,
87-
party_names[1],
88128
D,
89129
"D",
90130
nillion.SecretInteger,
131+
1,
132+
permissions,
91133
)
92134

93135
# Set up the compute bindings for the parties
@@ -99,19 +141,35 @@ async def main() -> None:
99141

100142
print(f"Computing using program {program_id}")
101143
print(
102-
f"Use secret store_id: {A_store_id}, {B_store_id}, {C_store_id}, {D_store_id}"
144+
f"Use secret store_id: {store_id_A}, {store_id_B}, {store_id_C}, {store_id_D}"
103145
)
104146

105-
computation_time_secrets = nillion.Secrets({"my_int2": nillion.SecretInteger(10)})
147+
##### COMPUTE
148+
print("-----COMPUTE")
149+
150+
# Bind the parties in the computation to the client to set input and output parties
151+
compute_bindings = nillion.ProgramBindings(program_id)
152+
compute_bindings.add_input_party(party_names[0], party_id)
153+
compute_bindings.add_input_party(party_names[1], party_id)
154+
compute_bindings.add_output_party(party_names[2], party_id)
155+
156+
# Create a computation time secret to use
157+
computation_time_secrets = nillion.NadaValues({})
158+
159+
# Get cost quote, then pay for operation to compute
106160

107-
# Perform the computation and return the result
108161
result = await compute(
109162
client,
163+
payments_wallet,
164+
payments_client,
165+
program_id,
110166
cluster_id,
111167
compute_bindings,
112-
[A_store_id, B_store_id, C_store_id, D_store_id],
168+
[store_id_A, store_id_B, store_id_C, store_id_D],
113169
computation_time_secrets,
170+
verbose=1,
114171
)
172+
115173
return result
116174

117175

examples/broadcasting/tests/broadcasting.yaml

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
---
22
program: broadcasting
33
inputs:
4-
secrets:
5-
B_1:
6-
SecretInteger: "3"
7-
A_0:
8-
SecretInteger: "3"
9-
C_1:
10-
SecretInteger: "3"
11-
B_0:
12-
SecretInteger: "3"
13-
D_0:
14-
SecretInteger: "3"
15-
C_2:
16-
SecretInteger: "3"
17-
C_0:
18-
SecretInteger: "3"
19-
A_2:
20-
SecretInteger: "3"
21-
A_1:
22-
SecretInteger: "3"
23-
D_1:
24-
SecretInteger: "3"
25-
B_2:
26-
SecretInteger: "3"
27-
D_2:
28-
SecretInteger: "3"
29-
public_variables: {}
4+
B_1:
5+
SecretInteger: "3"
6+
A_0:
7+
SecretInteger: "3"
8+
C_1:
9+
SecretInteger: "3"
10+
B_0:
11+
SecretInteger: "3"
12+
D_0:
13+
SecretInteger: "3"
14+
C_2:
15+
SecretInteger: "3"
16+
C_0:
17+
SecretInteger: "3"
18+
A_2:
19+
SecretInteger: "3"
20+
A_1:
21+
SecretInteger: "3"
22+
D_1:
23+
SecretInteger: "3"
24+
B_2:
25+
SecretInteger: "3"
26+
D_2:
27+
SecretInteger: "3"
28+
3029
expected_outputs:
3130
my_output_1:
3231
SecretInteger: "-3"

0 commit comments

Comments
 (0)