-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set random_seed for stohastic integration tests (#217)
* fix * fix#2 * minor * increase indulgence * minor * move set random seed * minor * add random seed for integration tests * minor * Try to log state hash after every action * Set seed of urandom to all tests (by mocking) by adding global autouse fixture * Revert "Set seed of urandom to all tests (by mocking) by adding global autouse fixture" This reverts commit 03d2d1f. * Revert "Try to log state hash after every action" This reverts commit eeec7b4. * Create conftest.py to fix seed and mock urandom before all tests * Further resolve conflict of incorrect imports after moving `utilities` folder * Use random.getrandbits for compatibility with python 3.8 * Add test that seed fully determines evolution process * Remove check that evolution history differs for different seeds * More robust history comparison * Remove unnecessary utils.py file and references to `set_random_seed` * Try debugging `test_hierarchy_pos` test internals * Generate test picture * Fix workflow to upload artifact * Print networkx version in CI for debugging purposes * Test requiring other version of networkX * Revert "Print networkx version in CI for debugging purposes" This reverts commit 94783b2. * Revert "Fix workflow to upload artifact" This reverts commit f3d490c. * Revert "Generate test picture" This reverts commit b723d98. * Revert "Try debugging `test_hierarchy_pos` test internals" This reverts commit 22fd62b. * Fix redundant imports --------- Co-authored-by: Vladimir Latypov <[email protected]>
- Loading branch information
1 parent
15a9275
commit ea68764
Showing
6 changed files
with
54 additions
and
6 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
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,11 @@ | ||
from unittest.mock import patch | ||
import pytest | ||
from golem.utilities.utilities import urandom_mock, set_random_seed | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def stabilize_random(): | ||
set_random_seed(42) | ||
|
||
with patch('os.urandom', urandom_mock): | ||
yield |
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
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,31 @@ | ||
from examples.synthetic_graph_evolution.generators import generate_labeled_graph | ||
from examples.synthetic_graph_evolution.graph_search import graph_search_setup | ||
from golem.utilities.utilities import set_random_seed | ||
|
||
|
||
def test_random_seed_fully_determines_evolution_process(): | ||
""" Tests that random seed fully determines evolution process. """ | ||
# Setup graph search | ||
target_graph = generate_labeled_graph('tree', 4, node_labels=['X', 'Y']) | ||
|
||
def launch_with_seed(seed): | ||
set_random_seed(seed) | ||
optimizer, objective = graph_search_setup( | ||
target_graph=target_graph, | ||
num_iterations=3, | ||
node_types=['X', 'Y'], | ||
pop_size=3 | ||
) | ||
optimizer.optimise(objective) | ||
return optimizer.history | ||
|
||
def history_equals(history1, history2): | ||
def get_generation_ids(history): | ||
return [[ind.graph.descriptive_id for ind in generation] for generation in history.generations] | ||
return get_generation_ids(history1) == get_generation_ids(history2) | ||
|
||
seed = 42 | ||
first_run = launch_with_seed(seed) | ||
second_run = launch_with_seed(seed) | ||
|
||
assert history_equals(first_run, second_run) |