Skip to content

Commit

Permalink
create_dummy
Browse files Browse the repository at this point in the history
  • Loading branch information
mhchia committed Sep 15, 2024
1 parent 3901444 commit 2ff30a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
4 changes: 2 additions & 2 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import torch

from zkstats.core import prover_gen_settings, setup, prover_gen_proof, verifier_verify, generate_data_commitment, verifier_define_calculation
from zkstats.computation import computation_to_model, TComputation, State, IModel
from zkstats.core import prover_gen_settings, setup, prover_gen_proof, verifier_verify, generate_data_commitment
from zkstats.computation import IModel


DEFAULT_POSSIBLE_SCALES = list(range(20))
Expand Down
29 changes: 12 additions & 17 deletions zkstats/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,21 @@ def verifier_define_calculation(
_export_onnx(verifier_model, dummy_data_tensor_array, verifier_model_path)


# TODO: Should only need the shape of data instead of the real dataset, since
# users (verifiers) call this function and they don't have the real data.
def create_dummy(data_path: str, dummy_data_path: str) -> None:
def create_dummy(shape_info: dict[str, int], dummy_data_path: str) -> None:
"""
Create a dummy data file with randomized data based on the shape of the original data.
"""
# Convert data file to json under the same directory but with suffix .json
data_path: Path = Path(data_path)
data_json_path = Path(data_path).with_suffix(DataExtension.JSON.value)
Create a dummy data file with randomized data based on the provided shape information.
data = json.loads(open(data_json_path, "r").read())
# assume all columns have same number of rows
dummy_data ={}
for col in data:
# not use same value for every column to prevent something weird, like singular matrix
min_col = min(data[col])
max_col = max(data[col])
dummy_data[col] = np.round(np.random.uniform(min_col,max_col,len(data[col])),1).tolist()
Parameters:
- shape_info (dict): A dictionary where keys are column names and values are the number of elements (shape).
- dummy_data_path (str): The path to save the dummy data file.
"""
dummy_data = {}
for col, length in shape_info.items():
# Generate random data for each column
dummy_data[col] = np.round(np.random.uniform(0, 100, length), 1).tolist()

json.dump(dummy_data, open(dummy_data_path, 'w'))
with open(dummy_data_path, 'w') as f:
json.dump(dummy_data, f)

# ===================================================================================================
# ===================================================================================================
Expand Down

0 comments on commit 2ff30a9

Please sign in to comment.