Skip to content

Commit

Permalink
Chore: Many small corrections and Nada Numpy update to 2.0.0 (#52)
Browse files Browse the repository at this point in the history
* chore: updated numpy to version 2.0.0

* chore: added optional dependencies for examples and linting

* fix: added .gitignore to prevent not found file errors

* fix: Added linear_regression to testing infrastructure

* chore: bump version number
  • Loading branch information
jcabrero authored Jul 30, 2024
1 parent 17b8eca commit fbacdd2
Show file tree
Hide file tree
Showing 38 changed files with 384 additions and 155 deletions.
4 changes: 2 additions & 2 deletions examples/broadcasting/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import asyncio

import nada_numpy.client as na_client
import numpy as np
import py_nillion_client as nillion
from common.utils import compute, store_program, store_secret_array
from config import DIM
from cosmpy.aerial.client import LedgerClient
from cosmpy.aerial.wallet import LocalWallet
Expand All @@ -20,7 +20,7 @@
get_quote_and_pay, pay_with_quote)
from py_nillion_client import NodeKey, UserKey

from common.utils import compute, store_program, store_secret_array
import nada_numpy.client as na_client

home = os.getenv("HOME")
load_dotenv(f"{home}/.config/nillion/nillion-devnet.env")
Expand Down
5 changes: 3 additions & 2 deletions examples/broadcasting/src/broadcasting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

from typing import List

# Step 0: Nada Numpy is imported with this line
import nada_numpy as na
from config import DIM
from nada_dsl import Output, SecretInteger

# Step 0: Nada Numpy is imported with this line
import nada_numpy as na


def nada_main() -> List[Output]:
"""
Expand Down
5 changes: 3 additions & 2 deletions examples/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import time
from typing import Any, Callable, Dict, List

import nada_numpy as na
import nada_numpy.client as na_client
import numpy as np
import py_nillion_client as nillion
from cosmpy.aerial.client import LedgerClient
Expand All @@ -14,6 +12,9 @@
create_payments_config, get_quote,
get_quote_and_pay, pay_with_quote)

import nada_numpy as na
import nada_numpy.client as na_client


def async_timer(file_path: os.PathLike) -> Callable:
"""
Expand Down
5 changes: 2 additions & 3 deletions examples/dot_product/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import asyncio

import nada_numpy.client as na_client
import numpy as np
import py_nillion_client as nillion
from common.utils import compute, store_program, store_secret_array
from config import DIM
from cosmpy.aerial.client import LedgerClient
from cosmpy.aerial.wallet import LocalWallet
Expand All @@ -20,11 +20,10 @@
get_quote_and_pay, pay_with_quote)
from py_nillion_client import NodeKey, UserKey

from common.utils import compute, store_program, store_secret_array
import nada_numpy.client as na_client

home = os.getenv("HOME")
load_dotenv(f"{home}/.config/nillion/nillion-devnet.env")
# load_dotenv(f"/workspaces/ai/.nillion-testnet.env")


# Main asynchronous function to coordinate the process
Expand Down
2 changes: 1 addition & 1 deletion examples/dot_product/src/dot_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from typing import List

from config import DIM
from nada_dsl import Output, SecretInteger

# Step 0: Nada Numpy is imported with this line
import nada_numpy as na
from nada_dsl import Output, SecretInteger


def nada_main() -> List[Output]:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import asyncio

import nada_numpy.client as na_client
import numpy as np
import py_nillion_client as nillion
from common.utils import compute, store_program, store_secret_array
from cosmpy.aerial.client import LedgerClient
from cosmpy.aerial.wallet import LocalWallet
from cosmpy.crypto.keypairs import PrivateKey
Expand All @@ -20,12 +20,10 @@
from py_nillion_client import NodeKey, UserKey
from sklearn.linear_model import Ridge

from common.utils import compute, store_program, store_secret_array
import nada_numpy.client as na_client

home = os.getenv("HOME")

load_dotenv(f"{home}/.config/nillion/nillion-devnet.env")
# load_dotenv(f"/workspaces/ai/.nillion-testnet.env")


# Main asynchronous function to coordinate the process
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import nada_numpy as na
import numpy as np
from nada_dsl import *

import nada_numpy as na
from nada_numpy.array import NadaArray


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import nada_numpy as na
import numpy as np
from modular_inverse import PRIME, public_modular_inverse
from nada_dsl import *

import nada_numpy as na

# from nada_crypto import random_lu_matrix, public_modular_inverse


Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import nada_numpy as na
import numpy as np
from determinant import determinant
from gauss_jordan import gauss_jordan_zn
from modular_inverse import (PRIME, private_modular_inverse,
public_modular_inverse)
from nada_dsl import *

import nada_numpy as na
from nada_numpy.array import NadaArray


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import nada_numpy as na
import numpy as np
from nada_dsl import *

import nada_numpy as na
from nada_numpy.array import NadaArray

# LOG_SCALE = 8
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import time

import nada_numpy as na
import numpy as np
from nada_dsl import *

