Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use key to access column in computation #55

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ def user_computation(s: State, data: list[torch.Tensor]) -> torch.Tensor:
For example, we have two columns of data and we want to compute the mean of the medians of the two columns:

```python
def user_computation(s: State, data: list[torch.Tensor]) -> torch.Tensor:
def user_computation(s: State, data: Args) -> torch.Tensor:
# Compute the median of the first column
median1 = s.median(data[0])
median1 = s.median(data['column1'])
# Compute the median of the second column
median2 = s.median(data[1])
median2 = s.median(data['column2'])
# Compute the mean of the medians
return s.mean(torch.cat((median1.unsqueeze(0), median2.unsqueeze(0))).reshape(1,-1,1))
```
Expand All @@ -74,9 +74,9 @@ TODO: We should have a list for all supported PyTorch functions.
Although we cannot filter data into any arbitrary shape using just condition + index (e.g. `X[X > 0]`), we implemented State.where operation that allows users to filter data by their own choice of condition as follows.

```python
def user_computation(s: State, data: list[torch.Tensor]) -> torch.Tensor:
def user_computation(s: State, data: Args) -> torch.Tensor:
# Compute the mean of the absolute values
x = data[0]
x = data['x']
# Here condition can be chained as shown below, and can have many variables if we have more than just x: e.g. filter = torch.logical_and(x>20, y<2) in case of regression for example.
filter = torch.logical_and(x > 20, x<50)
# call our where function
Expand Down Expand Up @@ -116,9 +116,9 @@ Note here, that we can also just let prover generate model, and then send that m
```python
from zkstats.core import computation_to_model
# For prover: generate prover_model, and write to precal_witness file
_, prover_model = computation_to_model(user_computation, precal_witness_path, True, error)
_, prover_model = computation_to_model(user_computation, precal_witness_path, True, selected_columns, error)
# For verifier, generate verifier model (which is same as prover_model) by reading precal_witness file
_, verifier_model = computation_to_model(user_computation, precal_witness_path, False, error)
_, verifier_model = computation_to_model(user_computation, precal_witness_path, False, selected_columns, error)
```

#### Data Provider: generate settings
Expand Down
2 changes: 1 addition & 1 deletion examples/1.only_torch/only_torch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False,error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path,verifier_model, verifier_model_path)"
]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/2.torch+state/torch+state.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False,error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path,verifier_model, verifier_model_path)"
]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/3.state/state.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False,error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path,verifier_model, verifier_model_path)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/correlation/correlation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"\n",
"error = 0.01\n",
"# Prover/ data owner side\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, error)\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, selected_columns, error)\n",
"prover_gen_settings(data_path, selected_columns, sel_data_path, prover_model, prover_model_path, scales, \"resources\", settings_path)\n"
]
},
Expand All @@ -167,7 +167,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False,error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path,verifier_model, verifier_model_path)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/covariance/covariance.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"\n",
"error = 0.01\n",
"# Prover/ data owner side\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, error)\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, selected_columns, error)\n",
"prover_gen_settings(data_path, selected_columns, sel_data_path, prover_model, prover_model_path, scales, \"resources\", settings_path)\n"
]
},
Expand All @@ -163,7 +163,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False,error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path,verifier_model, verifier_model_path)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/geomean/geomean.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
" return s.geometric_mean(x)\n",
"\n",
"error = 0.01\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, error)\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, selected_columns, error)\n",
"prover_gen_settings(data_path, selected_columns, sel_data_path, prover_model, prover_model_path, scales, \"resources\", settings_path)"
]
},
Expand All @@ -164,7 +164,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False,error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path,verifier_model, verifier_model_path)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/harmomean/harmomean.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
"error = 0.1\n",
"\n",
"# Prover/ data owner side\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, error)\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, selected_columns, error)\n",
"prover_gen_settings(data_path, selected_columns, sel_data_path, prover_model, prover_model_path, scales, \"resources\", settings_path)\n",
"\n"
]
Expand All @@ -161,7 +161,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False,error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path,verifier_model, verifier_model_path)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/mean/mean.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
"\n",
"\n",
"# Prover/ data owner side\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, error)\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, selected_columns, error)\n",
"prover_gen_settings(data_path, selected_columns, sel_data_path, prover_model, prover_model_path, scales, \"resources\", settings_path)\n",
"\n"
]
Expand All @@ -186,7 +186,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False,error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path,verifier_model, verifier_model_path)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/median/median.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"# error here in Median only matters in determining the median value in case it doesnt exist in dataset. (Avg of 2 middle values)\n",
"error = 0.01\n",
"# Prover/ data owner side\n",
"_, prover_model = computation_to_model(computation,precal_witness_path, True, error)\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, selected_columns, error)\n",
"\n",
"prover_gen_settings(data_path, selected_columns, sel_data_path, prover_model,prover_model_path, scales, \"resources\", settings_path)"
]
Expand All @@ -165,7 +165,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path, verifier_model, verifier_model_path)"
]
Expand Down
4 changes: 2 additions & 2 deletions examples/mode/mode.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"error = 0\n",
"\n",
"# Prover/ data owner side\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, error)\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, selected_columns, error)\n",
"prover_gen_settings(data_path, selected_columns, sel_data_path, prover_model, prover_model_path, scales, \"resources\", settings_path)\n",
"\n"
]
Expand All @@ -168,7 +168,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False,error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path,verifier_model, verifier_model_path)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/pstdev/pstdev.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
"error = 0.01\n",
"\n",
"# Prover/ data owner side\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, error)\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, selected_columns, error)\n",
"prover_gen_settings(data_path, selected_columns, sel_data_path, prover_model, prover_model_path, scales, \"resources\", settings_path)\n",
"\n"
]
Expand All @@ -146,7 +146,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False,error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path,verifier_model, verifier_model_path)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/pvariance/pvariance.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
"error = 0.01\n",
"\n",
"# Prover/ data owner side\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, error)\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, selected_columns, error)\n",
"prover_gen_settings(data_path, selected_columns, sel_data_path, prover_model, prover_model_path, scales, \"resources\", settings_path)\n",
"\n"
]
Expand All @@ -147,7 +147,7 @@
"outputs": [],
"source": [
"# Prover/ data owner side\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False,error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path,verifier_model, verifier_model_path)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/regression/regression.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
" return s.linear_regression(x, y)\n",
"\n",
"error = 0.05\n",
"_, prover_model = computation_to_model(computation,precal_witness_path, True, error)\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, selected_columns, error)\n",
"\n",
"prover_gen_settings(data_path, selected_columns, sel_data_path, prover_model,prover_model_path, scales, \"resources\", settings_path)"
]
Expand All @@ -153,7 +153,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path, verifier_model, verifier_model_path)"
]
Expand Down
4 changes: 2 additions & 2 deletions examples/stdev/stdev.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
"\n",
"error = 0.01\n",
"# Prover/ data owner side\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, error)\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, selected_columns, error)\n",
"prover_gen_settings(data_path, selected_columns, sel_data_path, prover_model, prover_model_path, scales, \"resources\", settings_path)\n",
"\n"
]
Expand All @@ -145,7 +145,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False,error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path,verifier_model, verifier_model_path)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/variance/variance.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
"\n",
"error = 0.01\n",
"# Prover/ data owner side\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, error)\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, selected_columns, error)\n",
"prover_gen_settings(data_path, selected_columns, sel_data_path, prover_model, prover_model_path, scales, \"resources\", settings_path)\n",
"\n"
]
Expand All @@ -145,7 +145,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False,error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path,verifier_model, verifier_model_path)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/where/where+correlation/where+correlation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
" return s.correlation(filtered_x, filtered_y)\n",
"\n",
"error = 0.01\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, error)\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, selected_columns, error)\n",
"prover_gen_settings(data_path, selected_columns, sel_data_path, prover_model, prover_model_path, scales, \"resources\", settings_path)\n"
]
},
Expand All @@ -177,7 +177,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False,error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path,verifier_model, verifier_model_path)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/where/where+covariance/where+covariance.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
"\n",
"error = 0.01\n",
"\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, error)\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, selected_columns, error)\n",
"prover_gen_settings(data_path, selected_columns, sel_data_path, prover_model, prover_model_path, scales, \"resources\", settings_path)\n",
"\n"
]
Expand All @@ -170,7 +170,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False,error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path,verifier_model, verifier_model_path)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/where/where+geomean/where+geomean.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
"\n",
"error = 0.01\n",
"\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, error)\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, selected_columns, error)\n",
"prover_gen_settings(data_path, selected_columns, sel_data_path, prover_model, prover_model_path, scales, \"resources\", settings_path)\n"
]
},
Expand All @@ -169,7 +169,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False,error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path,verifier_model, verifier_model_path)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/where/where+harmomean/where+harmomean.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"\n",
"error = 0.1\n",
"\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, error)\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, selected_columns, error)\n",
"prover_gen_settings(data_path, selected_columns, sel_data_path, prover_model, prover_model_path, scales, \"resources\", settings_path)\n"
]
},
Expand All @@ -163,7 +163,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False,error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path,verifier_model, verifier_model_path)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/where/where+mean/where+mean.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"\n",
"error = 0.01\n",
"\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, error)\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, selected_columns, error)\n",
"prover_gen_settings(data_path, selected_columns, sel_data_path, prover_model, prover_model_path, scales, \"resources\", settings_path)\n",
"\n"
]
Expand All @@ -156,7 +156,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False,error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path,verifier_model, verifier_model_path)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/where/where+median/where+median.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
" return s.median(filtered_x)\n",
"\n",
"error = 0.01\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, error)\n",
"_, prover_model = computation_to_model(computation, precal_witness_path, True, selected_columns, error)\n",
"prover_gen_settings(data_path, selected_columns, sel_data_path, prover_model, prover_model_path, scales, \"resources\", settings_path)\n",
"\n"
]
Expand All @@ -165,7 +165,7 @@
"metadata": {},
"outputs": [],
"source": [
"_, verifier_model = computation_to_model(computation, precal_witness_path, False,error)\n",
"_, verifier_model = computation_to_model(computation, precal_witness_path, False, selected_columns, error)\n",
"verifier_define_calculation(dummy_data_path, selected_columns, sel_dummy_data_path,verifier_model, verifier_model_path)"
]
},
Expand Down
Loading
Loading