mapFolding 0.8.2__py3-none-any.whl → 0.8.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mapFolding/__init__.py +6 -2
- mapFolding/basecamp.py +11 -5
- mapFolding/filesystem.py +134 -109
- mapFolding/oeis.py +1 -1
- mapFolding/reference/__init__.py +7 -0
- mapFolding/reference/jobsCompleted/[2x19]/p2x19.py +197 -0
- mapFolding/reference/jobsCompleted/__init__.py +50 -0
- mapFolding/reference/jobsCompleted/p2x19/p2x19.py +29 -0
- mapFolding/someAssemblyRequired/__init__.py +37 -18
- mapFolding/someAssemblyRequired/_theTypes.py +35 -0
- mapFolding/someAssemblyRequired/_tool_Make.py +92 -0
- mapFolding/someAssemblyRequired/_tool_Then.py +65 -0
- mapFolding/someAssemblyRequired/_toolboxAntecedents.py +326 -0
- mapFolding/someAssemblyRequired/_toolboxContainers.py +306 -0
- mapFolding/someAssemblyRequired/_toolboxPython.py +76 -0
- mapFolding/someAssemblyRequired/getLLVMforNoReason.py +20 -1
- mapFolding/someAssemblyRequired/ingredientsNumba.py +17 -24
- mapFolding/someAssemblyRequired/synthesizeNumbaFlow.py +112 -149
- mapFolding/someAssemblyRequired/synthesizeNumbaJob.py +247 -0
- mapFolding/someAssemblyRequired/transformDataStructures.py +167 -100
- mapFolding/someAssemblyRequired/transformationTools.py +63 -678
- mapFolding/syntheticModules/__init__.py +1 -0
- mapFolding/syntheticModules/numbaCount_doTheNeedful.py +36 -33
- mapFolding/theDao.py +13 -11
- mapFolding/theSSOT.py +69 -119
- {mapfolding-0.8.2.dist-info → mapfolding-0.8.4.dist-info}/METADATA +4 -2
- mapfolding-0.8.4.dist-info/RECORD +49 -0
- {mapfolding-0.8.2.dist-info → mapfolding-0.8.4.dist-info}/WHEEL +1 -1
- tests/conftest.py +34 -29
- tests/test_computations.py +40 -31
- tests/test_filesystem.py +3 -3
- tests/test_other.py +4 -3
- mapFolding/someAssemblyRequired/synthesizeNumbaJobVESTIGIAL.py +0 -413
- mapfolding-0.8.2.dist-info/RECORD +0 -39
- {mapfolding-0.8.2.dist-info → mapfolding-0.8.4.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.8.2.dist-info → mapfolding-0.8.4.dist-info}/licenses/LICENSE +0 -0
- {mapfolding-0.8.2.dist-info → mapfolding-0.8.4.dist-info}/top_level.txt +0 -0
tests/conftest.py
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
from importlib import import_module as importlib_import_module
|
|
2
1
|
from collections.abc import Callable, Generator, Sequence
|
|
3
|
-
from types import ModuleType
|
|
4
|
-
|
|
5
|
-
import numpy
|
|
6
|
-
from mapFolding.theSSOT import ComputationState, The, getPackageDispatcher
|
|
7
2
|
from mapFolding.beDRY import getLeavesTotal, validateListDimensions, makeDataContainer
|
|
8
3
|
from mapFolding.oeis import oeisIDsImplemented, settingsOEIS
|
|
9
|
-
from mapFolding.someAssemblyRequired import
|
|
4
|
+
from mapFolding.someAssemblyRequired import importLogicalPath2Callable
|
|
10
5
|
from mapFolding.someAssemblyRequired.synthesizeNumbaFlow import makeNumbaFlow
|
|
6
|
+
from mapFolding.someAssemblyRequired._toolboxContainers import RecipeSynthesizeFlow
|
|
7
|
+
from mapFolding.theSSOT import ComputationState, The, getPackageDispatcher
|
|
11
8
|
from pathlib import Path, PurePosixPath
|
|
9
|
+
from types import ModuleType
|
|
12
10
|
from typing import Any, ContextManager
|
|
11
|
+
import importlib
|
|
13
12
|
import importlib.util
|
|
13
|
+
import numpy
|
|
14
14
|
import pytest
|
|
15
15
|
import random
|
|
16
16
|
import shutil
|
|
@@ -18,8 +18,9 @@ import unittest.mock
|
|
|
18
18
|
import uuid
|
|
19
19
|
|
|
20
20
|
# SSOT for test data paths and filenames
|
|
21
|
-
pathDataSamples = Path("tests/dataSamples")
|
|
21
|
+
pathDataSamples = Path("tests/dataSamples").absolute()
|
|
22
22
|
pathTmpRoot: Path = pathDataSamples / "tmp"
|
|
23
|
+
pathTmpRoot.mkdir(parents=True, exist_ok=True)
|
|
23
24
|
|
|
24
25
|
# The registrar maintains the register of temp files
|
|
25
26
|
registerOfTemporaryFilesystemObjects: set[Path] = set()
|
|
@@ -100,7 +101,22 @@ def setupWarningsAsErrors() -> Generator[None, Any, None]:
|
|
|
100
101
|
warnings.resetwarnings()
|
|
101
102
|
|
|
102
103
|
@pytest.fixture
|
|
103
|
-
def
|
|
104
|
+
def oneTestCuzTestsOverwritingTests(oeisID_1random: str) -> tuple[int, ...]:
|
|
105
|
+
"""For each `oeisID_1random` from the `pytest.fixture`, returns `listDimensions` from `valuesTestValidation`
|
|
106
|
+
if `validateListDimensions` approves. Each `listDimensions` is suitable for testing counts."""
|
|
107
|
+
while True:
|
|
108
|
+
n = random.choice(settingsOEIS[oeisID_1random]['valuesTestValidation'])
|
|
109
|
+
if n < 2:
|
|
110
|
+
continue
|
|
111
|
+
listDimensionsCandidate = list(settingsOEIS[oeisID_1random]['getMapShape'](n))
|
|
112
|
+
|
|
113
|
+
try:
|
|
114
|
+
return validateListDimensions(listDimensionsCandidate)
|
|
115
|
+
except (ValueError, NotImplementedError):
|
|
116
|
+
pass
|
|
117
|
+
|
|
118
|
+
@pytest.fixture
|
|
119
|
+
def listDimensionsTestCountFolds(oeisID: str) -> tuple[int, ...]:
|
|
104
120
|
"""For each `oeisID` from the `pytest.fixture`, returns `listDimensions` from `valuesTestValidation`
|
|
105
121
|
if `validateListDimensions` approves. Each `listDimensions` is suitable for testing counts."""
|
|
106
122
|
while True:
|
|
@@ -115,7 +131,7 @@ def listDimensionsTestCountFolds(oeisID: str):
|
|
|
115
131
|
pass
|
|
116
132
|
|
|
117
133
|
@pytest.fixture
|
|
118
|
-
def mapShapeTestFunctionality(oeisID_1random: str):
|
|
134
|
+
def mapShapeTestFunctionality(oeisID_1random: str) -> tuple[int, ...]:
|
|
119
135
|
"""To test functionality, get one `listDimensions` from `valuesTestValidation` if
|
|
120
136
|
`validateListDimensions` approves. The algorithm can count the folds of the returned
|
|
121
137
|
`listDimensions` in a short enough time suitable for testing."""
|
|
@@ -159,17 +175,6 @@ def mockFoldingFunction() -> Callable[..., Callable[..., None]]:
|
|
|
159
175
|
return mock_countFolds
|
|
160
176
|
return make_mock
|
|
161
177
|
|
|
162
|
-
@pytest.fixture
|
|
163
|
-
def mockDispatcher() -> Callable[[Any], ContextManager[Any]]:
|
|
164
|
-
"""Context manager for mocking dispatcher callable."""
|
|
165
|
-
def wrapper(mockFunction: Any) -> ContextManager[Any]:
|
|
166
|
-
dispatcherCallable = getPackageDispatcher()
|
|
167
|
-
return unittest.mock.patch(
|
|
168
|
-
f"{dispatcherCallable.__module__}.{dispatcherCallable.__name__}",
|
|
169
|
-
side_effect=mockFunction
|
|
170
|
-
)
|
|
171
|
-
return wrapper
|
|
172
|
-
|
|
173
178
|
@pytest.fixture(params=oeisIDsImplemented)
|
|
174
179
|
def oeisID(request: pytest.FixtureRequest) -> Any:
|
|
175
180
|
return request.param
|
|
@@ -198,42 +203,42 @@ def useThisDispatcher() -> Generator[Callable[..., None], Any, None]:
|
|
|
198
203
|
basecamp.getPackageDispatcher = dispatcherOriginal
|
|
199
204
|
|
|
200
205
|
def getAlgorithmDispatcher() -> Callable[[ComputationState], ComputationState]:
|
|
201
|
-
moduleImported: ModuleType =
|
|
202
|
-
dispatcherCallable = getattr(moduleImported, The.
|
|
206
|
+
moduleImported: ModuleType = importlib.import_module(The.logicalPathModuleSourceAlgorithm)
|
|
207
|
+
dispatcherCallable = getattr(moduleImported, The.sourceCallableDispatcher)
|
|
203
208
|
return dispatcherCallable
|
|
204
209
|
|
|
205
210
|
@pytest.fixture
|
|
206
211
|
def useAlgorithmSourceDispatcher(useThisDispatcher: Callable[..., Any]) -> Generator[None, None, None]:
|
|
207
212
|
"""Temporarily patches getDispatcherCallable to return the algorithm dispatcher."""
|
|
208
|
-
useThisDispatcher(
|
|
213
|
+
useThisDispatcher(importLogicalPath2Callable(The.logicalPathModuleSourceAlgorithm, The.sourceCallableDispatcher))
|
|
209
214
|
yield
|
|
210
215
|
|
|
211
216
|
@pytest.fixture
|
|
212
217
|
def syntheticDispatcherFixture(useThisDispatcher: Callable[..., Any], pathTmpTesting: Path) -> Callable[..., Any]:
|
|
213
218
|
"""Generate synthetic Numba-optimized dispatcher module and patch the dispatcher"""
|
|
214
219
|
# Configure synthesis flow to use test directory
|
|
215
|
-
|
|
220
|
+
TESTINGrecipeFlow = RecipeSynthesizeFlow(
|
|
216
221
|
pathPackage=PurePosixPath(pathTmpTesting.absolute()),
|
|
217
|
-
|
|
222
|
+
logicalPathFlowRoot=None,
|
|
218
223
|
moduleDispatcher="test_dispatcher",
|
|
219
224
|
# Figure out dynamic flow control to synthesized modules https://github.com/hunterhogan/mapFolding/issues/4
|
|
220
225
|
# dispatcherCallable="dispatcherSynthetic",
|
|
221
226
|
)
|
|
222
227
|
|
|
223
228
|
# Generate optimized module in test directory
|
|
224
|
-
makeNumbaFlow(
|
|
229
|
+
makeNumbaFlow(TESTINGrecipeFlow)
|
|
225
230
|
|
|
226
231
|
# Import synthesized dispatcher
|
|
227
232
|
importlibSpecificationDispatcher = importlib.util.spec_from_file_location(
|
|
228
|
-
|
|
229
|
-
Path(
|
|
233
|
+
TESTINGrecipeFlow.moduleDispatcher,
|
|
234
|
+
Path(TESTINGrecipeFlow.pathFilenameDispatcher),
|
|
230
235
|
)
|
|
231
236
|
if importlibSpecificationDispatcher is None or importlibSpecificationDispatcher.loader is None:
|
|
232
237
|
raise ImportError("Failed to load synthetic dispatcher module")
|
|
233
238
|
|
|
234
239
|
moduleSpecificationDispatcher = importlib.util.module_from_spec(importlibSpecificationDispatcher)
|
|
235
240
|
importlibSpecificationDispatcher.loader.exec_module(moduleSpecificationDispatcher)
|
|
236
|
-
callableDispatcherSynthetic = getattr(moduleSpecificationDispatcher,
|
|
241
|
+
callableDispatcherSynthetic = getattr(moduleSpecificationDispatcher, TESTINGrecipeFlow.callableDispatcher)
|
|
237
242
|
|
|
238
243
|
# Patch dispatcher and return callable
|
|
239
244
|
useThisDispatcher(callableDispatcherSynthetic)
|
tests/test_computations.py
CHANGED
|
@@ -1,53 +1,62 @@
|
|
|
1
1
|
from mapFolding.basecamp import countFolds
|
|
2
2
|
from mapFolding.filesystem import getPathFilenameFoldsTotal
|
|
3
|
+
from mapFolding.beDRY import validateListDimensions
|
|
3
4
|
from mapFolding.noHomeYet import getFoldsTotalKnown
|
|
4
5
|
from mapFolding.oeis import settingsOEIS, oeisIDfor_n
|
|
5
|
-
|
|
6
|
-
from
|
|
6
|
+
from mapFolding.someAssemblyRequired.synthesizeNumbaJob import makeJobNumba, Z0Z_RecipeJob
|
|
7
|
+
from mapFolding.someAssemblyRequired.transformDataStructures import makeInitializedComputationState
|
|
8
|
+
from pathlib import Path, PurePosixPath
|
|
7
9
|
from tests.conftest import standardizedEqualToCallableReturn, registrarRecordsTmpObject
|
|
8
10
|
from types import ModuleType
|
|
9
11
|
import importlib.util
|
|
10
12
|
import multiprocessing
|
|
13
|
+
import threading
|
|
14
|
+
from copy import deepcopy
|
|
11
15
|
import pytest
|
|
12
16
|
|
|
13
17
|
if __name__ == '__main__':
|
|
14
18
|
multiprocessing.set_start_method('spawn')
|
|
15
19
|
|
|
16
20
|
def test_algorithmSourceParallel(listDimensionsTestParallelization: list[int], useAlgorithmSourceDispatcher: None) -> None:
|
|
17
|
-
|
|
21
|
+
standardizedEqualToCallableReturn(getFoldsTotalKnown(tuple(listDimensionsTestParallelization)), countFolds, listDimensionsTestParallelization, None, 'maximum', None)
|
|
18
22
|
|
|
19
23
|
def test_algorithmSourceSequential(listDimensionsTestCountFolds: tuple[int, ...], useAlgorithmSourceDispatcher: None) -> None:
|
|
20
|
-
|
|
24
|
+
standardizedEqualToCallableReturn(getFoldsTotalKnown(tuple(listDimensionsTestCountFolds)), countFolds, listDimensionsTestCountFolds)
|
|
21
25
|
|
|
22
26
|
def test_aOFn_calculate_value(oeisID: str) -> None:
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
for n in settingsOEIS[oeisID]['valuesTestValidation']:
|
|
28
|
+
standardizedEqualToCallableReturn(settingsOEIS[oeisID]['valuesKnown'][n], oeisIDfor_n, oeisID, n)
|
|
25
29
|
|
|
26
30
|
def test_syntheticParallel(syntheticDispatcherFixture: None, listDimensionsTestParallelization: list[int]):
|
|
27
|
-
|
|
31
|
+
standardizedEqualToCallableReturn(getFoldsTotalKnown(tuple(listDimensionsTestParallelization)), countFolds, listDimensionsTestParallelization, None, 'maximum')
|
|
28
32
|
|
|
29
33
|
def test_syntheticSequential(syntheticDispatcherFixture: None, listDimensionsTestCountFolds: list[int]) -> None:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
34
|
+
standardizedEqualToCallableReturn(getFoldsTotalKnown(tuple(listDimensionsTestCountFolds)), countFolds, listDimensionsTestCountFolds)
|
|
35
|
+
|
|
36
|
+
@pytest.mark.parametrize('pathFilenameTmpTesting', ['.py'], indirect=True)
|
|
37
|
+
def test_writeJobNumba(oneTestCuzTestsOverwritingTests: list[int], pathFilenameTmpTesting: Path) -> None:
|
|
38
|
+
mapShape = validateListDimensions(oneTestCuzTestsOverwritingTests)
|
|
39
|
+
state = makeInitializedComputationState(mapShape)
|
|
40
|
+
|
|
41
|
+
pathFilenameModule = pathFilenameTmpTesting.absolute()
|
|
42
|
+
pathFilenameFoldsTotal = pathFilenameModule.with_suffix('.foldsTotalTesting')
|
|
43
|
+
registrarRecordsTmpObject(pathFilenameFoldsTotal)
|
|
44
|
+
|
|
45
|
+
jobTest = Z0Z_RecipeJob(state
|
|
46
|
+
, pathModule=PurePosixPath(pathFilenameModule.parent)
|
|
47
|
+
, moduleIdentifier=pathFilenameModule.stem
|
|
48
|
+
, pathFilenameFoldsTotal=PurePosixPath(pathFilenameFoldsTotal))
|
|
49
|
+
|
|
50
|
+
makeJobNumba(jobTest)
|
|
51
|
+
|
|
52
|
+
Don_Lapre_Road_to_Self_Improvement = importlib.util.spec_from_file_location("__main__", pathFilenameModule)
|
|
53
|
+
if Don_Lapre_Road_to_Self_Improvement is None:
|
|
54
|
+
raise ImportError(f"Failed to create module specification from {pathFilenameModule}")
|
|
55
|
+
if Don_Lapre_Road_to_Self_Improvement.loader is None:
|
|
56
|
+
raise ImportError(f"Failed to get loader for module {pathFilenameModule}")
|
|
57
|
+
module = importlib.util.module_from_spec(Don_Lapre_Road_to_Self_Improvement)
|
|
58
|
+
|
|
59
|
+
module.__name__ = "__main__"
|
|
60
|
+
Don_Lapre_Road_to_Self_Improvement.loader.exec_module(module)
|
|
61
|
+
|
|
62
|
+
standardizedEqualToCallableReturn(str(getFoldsTotalKnown(mapShape)), pathFilenameFoldsTotal.read_text().strip)
|
tests/test_filesystem.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from contextlib import redirect_stdout
|
|
2
2
|
from mapFolding.filesystem import getFilenameFoldsTotal, getPathFilenameFoldsTotal, saveFoldsTotal
|
|
3
3
|
from mapFolding.beDRY import validateListDimensions
|
|
4
|
-
from mapFolding.
|
|
4
|
+
from mapFolding.filesystem import getPathRootJobDEFAULT
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
import io
|
|
7
7
|
import pytest
|
|
@@ -33,14 +33,14 @@ def test_getPathFilenameFoldsTotal_defaultPath(mapShapeTestFunctionality: tuple[
|
|
|
33
33
|
pathFilenameFoldsTotal = getPathFilenameFoldsTotal(mapShapeTestFunctionality)
|
|
34
34
|
assert pathFilenameFoldsTotal.is_absolute(), "Path should be absolute"
|
|
35
35
|
assert pathFilenameFoldsTotal.name == getFilenameFoldsTotal(mapShapeTestFunctionality), "Filename should match getFilenameFoldsTotal output"
|
|
36
|
-
assert pathFilenameFoldsTotal.parent ==
|
|
36
|
+
assert pathFilenameFoldsTotal.parent == getPathRootJobDEFAULT(), "Parent directory should match default job root"
|
|
37
37
|
|
|
38
38
|
def test_getPathFilenameFoldsTotal_relativeFilename(mapShapeTestFunctionality: tuple[int, ...]) -> None:
|
|
39
39
|
"""Test getPathFilenameFoldsTotal with relative filename."""
|
|
40
40
|
relativeFilename = Path("custom/path/test.foldsTotal")
|
|
41
41
|
pathFilenameFoldsTotal = getPathFilenameFoldsTotal(mapShapeTestFunctionality, relativeFilename)
|
|
42
42
|
assert pathFilenameFoldsTotal.is_absolute(), "Path should be absolute"
|
|
43
|
-
assert pathFilenameFoldsTotal ==
|
|
43
|
+
assert pathFilenameFoldsTotal == getPathRootJobDEFAULT() / relativeFilename, "Relative path should be appended to default job root"
|
|
44
44
|
|
|
45
45
|
def test_getPathFilenameFoldsTotal_createsDirs(pathTmpTesting: Path, mapShapeTestFunctionality: tuple[int, ...]) -> None:
|
|
46
46
|
"""Test that getPathFilenameFoldsTotal creates necessary directories."""
|
tests/test_other.py
CHANGED
|
@@ -5,6 +5,7 @@ from tests.conftest import standardizedEqualToCallableReturn
|
|
|
5
5
|
from typing import Any, Literal
|
|
6
6
|
from Z0Z_tools import intInnit
|
|
7
7
|
from Z0Z_tools.pytestForYourUse import PytestFor_intInnit, PytestFor_oopsieKwargsie
|
|
8
|
+
import multiprocessing
|
|
8
9
|
import numba
|
|
9
10
|
import pytest
|
|
10
11
|
import sys
|
|
@@ -78,6 +79,6 @@ def testOopsieKwargsie(nameOfTest: str, callablePytest: Callable[[], None]) -> N
|
|
|
78
79
|
(0, numba.get_num_threads()),
|
|
79
80
|
(1, 1),
|
|
80
81
|
])
|
|
81
|
-
def
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
def test_setCPUlimitNumba(CPUlimit: None | float | bool | Literal[4] | Literal[-2] | Literal[0] | Literal[1], expectedLimit: Any | int) -> None:
|
|
83
|
+
numba.set_num_threads(multiprocessing.cpu_count())
|
|
84
|
+
standardizedEqualToCallableReturn(expectedLimit, setCPUlimit, CPUlimit, 'numba')
|