-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add another test that our seeding system is good
by checking that the seed depends on the file name, function name and parameter closes #zama-ai/concrete-ml-internal#4325
- Loading branch information
1 parent
b3133c1
commit bab4326
Showing
5 changed files
with
194 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
script/make_utils/check_first_line_is_different_from_other_lines.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Helper to check the first line is different from all other lines.""" | ||
|
||
import argparse | ||
from pathlib import Path | ||
|
||
|
||
def process_file(file_str: str): | ||
"""Helper to check the first line is different from all other lines. | ||
Args: | ||
file_str (str): the path to the file to process. | ||
Returns: | ||
True if everything went alright. | ||
Raises: | ||
ValueError: if the first line is equal to another line in the file | ||
""" | ||
file_path = Path(file_str).resolve() | ||
|
||
with open(file_path, "r", encoding="utf-8") as f: | ||
file_content = f.readlines() | ||
|
||
first_line = file_content[0] | ||
|
||
for new_line in file_content[1:]: | ||
is_equal_line = new_line == first_line | ||
if is_equal_line: | ||
raise ValueError("Error, the first line and another line are equal") | ||
|
||
assert len(file_content) > 1 | ||
print(f"{file_path} looks good (number of lines: {len(file_content)})!") | ||
return True | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser( | ||
"Helper to check the first line is different from all other lines", allow_abbrev=False | ||
) | ||
|
||
parser.add_argument("--file", type=str, required=True, help="The log files to check") | ||
|
||
cli_args = parser.parse_args() | ||
process_file(cli_args.file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""Tests for the torch to numpy module.""" | ||
import random | ||
|
||
import numpy | ||
import pytest | ||
|
||
|
||
def body(): | ||
"""Common function used in the tests, which picks random from numpy in different ways.""" | ||
numpy.set_printoptions(threshold=10000) | ||
numpy.set_printoptions(linewidth=10000) | ||
|
||
print("Output: ", end="") | ||
|
||
# Python random | ||
for _ in range(1): | ||
print(random.randint(0, 1000), end="") | ||
|
||
# Numpy random | ||
for _ in range(1): | ||
print(numpy.random.randint(0, 1000), end="") | ||
print(numpy.random.uniform(-100, 100, size=(3, 3)).flatten(), end="") | ||
|
||
|
||
@pytest.mark.parametrize("parameters", [1, 2, 3]) | ||
def test_bcm_seed_1(parameters): | ||
"""Test python and numpy seeding.""" | ||
|
||
assert parameters is not None | ||
body() | ||
|
||
|
||
@pytest.mark.parametrize("parameters", [1, 3]) | ||
def test_bcm_seed_2(parameters): | ||
"""Test python and numpy seeding.""" | ||
|
||
assert parameters is not None | ||
body() | ||
|
||
|
||
@pytest.mark.parametrize("parameters", ["a", "b"]) | ||
def test_bcm_seed_3(parameters): | ||
"""Test python and numpy seeding.""" | ||
|
||
assert parameters is not None | ||
body() | ||
|
||
|
||
def test_bcm_seed_4(): | ||
"""Test python and numpy seeding.""" | ||
|
||
body() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""Tests for the torch to numpy module.""" | ||
import random | ||
|
||
import numpy | ||
import pytest | ||
|
||
|
||
def body(): | ||
"""Common function used in the tests, which picks random from numpy in different ways.""" | ||
numpy.set_printoptions(threshold=10000) | ||
numpy.set_printoptions(linewidth=10000) | ||
|
||
print("Output: ", end="") | ||
|
||
# Python random | ||
for _ in range(1): | ||
print(random.randint(0, 1000), end="") | ||
|
||
# Numpy random | ||
for _ in range(1): | ||
print(numpy.random.randint(0, 1000), end="") | ||
print(numpy.random.uniform(-100, 100, size=(3, 3)).flatten(), end="") | ||
|
||
|
||
@pytest.mark.parametrize("parameters", [1, 2, 3]) | ||
def test_bcm_seed_1(parameters): | ||
"""Test python and numpy seeding.""" | ||
|
||
assert parameters is not None | ||
body() | ||
|
||
|
||
@pytest.mark.parametrize("parameters", [1, 3]) | ||
def test_bcm_seed_2(parameters): | ||
"""Test python and numpy seeding.""" | ||
|
||
assert parameters is not None | ||
body() | ||
|
||
|
||
@pytest.mark.parametrize("parameters", ["a", "b"]) | ||
def test_bcm_seed_3(parameters): | ||
"""Test python and numpy seeding.""" | ||
|
||
assert parameters is not None | ||
body() | ||
|
||
|
||
def test_bcm_seed_4(): | ||
"""Test python and numpy seeding.""" | ||
|
||
body() |