Skip to content

Commit edac2c6

Browse files
Ryan McKennacopybara-github
authored andcommitted
Update github workflow to include static analysis checks. Delete test.sh and lint.sh, and move its logic to the ci.yml file.
PiperOrigin-RevId: 859707838
1 parent 6ab5ef4 commit edac2c6

File tree

13 files changed

+45
-234
lines changed

13 files changed

+45
-234
lines changed

.github/workflows/ci.yml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,37 @@ jobs:
2121
- uses: "actions/setup-python@v6"
2222
with:
2323
python-version: "${{ matrix.python-version }}"
24-
- name: Run CI tests
25-
run: bash test.sh
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install build wheel
28+
pip install pylint pytype flake8 pylint-exit
29+
pip install -e .[dev]
30+
pip install -r docs/requirements.txt
31+
pip install crc32c
32+
- name: Run flake8
33+
run: flake8 jax_privacy tests examples
34+
- name: Run pylint
35+
run: |
36+
pylint --ignore=auditing.py --rcfile=.pylintrc jax_privacy || pylint-exit -efail -wfail -cfail -rfail $?
37+
# pylint --rcfile=.pylintrc examples || pylint-exit -efail -wfail -cfail -rfail $?
38+
# pylint --rcfile=.pylintrc tests -d W0212,C0114 || pylint-exit -efail -wfail -cfail -rfail $?
2639
shell: bash
40+
- name: Run pytype
41+
run: |
42+
pytype jax_privacy -k
43+
pytype tests -k
44+
pytype examples -k
45+
-name: Run doctests
46+
run: |
47+
pytest --doctest-modules jax_privacy/
48+
- name: Run tests
49+
run: |
50+
pytest -n auto tests/ -k "not matrix_factorization and not distributed_noise_generation_test and not sharding_utils_test"
51+
pytest -n auto tests/ -k "distributed_noise_generation_test"
52+
pytest -n auto tests/ -k "sharding_utils_test"
53+
export HYPOTHESIS_PROFILE=dpftrl_default
54+
pytest -n auto tests/ -k "matrix_factorization" --ignore=tests/matrix_factorization/buffered_toeplitz_test.py
55+
shell: bash
56+
- name: Build docs
57+
run: sphinx-build -W -b html docs/ docs/_build/html

MANIFEST.in

Lines changed: 0 additions & 1 deletion
This file was deleted.

conftest.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

jax_privacy/batch_selection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def batch_iterator(
293293

294294
@dataclasses.dataclass(frozen=True)
295295
class UserSelectionStrategy:
296-
"""Applies base_strategy at the user level, and selects multiple examples per user.
296+
"""Applies base_strategy at user level, selecting multiple examples per user.
297297
298298
Each batch returned by the batch_iterator is a 2D array of integer indices,
299299
where all entries in the same row are examples owned by the same user. The

jax_privacy/clipping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __call__(self, *args, **kwargs):
5555

5656
def sensitivity(
5757
self,
58-
neighboring_relation: dp_accounting.NeighboringRelation = _REPLACE_SPECIAL,
58+
neighboring_relation: dp_accounting.NeighboringRelation = _REPLACE_SPECIAL
5959
):
6060
"""Returns the L2 sensitivity of the Callable.
6161

jax_privacy/experimental/accounting.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,21 @@
2020
>>> import dp_accounting
2121
>>> event = dpsgd_event(noise_multiplier=3, iterations=512, sampling_prob=0.1)
2222
>>> accountant = dp_accounting.pld.PLDAccountant()
23-
>>> accountant.compose(event).get_epsilon(target_delta=1e-6)
24-
3.769686577205207
23+
>>> epsilon = accountant.compose(event).get_epsilon(target_delta=1e-6)
24+
>>> round(epsilon, 2)
25+
3.77
2526
2627
Example Usage (Calibrating Noise Multiplier for DP-SGD):
2728
2829
>>> make_event = lambda sigma: dpsgd_event(sigma, 512, sampling_prob=0.1)
29-
>>> dp_accounting.calibrate_dp_mechanism(
30+
>>> noise_multiplier = dp_accounting.calibrate_dp_mechanism(
3031
... dp_accounting.pld.PLDAccountant,
3132
... make_event,
3233
... target_epsilon=1.0,
3334
... target_delta=1e-6
3435
... )
35-
9.661830157637436
36+
>>> round(noise_multiplier, 2)
37+
9.66
3638
3739
Example Usage (Calibrating Number of Iterations for DP-SGD):
3840
@@ -105,7 +107,7 @@ def truncated_dpsgd_event(
105107
num_examples: int,
106108
truncated_batch_size: int,
107109
) -> dp_accounting.DpEvent:
108-
"""Returns the DpEvent for truncated DP-SGD with the given training parameters.
110+
"""Returns the DpEvent for truncated DP-SGD with the given training params.
109111
110112
This mechanism is like DP-SGD, but batches larger than `truncated_batch_size`
111113
are truncated to size `truncated_batch_size`. See these references for more

jax_privacy/matrix_factorization/streaming_matrix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from collections.abc import Callable
2121
import dataclasses
22-
from typing import Any, TypeAlias, TypeVar
22+
from typing import Any, Generic, TypeAlias, TypeVar
2323

2424
import chex
2525
import jax
@@ -37,7 +37,7 @@
3737

3838

3939
@dataclasses.dataclass(frozen=True)
40-
class StreamingMatrix:
40+
class StreamingMatrix(Generic[State]):
4141
"""A linear mapping x -> A x for a lower-triangular (streaming) A matrix.
4242
4343
Via the attributes / member functions `init_multiply` and `multiply_next`,

jax_privacy/noise_addition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060

6161
class _NoiseStructureFn(Protocol):
62-
"""Protocol specifying the semantics of _IntermediateStrategy.get_noise_structure.
62+
"""Protocol defining semantics of _IntermediateStrategy.get_noise_structure.
6363
6464
(Expected) Formal Guarantees of y = get_noise_structure(x):
6565
- x.size <= y.size (i.e., math.prod(x.shape) <= math.prod(y.shape)). See

lint.sh

Lines changed: 0 additions & 51 deletions
This file was deleted.

requirements-dev.txt

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)