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.
Files changed (37) hide show
  1. mapFolding/__init__.py +6 -2
  2. mapFolding/basecamp.py +11 -5
  3. mapFolding/filesystem.py +134 -109
  4. mapFolding/oeis.py +1 -1
  5. mapFolding/reference/__init__.py +7 -0
  6. mapFolding/reference/jobsCompleted/[2x19]/p2x19.py +197 -0
  7. mapFolding/reference/jobsCompleted/__init__.py +50 -0
  8. mapFolding/reference/jobsCompleted/p2x19/p2x19.py +29 -0
  9. mapFolding/someAssemblyRequired/__init__.py +37 -18
  10. mapFolding/someAssemblyRequired/_theTypes.py +35 -0
  11. mapFolding/someAssemblyRequired/_tool_Make.py +92 -0
  12. mapFolding/someAssemblyRequired/_tool_Then.py +65 -0
  13. mapFolding/someAssemblyRequired/_toolboxAntecedents.py +326 -0
  14. mapFolding/someAssemblyRequired/_toolboxContainers.py +306 -0
  15. mapFolding/someAssemblyRequired/_toolboxPython.py +76 -0
  16. mapFolding/someAssemblyRequired/getLLVMforNoReason.py +20 -1
  17. mapFolding/someAssemblyRequired/ingredientsNumba.py +17 -24
  18. mapFolding/someAssemblyRequired/synthesizeNumbaFlow.py +112 -149
  19. mapFolding/someAssemblyRequired/synthesizeNumbaJob.py +247 -0
  20. mapFolding/someAssemblyRequired/transformDataStructures.py +167 -100
  21. mapFolding/someAssemblyRequired/transformationTools.py +63 -678
  22. mapFolding/syntheticModules/__init__.py +1 -0
  23. mapFolding/syntheticModules/numbaCount_doTheNeedful.py +36 -33
  24. mapFolding/theDao.py +13 -11
  25. mapFolding/theSSOT.py +69 -119
  26. {mapfolding-0.8.2.dist-info → mapfolding-0.8.4.dist-info}/METADATA +4 -2
  27. mapfolding-0.8.4.dist-info/RECORD +49 -0
  28. {mapfolding-0.8.2.dist-info → mapfolding-0.8.4.dist-info}/WHEEL +1 -1
  29. tests/conftest.py +34 -29
  30. tests/test_computations.py +40 -31
  31. tests/test_filesystem.py +3 -3
  32. tests/test_other.py +4 -3
  33. mapFolding/someAssemblyRequired/synthesizeNumbaJobVESTIGIAL.py +0 -413
  34. mapfolding-0.8.2.dist-info/RECORD +0 -39
  35. {mapfolding-0.8.2.dist-info → mapfolding-0.8.4.dist-info}/entry_points.txt +0 -0
  36. {mapfolding-0.8.2.dist-info → mapfolding-0.8.4.dist-info}/licenses/LICENSE +0 -0
  37. {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 RecipeSynthesizeFlow
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 listDimensionsTestCountFolds(oeisID: str):
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 = importlib_import_module(The.logicalPathModuleSourceAlgorithm)
202
- dispatcherCallable = getattr(moduleImported, The.dispatcherCallable)
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(getAlgorithmDispatcher())
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
- recipeFlow = RecipeSynthesizeFlow(
220
+ TESTINGrecipeFlow = RecipeSynthesizeFlow(
216
221
  pathPackage=PurePosixPath(pathTmpTesting.absolute()),
217
- Z0Z_flowLogicalPathRoot=None,
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(recipeFlow)
229
+ makeNumbaFlow(TESTINGrecipeFlow)
225
230
 
226
231
  # Import synthesized dispatcher
227
232
  importlibSpecificationDispatcher = importlib.util.spec_from_file_location(
228
- recipeFlow.moduleDispatcher,
229
- Path(recipeFlow.pathFilenameDispatcher),
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, recipeFlow.dispatcherCallable)
241
+ callableDispatcherSynthetic = getattr(moduleSpecificationDispatcher, TESTINGrecipeFlow.callableDispatcher)
237
242
 
238
243
  # Patch dispatcher and return callable
239
244
  useThisDispatcher(callableDispatcherSynthetic)
@@ -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
- # from mapFolding.someAssemblyRequired import writeJobNumba
6
- from pathlib import Path
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
- standardizedEqualToCallableReturn(getFoldsTotalKnown(tuple(listDimensionsTestParallelization)), countFolds, listDimensionsTestParallelization, None, 'maximum', None)
21
+ standardizedEqualToCallableReturn(getFoldsTotalKnown(tuple(listDimensionsTestParallelization)), countFolds, listDimensionsTestParallelization, None, 'maximum', None)
18
22
 
19
23
  def test_algorithmSourceSequential(listDimensionsTestCountFolds: tuple[int, ...], useAlgorithmSourceDispatcher: None) -> None:
20
- standardizedEqualToCallableReturn(getFoldsTotalKnown(tuple(listDimensionsTestCountFolds)), countFolds, listDimensionsTestCountFolds)
24
+ standardizedEqualToCallableReturn(getFoldsTotalKnown(tuple(listDimensionsTestCountFolds)), countFolds, listDimensionsTestCountFolds)
21
25
 
22
26
  def test_aOFn_calculate_value(oeisID: str) -> None:
23
- for n in settingsOEIS[oeisID]['valuesTestValidation']:
24
- standardizedEqualToCallableReturn(settingsOEIS[oeisID]['valuesKnown'][n], oeisIDfor_n, oeisID, n)
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
- standardizedEqualToCallableReturn(getFoldsTotalKnown(tuple(listDimensionsTestParallelization)), countFolds, listDimensionsTestParallelization, None, 'maximum')
31
+ standardizedEqualToCallableReturn(getFoldsTotalKnown(tuple(listDimensionsTestParallelization)), countFolds, listDimensionsTestParallelization, None, 'maximum')
28
32
 
29
33
  def test_syntheticSequential(syntheticDispatcherFixture: None, listDimensionsTestCountFolds: list[int]) -> None:
30
- standardizedEqualToCallableReturn(getFoldsTotalKnown(tuple(listDimensionsTestCountFolds)), countFolds, listDimensionsTestCountFolds)
31
-
32
- # @pytest.mark.parametrize('pathFilenameTmpTesting', ['.py'], indirect=True)
33
- # def test_writeJobNumba(listDimensionsTestCountFolds: list[int], pathFilenameTmpTesting: Path) -> None:
34
- # from mapFolding.syntheticModules import numbaCount
35
- # algorithmSourceHARDCODED: ModuleType = numbaCount
36
- # algorithmSource = algorithmSourceHARDCODED
37
- # callableTargetHARDCODED = 'countSequential'
38
- # callableTarget = callableTargetHARDCODED
39
- # pathFilenameModule = writeJobNumba(listDimensionsTestCountFolds, algorithmSource, callableTarget, pathFilenameWriteJob=pathFilenameTmpTesting.absolute())
40
-
41
- # Don_Lapre_Road_to_Self_Improvement = importlib.util.spec_from_file_location("__main__", pathFilenameModule)
42
- # if Don_Lapre_Road_to_Self_Improvement is None:
43
- # raise ImportError(f"Failed to create module specification from {pathFilenameModule}")
44
- # if Don_Lapre_Road_to_Self_Improvement.loader is None:
45
- # raise ImportError(f"Failed to get loader for module {pathFilenameModule}")
46
- # module = importlib.util.module_from_spec(Don_Lapre_Road_to_Self_Improvement)
47
-
48
- # module.__name__ = "__main__"
49
- # Don_Lapre_Road_to_Self_Improvement.loader.exec_module(module)
50
-
51
- # pathFilenameFoldsTotal = getPathFilenameFoldsTotal(listDimensionsTestCountFolds)
52
- # registrarRecordsTmpObject(pathFilenameFoldsTotal)
53
- # standardizedEqualToCallableReturn(str(getFoldsTotalKnown(tuple(listDimensionsTestCountFolds))), pathFilenameFoldsTotal.read_text().strip)
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.theSSOT import getPathJobRootDEFAULT
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 == getPathJobRootDEFAULT(), "Parent directory should match default job root"
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 == getPathJobRootDEFAULT() / relativeFilename, "Relative path should be appended to default job root"
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 test_setCPUlimit(CPUlimit: None | float | bool | Literal[4] | Literal[-2] | Literal[0] | Literal[1], expectedLimit: Any | int) -> None:
82
- if The.concurrencyPackage == 'numba':
83
- standardizedEqualToCallableReturn(expectedLimit, setCPUlimit, CPUlimit)
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')