import nada_numpy as na
from nada_numpy.array import NadaArray

LOG_SCALE = 16
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import nada_numpy as na
import numpy as np
from nada_dsl import *

import nada_numpy as na

LOG_SCALE = 16
SCALE = 1 << LOG_SCALE
PRIME_64 = 18446744072637906947
Expand Down
5 changes: 5 additions & 0 deletions examples/linear_regression/target/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This directory is kept purposely, so that no compilation errors arise.
# Ignore everything in this directory
*
# Except this file
!.gitignore
38 changes: 38 additions & 0 deletions examples/linear_regression/tests/linear_regression_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
program: linear_regression
inputs:
A_0_0:
SecretInteger: "-256"
A_0_1:
SecretInteger: "-199"
A_0_2:
SecretInteger: "-142"
A_1_0:
SecretInteger: "-85"
A_1_1:
SecretInteger: "-28"
A_1_2:
SecretInteger: "28"
A_2_0:
SecretInteger: "85"
A_2_1:
SecretInteger: "142"
A_2_2:
SecretInteger: "256"
b_0:
SecretInteger: "-256"
b_1:
SecretInteger: "-199"
b_2:
SecretInteger: "-142"
# lambda_0:
# Integer: "1"
expected_outputs:
b:
SecretInteger: "330643400256"
w_0:
SecretInteger: "1102041164640"
w_1:
SecretInteger: "-993683999568"
w_2:
SecretInteger: "1868226984"
5 changes: 2 additions & 3 deletions examples/matrix_multiplication/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import asyncio

import nada_numpy.client as na_client
import numpy as np
import py_nillion_client as nillion
from common.utils import compute, store_program, store_secret_array
from config import DIM
from cosmpy.aerial.client import LedgerClient
from cosmpy.aerial.wallet import LocalWallet
Expand All @@ -20,11 +20,10 @@
get_quote_and_pay, pay_with_quote)
from py_nillion_client import NodeKey, UserKey

from common.utils import compute, store_program, store_secret_array
import nada_numpy.client as na_client

home = os.getenv("HOME")
load_dotenv(f"{home}/.config/nillion/nillion-devnet.env")
# load_dotenv(f"/workspaces/ai/.nillion-testnet.env")


# Main asynchronous function to coordinate the process
Expand Down
5 changes: 3 additions & 2 deletions examples/matrix_multiplication/src/matrix_multiplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

from typing import List

# Step 0: Nada Numpy is imported with this line
import nada_numpy as na
from config import DIM
from nada_dsl import Output, SecretInteger

# Step 0: Nada Numpy is imported with this line
import nada_numpy as na


def nada_main() -> List[Output]:
"""
Expand Down
5 changes: 2 additions & 3 deletions examples/rational_numbers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import asyncio

import nada_numpy.client as na_client
import numpy as np
import py_nillion_client as nillion
from common.utils import compute, store_program, store_secret_value
from cosmpy.aerial.client import LedgerClient
from cosmpy.aerial.wallet import LocalWallet
from cosmpy.crypto.keypairs import PrivateKey
Expand All @@ -18,11 +18,10 @@
create_payments_config)
from py_nillion_client import NodeKey, UserKey

from common.utils import compute, store_program, store_secret_value
import nada_numpy.client as na_client

home = os.getenv("HOME")
load_dotenv(f"{home}/.config/nillion/nillion-devnet.env")
# load_dotenv(f"/workspaces/ai/.nillion-testnet.env")


# Main asynchronous function to coordinate the process
Expand Down
3 changes: 2 additions & 1 deletion examples/rational_numbers/src/rational_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from typing import List

import nada_numpy as na
from nada_dsl import Output

import nada_numpy as na


def nada_main() -> List[Output]:
"""
Expand Down
24 changes: 1 addition & 23 deletions nada_numpy/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# pylint:disable=too-many-lines

from typing import Any, Callable, Optional, Sequence, Union, get_args, overload
from typing import Any, Callable, Optional, Sequence, Union, get_args

import numpy as np
from nada_dsl import (Boolean, Input, Integer, Output, Party, PublicInteger,
Expand Down Expand Up @@ -870,28 +870,6 @@ def item(self, *args, **kwargs):
return NadaArray(result)
return result

@overload
def itemset(self, value: Any): ...
@overload
def itemset(self, item: Any, value: Any): ...

# pylint:disable=missing-function-docstring
@copy_metadata(np.ndarray.itemset)
def itemset(self, *args, **kwargs):
value = None
if len(args) == 1:
value = args[0]
elif len(args) == 2:
value = args[1]
else:
value = kwargs["value"]

_check_type_compatibility(value, self.dtype)
result = self.inner.itemset(*args, **kwargs)
if isinstance(result, np.ndarray):
return NadaArray(result)
return result

# pylint:disable=missing-function-docstring
@copy_metadata(np.ndarray.prod)
def prod(self, *args, **kwargs):
Expand Down
Loading

0 comments on commit fbacdd2

Please sign in to comment.