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

Update to Torch > 2.2, Smartnoise-SQL 1.0.4 #601

Merged
merged 4 commits into from
Jul 30, 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
7 changes: 7 additions & 0 deletions synth/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# SmartNoise Synth v1.0.4 Release Notes

* Use newer faker versions
* Support Python 3.12
* Switch to use SmartNoise SQL v1.0.4
* Switch to torch >=2.2.0

# SmartNoise Synth v1.0.3 Release Notes

* Switch to use SmartNoise SQL v1.0.3
Expand Down
2 changes: 1 addition & 1 deletion synth/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.3
1.0.4
13 changes: 7 additions & 6 deletions synth/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "smartnoise-synth"
version = "1.0.3"
version = "1.0.4"
description = "Differentially Private Synthetic Data"
authors = ["SmartNoise Team <smartnoise@opendp.org>"]
license = "MIT"
Expand All @@ -10,15 +10,16 @@ repository = "https://github.com/opendp/smartnoise-sdk"
readme = "README.md"

[tool.poetry.dependencies]
python = ">=3.7,<=3.11"
python = ">=3.9,<3.13"
opacus = "^0.14.0"
torch = "<2.0.0"
torch = {version = ">=2.2.0", optional = true}
pac-synth = "^0.0.8"
smartnoise-sql = "^1.0.3"
Faker = "^15.0.0"
smartnoise-sql = "^1.0.4"
Faker = ">=17.0.0"
private-pgm = { git = "https://github.com/ryan112358/private-pgm.git", rev = "01f02f17eba440f4e76c1d06fa5ee9eed0bd2bca" }

[tool.poetry.dev-dependencies]

[build-system]
requires = ["setuptools", "poetry-core>=1.0.0"]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
42 changes: 0 additions & 42 deletions synth/setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion synth/tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ mlflow
scikit-learn
numpy
pytest
git+https://github.com/ryan112358/private-pgm.git
git+https://github.com/ryan112358/private-pgm.git@01f02f17eba440f4e76c1d06fa5ee9eed0bd2bca
5 changes: 3 additions & 2 deletions synth/tests/test_aggregate_seeded.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import json
import pytest


from snsynth.transform.table import NoTransformer

def gen_data_frame_with_schema(schema, n_records):
Expand Down Expand Up @@ -57,8 +58,8 @@ def gen_data_frame(number_of_records_to_generate):
)


class TestAggregateSeeded:
def setup(self):
class TestAggregateSeeded():
def setup_method(self):
self.sensitive_df = gen_data_frame(10000)

def test_synth_creation_with_default_params(self):
Expand Down
2 changes: 1 addition & 1 deletion synth/tests/test_aim.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestAIM(TestCase):
aim = None

@classmethod
def setUpClass(cls) -> None:
def setup_class(cls) -> None:
cls.example_df = pd.read_csv(cls.input_data_path)
cls.aim = AIMSynthesizer()

Expand Down
3 changes: 2 additions & 1 deletion synth/tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import subprocess
import pandas as pd
from sklearn import preprocessing
from unittest import TestCase
from snsynth import *

git_root_dir = subprocess.check_output("git rev-parse --show-toplevel".split(" ")).decode("utf-8").strip()
Expand All @@ -10,7 +11,7 @@

df = pd.read_csv(csv_path, index_col=None)

class TestFactory:
class TestFactory(TestCase):
def test_create_empty(self):
for synth in Synthesizer.list_synthesizers():
_ = Synthesizer.create(synth, epsilon=1.0)
Expand Down
3 changes: 2 additions & 1 deletion synth/tests/test_input_checks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import pandas as pd


from snsynth.pytorch import PytorchDPSynthesizer
from snsynth.pytorch.nn import PATECTGAN, PATEGAN

Expand All @@ -13,7 +14,7 @@
)


class TestDPGANInputChecks:
class TestDPGANInputChecks():
def test_train_patectgan_continuous(self):
dpgan = PATECTGAN(epsilon=eps, batch_size=batch_size)
try:
Expand Down
11 changes: 8 additions & 3 deletions synth/tests/test_mst.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import subprocess
import os


import numpy as np
import pandas as pd

