mapFolding 0.2.6__py3-none-any.whl → 0.2.7__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-0.2.6.dist-info → mapFolding-0.2.7.dist-info}/METADATA +21 -7
- mapFolding-0.2.7.dist-info/RECORD +19 -0
- mapFolding-0.2.7.dist-info/top_level.txt +3 -0
- {mapFolding/someAssemblyRequired → someAssemblyRequired}/inlineAfunction.py +2 -2
- {mapFolding/someAssemblyRequired → someAssemblyRequired}/jobsAndTasks.py +3 -4
- {mapFolding/someAssemblyRequired → someAssemblyRequired}/makeNumbaJob.py +19 -16
- mapFolding/__init__.py +0 -12
- mapFolding/babbage.py +0 -35
- mapFolding/beDRY.py +0 -319
- mapFolding/importSelector.py +0 -7
- mapFolding/lovelace.py +0 -213
- mapFolding/oeis.py +0 -323
- mapFolding/startHere.py +0 -50
- mapFolding/theSSOT.py +0 -76
- mapFolding-0.2.6.dist-info/RECORD +0 -33
- mapFolding-0.2.6.dist-info/top_level.txt +0 -2
- tests/__init__.py +0 -1
- tests/conftest.py +0 -343
- tests/pythons_idiotic_namespace.py +0 -1
- tests/test_oeis.py +0 -194
- tests/test_other.py +0 -282
- tests/test_tasks.py +0 -31
- {mapFolding/benchmarks → benchmarks}/benchmarking.py +0 -0
- {mapFolding-0.2.6.dist-info → mapFolding-0.2.7.dist-info}/WHEEL +0 -0
- {mapFolding-0.2.6.dist-info → mapFolding-0.2.7.dist-info}/entry_points.txt +0 -0
- {mapFolding/reference → reference}/flattened.py +0 -0
- {mapFolding/reference → reference}/hunterNumba.py +0 -0
- {mapFolding/reference → reference}/irvineJavaPort.py +0 -0
- {mapFolding/reference → reference}/jax.py +0 -0
- {mapFolding/reference → reference}/lunnan.py +0 -0
- {mapFolding/reference → reference}/lunnanNumpy.py +0 -0
- {mapFolding/reference → reference}/lunnanWhile.py +0 -0
- {mapFolding/reference → reference}/rotatedEntryPoint.py +0 -0
- {mapFolding/reference → reference}/total_countPlus1vsPlusN.py +0 -0
- {mapFolding/someAssemblyRequired → someAssemblyRequired}/makeNuitkaSource.py +0 -0
|
@@ -1,18 +1,32 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: mapFolding
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: Count distinct ways to fold a map (or a strip of stamps)
|
|
5
5
|
Author-email: Hunter Hogan <HunterHogan@pm.me>
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
License: CC-BY-NC-4.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/hunterhogan/mapFolding
|
|
8
|
+
Project-URL: Donate, https://www.patreon.com/integrated
|
|
9
|
+
Keywords: A001415,A001416,A001417,A001418,A195646,folding,map folding,OEIS,stamp folding
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Education
|
|
13
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
14
|
+
Classifier: Intended Audience :: Other Audience
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Natural Language :: English
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: <3.14,>=3.10
|
|
8
22
|
Description-Content-Type: text/markdown
|
|
9
23
|
Requires-Dist: numba
|
|
10
24
|
Requires-Dist: numpy
|
|
11
|
-
Requires-Dist:
|
|
25
|
+
Requires-Dist: Z0Z_tools
|
|
12
26
|
Provides-Extra: benchmark
|
|
13
|
-
Requires-Dist: pandas; extra == "benchmark"
|
|
14
|
-
Requires-Dist: jupyter; extra == "benchmark"
|
|
15
27
|
Requires-Dist: ipywidgets; extra == "benchmark"
|
|
28
|
+
Requires-Dist: jupyter; extra == "benchmark"
|
|
29
|
+
Requires-Dist: pandas; extra == "benchmark"
|
|
16
30
|
Requires-Dist: tqdm; extra == "benchmark"
|
|
17
31
|
Provides-Extra: testing
|
|
18
32
|
Requires-Dist: pytest; extra == "testing"
|
|
@@ -40,7 +54,7 @@ The directory [mapFolding/reference](https://github.com/hunterhogan/mapFolding/b
|
|
|
40
54
|
|
|
41
55
|
## Simple, easy usage based on OEIS IDs
|
|
42
56
|
|
|
43
|
-
`mapFolding` directly implements some IDs from _The On-Line Encyclopedia of Integer Sequences_.
|
|
57
|
+
`mapFolding` directly implements some IDs from _The On-Line Encyclopedia of Integer Sequences_ ([BibTex](https://github.com/hunterhogan/mapFolding/blob/main/mapFolding/citations/oeis.bibtex) citation).
|
|
44
58
|
|
|
45
59
|
### Usage: command line
|
|
46
60
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
benchmarks/benchmarking.py,sha256=HD_0NSvuabblg94ftDre6LFnXShTe8MYj3hIodW-zV0,3076
|
|
2
|
+
reference/flattened.py,sha256=X9nvRzg7YDcpCtSDTL4YiidjshlX9rg2e6JVCY6i2u0,16547
|
|
3
|
+
reference/hunterNumba.py,sha256=0giUyqAFzP-XKcq3Kz8wIWCK0BVFhjABVJ1s-w4Jhu0,7109
|
|
4
|
+
reference/irvineJavaPort.py,sha256=Sj-63Z-OsGuDoEBXuxyjRrNmmyl0d7Yz_XuY7I47Oyg,4250
|
|
5
|
+
reference/jax.py,sha256=bB34dGdi3VSz4cRFbmCPn_erAmQ3FyrSED8uJ7CsES0,14961
|
|
6
|
+
reference/lunnan.py,sha256=XEcql_gxvCCghb6Or3qwmPbn4IZUbZTaSmw_fUjRxZE,5037
|
|
7
|
+
reference/lunnanNumpy.py,sha256=HqDgSwTOZA-G0oophOEfc4zs25Mv4yw2aoF1v8miOLk,4653
|
|
8
|
+
reference/lunnanWhile.py,sha256=7NY2IKO5XBgol0aWWF_Fi-7oTL9pvu_z6lB0TF1uVHk,4063
|
|
9
|
+
reference/rotatedEntryPoint.py,sha256=z0QyDQtnMvXNj5ntWzzJUQUMFm1-xHGLVhtYzwmczUI,11530
|
|
10
|
+
reference/total_countPlus1vsPlusN.py,sha256=usenM8Yn_G1dqlPl7NKKkcnbohBZVZBXTQRm2S3_EDA,8106
|
|
11
|
+
someAssemblyRequired/inlineAfunction.py,sha256=_hGAxVSVUAKCsNT92p0--Y636HkudpxHDEClXKrmmNE,6181
|
|
12
|
+
someAssemblyRequired/jobsAndTasks.py,sha256=zHgqvY4GHiCmH1fQrOHxsyDFUWoOcNtLAKPLwL6NVvU,2155
|
|
13
|
+
someAssemblyRequired/makeNuitkaSource.py,sha256=jTK34OWzm6OsgFPd2mHwETxFo2X83io0M4YiEHRgk3U,3262
|
|
14
|
+
someAssemblyRequired/makeNumbaJob.py,sha256=L1JORHfVKjBve7GjlE4-JMnzT7wJGJISGzLbWyRCyxU,5899
|
|
15
|
+
mapFolding-0.2.7.dist-info/METADATA,sha256=i3nAtGhadvid_ODpCN9uXk9e4L3zQhXJfuElSQUmY50,7425
|
|
16
|
+
mapFolding-0.2.7.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
17
|
+
mapFolding-0.2.7.dist-info/entry_points.txt,sha256=F3OUeZR1XDTpoH7k3wXuRb3KF_kXTTeYhu5AGK1SiOQ,146
|
|
18
|
+
mapFolding-0.2.7.dist-info/top_level.txt,sha256=yHhQq-bIJhB4pZcof5hXDTIjan0nxcFuOEWb7gy1DuU,42
|
|
19
|
+
mapFolding-0.2.7.dist-info/RECORD,,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
from mapFolding import indexMy,
|
|
1
|
+
from mapFolding import indexMy, indexTrack
|
|
2
2
|
import ast
|
|
3
3
|
import copy
|
|
4
4
|
import pathlib
|
|
5
5
|
|
|
6
6
|
def getDictionaryEnumValues():
|
|
7
7
|
dictionaryEnumValues = {}
|
|
8
|
-
for enumIndex in [indexMy,
|
|
8
|
+
for enumIndex in [indexMy, indexTrack]:
|
|
9
9
|
for memberName, memberValue in enumIndex._member_map_.items():
|
|
10
10
|
dictionaryEnumValues[f"{enumIndex.__name__}.{memberName}.value"] = memberValue.value
|
|
11
11
|
return dictionaryEnumValues
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
from typing import Any, Optional, Sequence, Type
|
|
1
|
+
from typing import Any, Optional, Sequence, Type
|
|
2
2
|
|
|
3
3
|
def Z0Z_makeJob(listDimensions: Sequence[int], **keywordArguments: Optional[Type[Any]]):
|
|
4
4
|
from mapFolding import outfitCountFolds
|
|
5
5
|
stateUniversal = outfitCountFolds(listDimensions, computationDivisions=None, CPUlimit=None, **keywordArguments)
|
|
6
6
|
from mapFolding.someAssemblyRequired.countInitializeNoNumba import countInitialize
|
|
7
|
-
countInitialize(stateUniversal['connectionGraph'], stateUniversal['gapsWhere'], stateUniversal['my'], stateUniversal['
|
|
7
|
+
countInitialize(stateUniversal['connectionGraph'], stateUniversal['gapsWhere'], stateUniversal['my'], stateUniversal['track'])
|
|
8
8
|
from mapFolding import getPathFilenameFoldsTotal
|
|
9
9
|
pathFilenameChopChop = getPathFilenameFoldsTotal(stateUniversal['mapShape'])
|
|
10
10
|
import pathlib
|
|
@@ -35,11 +35,10 @@ def runJob(pathFilename):
|
|
|
35
35
|
gapsWhere: numpy.ndarray = stateJob['gapsWhere']
|
|
36
36
|
my: numpy.ndarray = stateJob['my']
|
|
37
37
|
pathFilenameFoldsTotal: Final[Path] = stateJob['pathFilenameFoldsTotal']
|
|
38
|
-
the: Final[numpy.ndarray] = stateJob['the']
|
|
39
38
|
track: numpy.ndarray = stateJob['track']
|
|
40
39
|
|
|
41
40
|
from mapFolding.someAssemblyRequired.countSequentialNoNumba import countSequential
|
|
42
|
-
countSequential(connectionGraph, foldsSubTotals, gapsWhere, my,
|
|
41
|
+
countSequential(connectionGraph, foldsSubTotals, gapsWhere, my, track)
|
|
43
42
|
|
|
44
43
|
print(foldsSubTotals.sum().item())
|
|
45
44
|
Path(pathFilenameFoldsTotal).parent.mkdir(parents=True, exist_ok=True)
|
|
@@ -16,7 +16,7 @@ import pathlib
|
|
|
16
16
|
import pickle
|
|
17
17
|
import python_minifier
|
|
18
18
|
|
|
19
|
-
listDimensions = [
|
|
19
|
+
listDimensions = [5,5]
|
|
20
20
|
|
|
21
21
|
# NOTE this overwrites files
|
|
22
22
|
Z0Z_inlineMapFolding()
|
|
@@ -38,22 +38,23 @@ def writeModuleWithNumba(listDimensions):
|
|
|
38
38
|
datatypeDefault = 'uint8'
|
|
39
39
|
numpy_dtypeDefault = make_dtype(datatypeDefault)
|
|
40
40
|
numpy_dtypeSmall = numpy_dtypeDefault
|
|
41
|
-
|
|
41
|
+
# forceinline=True might actually be useful
|
|
42
42
|
parametersNumba = f"numba.types.{datatypeLarge}(), \
|
|
43
43
|
cache=True, \
|
|
44
|
+
nopython=True, \
|
|
45
|
+
fastmath=True, \
|
|
46
|
+
forceinline=True, \
|
|
47
|
+
inline='always', \
|
|
48
|
+
looplift=False, \
|
|
49
|
+
_nrt=True, \
|
|
50
|
+
error_model='numpy', \
|
|
51
|
+
parallel=False, \
|
|
52
|
+
boundscheck=False, \
|
|
53
|
+
no_cfunc_wrapper=False, \
|
|
54
|
+
no_cpython_wrapper=False, \
|
|
44
55
|
"
|
|
45
56
|
# no_cfunc_wrapper=True, \
|
|
46
57
|
# no_cpython_wrapper=True, \
|
|
47
|
-
# _nrt=True, \
|
|
48
|
-
# nopython=True, \
|
|
49
|
-
# parallel=False, \
|
|
50
|
-
# boundscheck=False, \
|
|
51
|
-
# error_model='numpy', \
|
|
52
|
-
# fastmath=True, \
|
|
53
|
-
# no_cfunc_wrapper=False, \
|
|
54
|
-
# no_cpython_wrapper=False, \
|
|
55
|
-
# looplift=True, \
|
|
56
|
-
# forceinline=True, \
|
|
57
58
|
|
|
58
59
|
pathFilenameData = Z0Z_makeJob(listDimensions, datatypeDefault=numpy_dtypeDefault, datatypeLarge=numpy_dtypeLarge, datatypeSmall=numpy_dtypeSmall)
|
|
59
60
|
|
|
@@ -74,14 +75,13 @@ cache=True, \
|
|
|
74
75
|
linesDataDynamic = "\n".join([linesDataDynamic
|
|
75
76
|
, ImaIndent + f"foldsTotal = numba.types.{datatypeLarge}(0)"
|
|
76
77
|
, ImaIndent + convertNDArrayToStr(stateJob['my'], 'my')
|
|
77
|
-
, ImaIndent + convertNDArrayToStr(stateJob['
|
|
78
|
+
, ImaIndent + convertNDArrayToStr(stateJob['foldGroups'], 'foldGroups')
|
|
78
79
|
, ImaIndent + convertNDArrayToStr(stateJob['gapsWhere'], 'gapsWhere')
|
|
79
80
|
, ImaIndent + convertNDArrayToStr(stateJob['track'], 'track')
|
|
80
81
|
])
|
|
81
82
|
|
|
82
83
|
linesDataStatic = """"""
|
|
83
84
|
linesDataStatic = "\n".join([linesDataStatic
|
|
84
|
-
, ImaIndent + convertNDArrayToStr(stateJob['the'], 'the')
|
|
85
85
|
, ImaIndent + convertNDArrayToStr(stateJob['connectionGraph'], 'connectionGraph')
|
|
86
86
|
])
|
|
87
87
|
|
|
@@ -106,11 +106,14 @@ cache=True, \
|
|
|
106
106
|
linesLaunch = """"""
|
|
107
107
|
linesLaunch = linesLaunch + f"""
|
|
108
108
|
if __name__ == '__main__':
|
|
109
|
-
|
|
109
|
+
import time
|
|
110
|
+
timeStart = time.perf_counter()
|
|
111
|
+
{identifierCallableLaunch}()
|
|
112
|
+
print(time.perf_counter() - timeStart)"""
|
|
110
113
|
|
|
111
114
|
linesWriteFoldsTotal = """"""
|
|
112
115
|
linesWriteFoldsTotal = "\n".join([linesWriteFoldsTotal
|
|
113
|
-
, " foldsTotal =
|
|
116
|
+
, " foldsTotal = foldGroups[0:-1].sum() * foldGroups[-1]"
|
|
114
117
|
, " print(foldsTotal)"
|
|
115
118
|
, " with numba.objmode():"
|
|
116
119
|
, f" open('{pathFilenameFoldsTotal.as_posix()}', 'w').write(str(foldsTotal))"
|
mapFolding/__init__.py
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
from .theSSOT import *
|
|
2
|
-
from Z0Z_tools import defineConcurrencyLimit, intInnit, oopsieKwargsie
|
|
3
|
-
from .beDRY import getFilenameFoldsTotal, getPathFilenameFoldsTotal, outfitCountFolds, saveFoldsTotal
|
|
4
|
-
from .startHere import countFolds
|
|
5
|
-
from .oeis import oeisIDfor_n, getOEISids, clearOEIScache
|
|
6
|
-
|
|
7
|
-
__all__ = [
|
|
8
|
-
'clearOEIScache',
|
|
9
|
-
'countFolds',
|
|
10
|
-
'getOEISids',
|
|
11
|
-
'oeisIDfor_n',
|
|
12
|
-
]
|
mapFolding/babbage.py
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
from mapFolding.importSelector import countSequential, countParallel, countInitialize
|
|
2
|
-
from mapFolding import indexMy
|
|
3
|
-
from numpy import integer
|
|
4
|
-
from numpy.typing import NDArray
|
|
5
|
-
from typing import Any, Tuple
|
|
6
|
-
import numba
|
|
7
|
-
import numpy
|
|
8
|
-
|
|
9
|
-
@numba.jit(cache=True)
|
|
10
|
-
def _countFolds(connectionGraph: NDArray[integer[Any]], foldGroups: NDArray[integer[Any]], gapsWhere: NDArray[integer[Any]], mapShape: Tuple[int, ...], my: NDArray[integer[Any]], track: NDArray[integer[Any]]):
|
|
11
|
-
"""
|
|
12
|
-
What in tarnation is this stupid module and function?
|
|
13
|
-
|
|
14
|
-
- This function is not in the same module as `countFolds` so that we can delay Numba just-in-time (jit) compilation of this function and the finalization of its settings until we are ready.
|
|
15
|
-
- This function is not in the same module as `countFoldsCompiled`, which is the function that does the hard, so that we can delay `numba.jit` compilation of `countFoldsCompiled`.
|
|
16
|
-
- `countFoldsCompiled` is not merely "jitted", it is super jitted, which makes it too arrogant to talk to plebian Python functions. It will, however, reluctantly talk to basic jitted functions.
|
|
17
|
-
- The function in this module is jitted, so it can talk to `countFoldsCompiled`, and because it isn't so arrogant, it will talk to the low-class `countFolds` with only a few restrictions, such as:
|
|
18
|
-
- No `TypedDict`
|
|
19
|
-
- No Python v 3.13
|
|
20
|
-
- The plebs must clean up their own memory problems
|
|
21
|
-
- No oversized integers
|
|
22
|
-
- No global variables, only global constants
|
|
23
|
-
- They don't except pleb nonlocal variables either
|
|
24
|
-
- Python "class": they are all inferior to a jit
|
|
25
|
-
- No `**kwargs`
|
|
26
|
-
- and just a few dozen-jillion other things.
|
|
27
|
-
|
|
28
|
-
"""
|
|
29
|
-
# print("babbage")
|
|
30
|
-
countInitialize(connectionGraph=connectionGraph, gapsWhere=gapsWhere, my=my, track=track)
|
|
31
|
-
|
|
32
|
-
if my[indexMy.taskDivisions.value] > 0:
|
|
33
|
-
countParallel(connectionGraph=connectionGraph, foldGroups=foldGroups, gapsWherePARALLEL=gapsWhere, myPARALLEL=my, trackPARALLEL=track)
|
|
34
|
-
else:
|
|
35
|
-
countSequential(connectionGraph=connectionGraph, foldGroups=foldGroups, gapsWhere=gapsWhere, my=my, track=track)
|
mapFolding/beDRY.py
DELETED
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
"""A relatively stable API for oft-needed functionality."""
|
|
2
|
-
from mapFolding import dtypeDefault, dtypeLarge, dtypeSmall, pathJobDEFAULT
|
|
3
|
-
from mapFolding import indexMy, indexTrack, computationState
|
|
4
|
-
from mapFolding import intInnit, defineConcurrencyLimit, oopsieKwargsie
|
|
5
|
-
from numpy import integer
|
|
6
|
-
from numpy.typing import NDArray
|
|
7
|
-
from typing import Any, List, Optional, Sequence, Type, Union
|
|
8
|
-
import numba
|
|
9
|
-
import numpy
|
|
10
|
-
import os
|
|
11
|
-
import pathlib
|
|
12
|
-
import sys
|
|
13
|
-
|
|
14
|
-
def getFilenameFoldsTotal(listDimensions: Sequence[int]) -> str:
|
|
15
|
-
return str(sorted(listDimensions)).replace(', ', 'x').replace('[', 'p').replace(']', '') + '.foldsTotal'
|
|
16
|
-
|
|
17
|
-
def getLeavesTotal(listDimensions: Sequence[int]) -> int:
|
|
18
|
-
"""
|
|
19
|
-
How many leaves are in the map.
|
|
20
|
-
|
|
21
|
-
Parameters:
|
|
22
|
-
listDimensions: A list of integers representing dimensions.
|
|
23
|
-
|
|
24
|
-
Returns:
|
|
25
|
-
productDimensions: The product of all positive integer dimensions.
|
|
26
|
-
"""
|
|
27
|
-
listNonNegative = parseDimensions(listDimensions, 'listDimensions')
|
|
28
|
-
listPositive = [dimension for dimension in listNonNegative if dimension > 0]
|
|
29
|
-
|
|
30
|
-
if not listPositive:
|
|
31
|
-
return 0
|
|
32
|
-
else:
|
|
33
|
-
productDimensions = 1
|
|
34
|
-
for dimension in listPositive:
|
|
35
|
-
if dimension > sys.maxsize // productDimensions:
|
|
36
|
-
raise OverflowError(f"I received {dimension=} in {listDimensions=}, but the product of the dimensions exceeds the maximum size of an integer on this system.")
|
|
37
|
-
productDimensions *= dimension
|
|
38
|
-
|
|
39
|
-
return productDimensions
|
|
40
|
-
|
|
41
|
-
def getPathFilenameFoldsTotal(listDimensions: Sequence[int], pathishWriteFoldsTotal: Optional[Union[str, os.PathLike[str]]] = None) -> pathlib.Path:
|
|
42
|
-
pathFilenameFoldsTotal = pathlib.Path(pathishWriteFoldsTotal) if pathishWriteFoldsTotal is not None else pathJobDEFAULT
|
|
43
|
-
if pathFilenameFoldsTotal.is_dir():
|
|
44
|
-
filenameFoldsTotalDEFAULT = getFilenameFoldsTotal(listDimensions)
|
|
45
|
-
pathFilenameFoldsTotal = pathFilenameFoldsTotal / filenameFoldsTotalDEFAULT
|
|
46
|
-
pathFilenameFoldsTotal.parent.mkdir(parents=True, exist_ok=True)
|
|
47
|
-
return pathFilenameFoldsTotal
|
|
48
|
-
|
|
49
|
-
def getTaskDivisions(computationDivisions: Optional[Union[int, str]], concurrencyLimit: int, CPUlimit: Optional[Union[bool, float, int]], listDimensions: Sequence[int]):
|
|
50
|
-
"""
|
|
51
|
-
Determines whether or how to divide the computation into tasks.
|
|
52
|
-
|
|
53
|
-
Parameters
|
|
54
|
-
----------
|
|
55
|
-
computationDivisions (None):
|
|
56
|
-
Specifies how to divide computations:
|
|
57
|
-
- None: no division of the computation into tasks; sets task divisions to 0
|
|
58
|
-
- int: direct set the number of task divisions; cannot exceed the map's total leaves
|
|
59
|
-
- "maximum": divides into `leavesTotal`-many `taskDivisions`
|
|
60
|
-
- "cpu": limits the divisions to the number of available CPUs, i.e. `concurrencyLimit`
|
|
61
|
-
concurrencyLimit:
|
|
62
|
-
Maximum number of concurrent tasks allowed
|
|
63
|
-
listDimensions: for error reporting
|
|
64
|
-
CPUlimit: for error reporting
|
|
65
|
-
|
|
66
|
-
Returns
|
|
67
|
-
-------
|
|
68
|
-
taskDivisions:
|
|
69
|
-
|
|
70
|
-
Raises
|
|
71
|
-
------
|
|
72
|
-
ValueError
|
|
73
|
-
If computationDivisions is an unsupported type or if resulting task divisions exceed total leaves
|
|
74
|
-
|
|
75
|
-
Notes
|
|
76
|
-
-----
|
|
77
|
-
Task divisions cannot exceed total leaves to prevent duplicate counting of folds.
|
|
78
|
-
"""
|
|
79
|
-
if not computationDivisions:
|
|
80
|
-
return 0
|
|
81
|
-
else:
|
|
82
|
-
leavesTotal = getLeavesTotal(listDimensions)
|
|
83
|
-
if isinstance(computationDivisions, int):
|
|
84
|
-
taskDivisions = computationDivisions
|
|
85
|
-
elif isinstance(computationDivisions, str):
|
|
86
|
-
computationDivisions = computationDivisions.lower()
|
|
87
|
-
if computationDivisions == "maximum":
|
|
88
|
-
taskDivisions = leavesTotal
|
|
89
|
-
elif computationDivisions == "cpu":
|
|
90
|
-
taskDivisions = min(concurrencyLimit, leavesTotal)
|
|
91
|
-
else:
|
|
92
|
-
raise ValueError(f"I received {computationDivisions} for the parameter, `computationDivisions`, but the so-called programmer didn't implement code for that.")
|
|
93
|
-
|
|
94
|
-
if taskDivisions > leavesTotal:
|
|
95
|
-
raise ValueError(f"Problem: `taskDivisions`, ({taskDivisions}), is greater than `leavesTotal`, ({leavesTotal}), which will cause duplicate counting of the folds.\n\nChallenge: you cannot directly set `taskDivisions` or `leavesTotal`. They are derived from parameters that may or may not still be named `computationDivisions`, `CPUlimit` , and `listDimensions` and from dubious-quality Python code.\n\nFor those parameters, I received {computationDivisions=}, {CPUlimit=}, and {listDimensions=}.\n\nPotential solutions: get a different hobby or set `computationDivisions` to a different value.")
|
|
96
|
-
|
|
97
|
-
return taskDivisions
|
|
98
|
-
|
|
99
|
-
def makeConnectionGraph(listDimensions: Sequence[int], **keywordArguments: Optional[Type]) -> NDArray[integer[Any]]:
|
|
100
|
-
"""
|
|
101
|
-
Constructs a multi-dimensional connection graph representing the connections between the leaves of a map with the given dimensions.
|
|
102
|
-
Also called a Cartesian product decomposition or dimensional product mapping.
|
|
103
|
-
|
|
104
|
-
Parameters
|
|
105
|
-
listDimensions: A sequence of integers representing the dimensions of the map.
|
|
106
|
-
|
|
107
|
-
Returns
|
|
108
|
-
connectionGraph: A 3D numpy array with shape of (dimensionsTotal, leavesTotal + 1, leavesTotal + 1).
|
|
109
|
-
"""
|
|
110
|
-
datatype = keywordArguments.get('datatype', dtypeDefault)
|
|
111
|
-
mapShape = validateListDimensions(listDimensions)
|
|
112
|
-
leavesTotal = getLeavesTotal(mapShape)
|
|
113
|
-
arrayDimensions = numpy.array(mapShape, dtype=datatype)
|
|
114
|
-
dimensionsTotal = len(arrayDimensions)
|
|
115
|
-
|
|
116
|
-
# Step 1: find the cumulative product of the map's dimensions
|
|
117
|
-
cumulativeProduct = numpy.multiply.accumulate([1] + mapShape, dtype=datatype)
|
|
118
|
-
|
|
119
|
-
# Step 2: create a coordinate system
|
|
120
|
-
coordinateSystem = numpy.zeros((dimensionsTotal, leavesTotal + 1), dtype=datatype)
|
|
121
|
-
|
|
122
|
-
for indexDimension in range(dimensionsTotal):
|
|
123
|
-
for leaf1ndex in range(1, leavesTotal + 1):
|
|
124
|
-
coordinateSystem[indexDimension, leaf1ndex] = (
|
|
125
|
-
((leaf1ndex - 1) // cumulativeProduct[indexDimension]) %
|
|
126
|
-
arrayDimensions[indexDimension] + 1
|
|
127
|
-
)
|
|
128
|
-
|
|
129
|
-
# Step 3: create and fill the connection graph
|
|
130
|
-
connectionGraph = numpy.zeros((dimensionsTotal, leavesTotal + 1, leavesTotal + 1), dtype=datatype)
|
|
131
|
-
|
|
132
|
-
for indexDimension in range(dimensionsTotal):
|
|
133
|
-
for activeLeaf1ndex in range(1, leavesTotal + 1):
|
|
134
|
-
for connectee1ndex in range(1, activeLeaf1ndex + 1):
|
|
135
|
-
# Base coordinate conditions
|
|
136
|
-
isFirstCoord = coordinateSystem[indexDimension, connectee1ndex] == 1
|
|
137
|
-
isLastCoord = coordinateSystem[indexDimension, connectee1ndex] == arrayDimensions[indexDimension]
|
|
138
|
-
exceedsActive = connectee1ndex + cumulativeProduct[indexDimension] > activeLeaf1ndex
|
|
139
|
-
|
|
140
|
-
# Parity check
|
|
141
|
-
isEvenParity = (coordinateSystem[indexDimension, activeLeaf1ndex] & 1) == \
|
|
142
|
-
(coordinateSystem[indexDimension, connectee1ndex] & 1)
|
|
143
|
-
|
|
144
|
-
# Determine connection value
|
|
145
|
-
if (isEvenParity and isFirstCoord) or (not isEvenParity and (isLastCoord or exceedsActive)):
|
|
146
|
-
connectionGraph[indexDimension, activeLeaf1ndex, connectee1ndex] = connectee1ndex
|
|
147
|
-
elif isEvenParity and not isFirstCoord:
|
|
148
|
-
connectionGraph[indexDimension, activeLeaf1ndex, connectee1ndex] = connectee1ndex - cumulativeProduct[indexDimension]
|
|
149
|
-
elif not isEvenParity and not (isLastCoord or exceedsActive):
|
|
150
|
-
connectionGraph[indexDimension, activeLeaf1ndex, connectee1ndex] = connectee1ndex + cumulativeProduct[indexDimension]
|
|
151
|
-
|
|
152
|
-
return connectionGraph
|
|
153
|
-
|
|
154
|
-
def makeDataContainer(shape, datatype: Optional[Type] = None):
|
|
155
|
-
"""Create a container, probably numpy.ndarray, with the given shape and datatype."""
|
|
156
|
-
if datatype is None:
|
|
157
|
-
datatype = dtypeDefault
|
|
158
|
-
return numpy.zeros(shape, dtype=datatype)
|
|
159
|
-
|
|
160
|
-
def outfitCountFolds(listDimensions: Sequence[int], computationDivisions: Optional[Union[int, str]] = None, CPUlimit: Optional[Union[bool, float, int]] = None, **keywordArguments: Optional[Type[Any]]) -> computationState:
|
|
161
|
-
"""
|
|
162
|
-
Initializes and configures the computation state for map folding computations.
|
|
163
|
-
|
|
164
|
-
Parameters
|
|
165
|
-
----------
|
|
166
|
-
listDimensions:
|
|
167
|
-
The dimensions of the map to be folded
|
|
168
|
-
computationDivisions (None):
|
|
169
|
-
Specifies how to divide computations:
|
|
170
|
-
- None: no division of the computation into tasks; sets task divisions to 0
|
|
171
|
-
- int: direct set the number of task divisions; cannot exceed the map's total leaves
|
|
172
|
-
- "maximum": divides into `leavesTotal`-many `taskDivisions`
|
|
173
|
-
- "cpu": limits the divisions to the number of available CPUs, i.e. `concurrencyLimit`
|
|
174
|
-
CPUlimit (None):
|
|
175
|
-
Whether and how to limit the CPU usage. See notes for details.
|
|
176
|
-
|
|
177
|
-
Returns
|
|
178
|
-
-------
|
|
179
|
-
computationState
|
|
180
|
-
An initialized computation state containing:
|
|
181
|
-
- connectionGraph: Graph representing connections in the map
|
|
182
|
-
- foldsSubTotals: Array tracking total folds
|
|
183
|
-
- mapShape: Validated and sorted dimensions of the map
|
|
184
|
-
- my: Array for internal state tracking
|
|
185
|
-
- gapsWhere: Array tracking gap positions
|
|
186
|
-
- the: Static settings and metadata
|
|
187
|
-
- track: Array for tracking computation progress
|
|
188
|
-
|
|
189
|
-
Limits on CPU usage `CPUlimit`:
|
|
190
|
-
- `False`, `None`, or `0`: No limits on CPU usage; uses all available CPUs. All other values will potentially limit CPU usage.
|
|
191
|
-
- `True`: Yes, limit the CPU usage; limits to 1 CPU.
|
|
192
|
-
- Integer `>= 1`: Limits usage to the specified number of CPUs.
|
|
193
|
-
- Decimal value (`float`) between 0 and 1: Fraction of total CPUs to use.
|
|
194
|
-
- Decimal value (`float`) between -1 and 0: Fraction of CPUs to *not* use.
|
|
195
|
-
- Integer `<= -1`: Subtract the absolute value from total CPUs.
|
|
196
|
-
"""
|
|
197
|
-
datatypeDefault = keywordArguments.get('datatypeDefault', dtypeDefault)
|
|
198
|
-
datatypeLarge = keywordArguments.get('datatypeLarge', dtypeLarge)
|
|
199
|
-
datatypeSmall = keywordArguments.get('datatypeSmall', dtypeSmall)
|
|
200
|
-
|
|
201
|
-
my = makeDataContainer(len(indexMy), datatypeDefault)
|
|
202
|
-
|
|
203
|
-
mapShape = tuple(sorted(validateListDimensions(listDimensions)))
|
|
204
|
-
concurrencyLimit = setCPUlimit(CPUlimit)
|
|
205
|
-
my[indexMy.taskDivisions] = getTaskDivisions(computationDivisions, concurrencyLimit, CPUlimit, mapShape)
|
|
206
|
-
|
|
207
|
-
foldGroups = makeDataContainer(max(my[indexMy.taskDivisions] + 1, 2), datatypeLarge)
|
|
208
|
-
foldGroups[-1] = leavesTotal = getLeavesTotal(mapShape)
|
|
209
|
-
|
|
210
|
-
my[indexMy.dimensionsTotal] = len(mapShape)
|
|
211
|
-
my[indexMy.leaf1ndex] = 1
|
|
212
|
-
stateInitialized = computationState(
|
|
213
|
-
connectionGraph = makeConnectionGraph(mapShape, datatype=datatypeSmall),
|
|
214
|
-
foldGroups = foldGroups,
|
|
215
|
-
mapShape = mapShape,
|
|
216
|
-
my = my,
|
|
217
|
-
gapsWhere = makeDataContainer(int(leavesTotal) * int(leavesTotal) + 1, datatypeSmall),
|
|
218
|
-
track = makeDataContainer((len(indexTrack), leavesTotal + 1), datatypeDefault)
|
|
219
|
-
)
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return stateInitialized
|
|
223
|
-
|
|
224
|
-
def parseDimensions(dimensions: Sequence[int], parameterName: str = 'listDimensions') -> List[int]:
|
|
225
|
-
"""
|
|
226
|
-
Parse and validate dimensions are non-negative integers.
|
|
227
|
-
|
|
228
|
-
Parameters:
|
|
229
|
-
dimensions: Sequence of integers representing dimensions
|
|
230
|
-
parameterName ('listDimensions'): Name of the parameter for error messages. Defaults to 'listDimensions'
|
|
231
|
-
Returns:
|
|
232
|
-
listNonNegative: List of validated non-negative integers
|
|
233
|
-
Raises:
|
|
234
|
-
ValueError: If any dimension is negative or if the list is empty
|
|
235
|
-
TypeError: If any element cannot be converted to integer (raised by intInnit)
|
|
236
|
-
"""
|
|
237
|
-
listValidated = intInnit(dimensions, parameterName)
|
|
238
|
-
listNonNegative = []
|
|
239
|
-
for dimension in listValidated:
|
|
240
|
-
if dimension < 0:
|
|
241
|
-
raise ValueError(f"Dimension {dimension} must be non-negative")
|
|
242
|
-
listNonNegative.append(dimension)
|
|
243
|
-
|
|
244
|
-
return listNonNegative
|
|
245
|
-
|
|
246
|
-
def saveFoldsTotal(pathFilename: Union[str, os.PathLike[str]], foldsTotal: int) -> None:
|
|
247
|
-
"""
|
|
248
|
-
Save foldsTotal with multiple fallback mechanisms.
|
|
249
|
-
|
|
250
|
-
Parameters:
|
|
251
|
-
pathFilename: Target save location
|
|
252
|
-
foldsTotal: Critical computed value to save
|
|
253
|
-
"""
|
|
254
|
-
try:
|
|
255
|
-
pathFilenameFoldsTotal = pathlib.Path(pathFilename)
|
|
256
|
-
pathFilenameFoldsTotal.parent.mkdir(parents=True, exist_ok=True)
|
|
257
|
-
pathFilenameFoldsTotal.write_text(str(foldsTotal))
|
|
258
|
-
except Exception as ERRORmessage:
|
|
259
|
-
try:
|
|
260
|
-
print(f"\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n\n{foldsTotal=}\n\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n")
|
|
261
|
-
print(ERRORmessage)
|
|
262
|
-
print(f"\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n\n{foldsTotal=}\n\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n")
|
|
263
|
-
randomnessPlanB = (int(str(foldsTotal).strip()[-1]) + 1) * ['YO_']
|
|
264
|
-
filenameInfixUnique = ''.join(randomnessPlanB)
|
|
265
|
-
pathFilenamePlanB = os.path.join(os.getcwd(), 'foldsTotal' + filenameInfixUnique + '.txt')
|
|
266
|
-
writeStreamFallback = open(pathFilenamePlanB, 'w')
|
|
267
|
-
writeStreamFallback.write(str(foldsTotal))
|
|
268
|
-
writeStreamFallback.close()
|
|
269
|
-
print(str(pathFilenamePlanB))
|
|
270
|
-
except:
|
|
271
|
-
print(foldsTotal)
|
|
272
|
-
|
|
273
|
-
def setCPUlimit(CPUlimit: Union[bool, float, int, None]) -> int:
|
|
274
|
-
"""Sets CPU limit for Numba concurrent operations. Note that it can only affect Numba-jitted functions that have not yet been imported.
|
|
275
|
-
|
|
276
|
-
Parameters:
|
|
277
|
-
CPUlimit: whether and how to limit the CPU usage. See notes for details.
|
|
278
|
-
Returns:
|
|
279
|
-
concurrencyLimit: The actual concurrency limit that was set
|
|
280
|
-
Raises:
|
|
281
|
-
TypeError: If CPUlimit is not of the expected types
|
|
282
|
-
|
|
283
|
-
Limits on CPU usage `CPUlimit`:
|
|
284
|
-
- `False`, `None`, or `0`: No limits on CPU usage; uses all available CPUs. All other values will potentially limit CPU usage.
|
|
285
|
-
- `True`: Yes, limit the CPU usage; limits to 1 CPU.
|
|
286
|
-
- Integer `>= 1`: Limits usage to the specified number of CPUs.
|
|
287
|
-
- Decimal value (`float`) between 0 and 1: Fraction of total CPUs to use.
|
|
288
|
-
- Decimal value (`float`) between -1 and 0: Fraction of CPUs to *not* use.
|
|
289
|
-
- Integer `<= -1`: Subtract the absolute value from total CPUs.
|
|
290
|
-
"""
|
|
291
|
-
if not (CPUlimit is None or isinstance(CPUlimit, (bool, int, float))):
|
|
292
|
-
CPUlimit = oopsieKwargsie(CPUlimit)
|
|
293
|
-
|
|
294
|
-
concurrencyLimit = defineConcurrencyLimit(CPUlimit)
|
|
295
|
-
numba.set_num_threads(concurrencyLimit)
|
|
296
|
-
|
|
297
|
-
return concurrencyLimit
|
|
298
|
-
|
|
299
|
-
def validateListDimensions(listDimensions: Sequence[int]) -> List[int]:
|
|
300
|
-
"""
|
|
301
|
-
Validates and sorts a sequence of at least two positive dimensions.
|
|
302
|
-
|
|
303
|
-
Parameters:
|
|
304
|
-
listDimensions: A sequence of integer dimensions to be validated.
|
|
305
|
-
|
|
306
|
-
Returns:
|
|
307
|
-
dimensionsValidSorted: A list, with at least two elements, of only positive integers.
|
|
308
|
-
|
|
309
|
-
Raises:
|
|
310
|
-
ValueError: If the input listDimensions is None.
|
|
311
|
-
NotImplementedError: If the resulting list of positive dimensions has fewer than two elements.
|
|
312
|
-
"""
|
|
313
|
-
if not listDimensions:
|
|
314
|
-
raise ValueError(f"listDimensions is a required parameter.")
|
|
315
|
-
listNonNegative = parseDimensions(listDimensions, 'listDimensions')
|
|
316
|
-
dimensionsValid = [dimension for dimension in listNonNegative if dimension > 0]
|
|
317
|
-
if len(dimensionsValid) < 2:
|
|
318
|
-
raise NotImplementedError(f"This function requires listDimensions, {listDimensions}, to have at least two dimensions greater than 0. You may want to look at https://oeis.org/.")
|
|
319
|
-
return sorted(dimensionsValid)
|
mapFolding/importSelector.py
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
from mapFolding.lovelace import countSequential
|
|
2
|
-
from mapFolding.lovelace import countParallel
|
|
3
|
-
from mapFolding.lovelace import countInitialize
|
|
4
|
-
|
|
5
|
-
# from mapFolding.someAssemblyRequired.countSequential import countSequential
|
|
6
|
-
# from mapFolding.someAssemblyRequired.countParallel import countParallel
|
|
7
|
-
# from mapFolding.someAssemblyRequired.countInitialize import countInitialize
|