Expand All @@ -14,10 +15,14 @@
df = df.drop(["income"], axis=1)
df = df.sample(frac=1, random_state=42)

class TestMST:
class TestMST():

def setup(self):
self.mst = MSTSynthesizer()
@classmethod
def setup_class(cls) -> None:
print("Setting up class")
cls.mst = MSTSynthesizer()
print("Setup class")
print(cls.mst)

def test_fit(self):
self.df_non_continuous = df[['sex','educ','race','married']]
Expand Down
2 changes: 1 addition & 1 deletion synth/tests/test_mwem.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

test_histogram_dims = (3,3,3)

class TestMWEM:
class TestMWEM():
def test_short_import_works(self):
assert MWEMSynthesizer == ShortMWEMSynthesizer

Expand Down
5 changes: 3 additions & 2 deletions synth/tests/test_pategan.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import string
import pandas as pd


# try:
from snsynth.pytorch import PytorchDPSynthesizer
from snsynth.pytorch.nn import PATEGAN
Expand All @@ -21,8 +22,8 @@
df = pd.read_csv(csv_path)

@pytest.mark.torch
class TestDPGAN:
def setup(self):
class TestDPGAN():
def setup_method(self):
self.pategan = PytorchDPSynthesizer(1.0, PATEGAN(1.0), None)

def test_fit(self):
Expand Down
17 changes: 9 additions & 8 deletions synth/tests/test_pytorch_synthesizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
import pandas as pd


from snsynth.pytorch import PytorchDPSynthesizer
from snsynth.pytorch.nn import DPGAN, DPCTGAN, PATECTGAN
from snsynth.transform.table import TableTransformer
Expand All @@ -26,8 +27,8 @@


@pytest.mark.torch
class TestPytorchDPSynthesizer_DPGAN:
def setup(self):
class TestPytorchDPSynthesizer_DPGAN():
def setup_method(self):
self.dpgan = PytorchDPSynthesizer(1.0, DPGAN(), None)

def test_fit(self):
Expand All @@ -52,8 +53,8 @@ def test_fit_continuous(self):
assert synth_data.shape == df_continuous.shape


class TestPytorchDPSynthesizer_DPCTGAN:
def setup(self):
class TestPytorchDPSynthesizer_DPCTGAN():
def setup_method(self):
self.dpctgan = PytorchDPSynthesizer(1.0, DPCTGAN(), None)

def test_fit(self):
Expand Down Expand Up @@ -81,8 +82,8 @@ def test_fit_numpy(self):
dpctgan.train(nf_non_continuous, preprocessor_eps=0.5, categorical_columns=[0, 1, 2, 3])


class TestPytorchDPSynthesizer_PATECTGAN:
def setup(self):
class TestPytorchDPSynthesizer_PATECTGAN():
def setup_method(self):
self.patectgan = PytorchDPSynthesizer(1.0, PATECTGAN(), None)

def test_fit(self):
Expand All @@ -106,8 +107,8 @@ def test_sample(self):
assert synth_data.shape == df.shape


class TestPytorchDPSynthesizer_PATECTDRAGAN:
def setup(self):
class TestPytorchDPSynthesizer_PATECTDRAGAN():
def setup_method(self):
self.patectgan = PytorchDPSynthesizer(
1.0, PATECTGAN(regularization="dragan"), None
)
Expand Down
5 changes: 3 additions & 2 deletions synth/tests/test_quail.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
import pandas as pd


from diffprivlib.models import LogisticRegression as DPLR

from snsynth.pytorch import PytorchDPSynthesizer
Expand All @@ -24,8 +25,8 @@


@pytest.mark.torch
class TestQUAIL:
def setup(self):
class TestQUAIL():
def setup_method(self):
def QuailClassifier(epsilon):
return DPLR(epsilon=epsilon)

Expand Down
2 changes: 1 addition & 1 deletion synth/tests/test_sample_conditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
narrow_df = pd.read_csv(csv_path, index_col=None, usecols=narrrow_columns)


class TestSampleConditional:
class TestSampleConditional():
def test_n_row_invalid(self):
dummy_synth = Synthesizer()
for n_row in [-np.inf, -1, 0, 0.9]:
Expand Down
Loading