mapFolding 0.12.2__py3-none-any.whl → 0.12.3__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 +4 -2
- mapFolding/_theSSOT.py +32 -88
- mapFolding/{datatypes.py → _theTypes.py} +25 -3
- mapFolding/basecamp.py +39 -34
- mapFolding/beDRY.py +79 -54
- mapFolding/dataBaskets.py +117 -74
- mapFolding/filesystemToolkit.py +140 -91
- mapFolding/oeis.py +242 -144
- mapFolding/reference/flattened.py +1 -1
- mapFolding/someAssemblyRequired/RecipeJob.py +68 -53
- mapFolding/someAssemblyRequired/__init__.py +40 -15
- mapFolding/someAssemblyRequired/_toolIfThis.py +82 -54
- mapFolding/someAssemblyRequired/_toolkitContainers.py +19 -16
- mapFolding/someAssemblyRequired/getLLVMforNoReason.py +35 -26
- mapFolding/someAssemblyRequired/makeAllModules.py +348 -275
- mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +81 -57
- mapFolding/someAssemblyRequired/toolkitNumba.py +80 -50
- mapFolding/someAssemblyRequired/transformationTools.py +63 -40
- {mapfolding-0.12.2.dist-info → mapfolding-0.12.3.dist-info}/METADATA +7 -11
- {mapfolding-0.12.2.dist-info → mapfolding-0.12.3.dist-info}/RECORD +28 -28
- tests/test_computations.py +26 -8
- tests/test_oeis.py +8 -7
- tests/test_other.py +3 -3
- tests/test_tasks.py +2 -4
- {mapfolding-0.12.2.dist-info → mapfolding-0.12.3.dist-info}/WHEEL +0 -0
- {mapfolding-0.12.2.dist-info → mapfolding-0.12.3.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.12.2.dist-info → mapfolding-0.12.3.dist-info}/licenses/LICENSE +0 -0
- {mapfolding-0.12.2.dist-info → mapfolding-0.12.3.dist-info}/top_level.txt +0 -0
mapFolding/filesystemToolkit.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"""
|
|
2
2
|
Persistent storage infrastructure for map folding computation results.
|
|
3
3
|
|
|
4
|
+
(AI generated docstring)
|
|
5
|
+
|
|
4
6
|
As computational state management orchestrates the complex recursive analysis,
|
|
5
7
|
this module ensures that the valuable results of potentially multi-day computations
|
|
6
8
|
are safely preserved and reliably retrievable. Map folding problems can require
|
|
@@ -27,47 +29,57 @@ import os
|
|
|
27
29
|
import platformdirs
|
|
28
30
|
|
|
29
31
|
def getFilenameFoldsTotal(mapShape: tuple[int, ...]) -> str:
|
|
30
|
-
"""
|
|
31
|
-
|
|
32
|
+
"""Create a standardized filename for a computed `foldsTotal` value.
|
|
33
|
+
|
|
34
|
+
(AI generated docstring)
|
|
32
35
|
|
|
33
36
|
This function generates a consistent, filesystem-safe filename based on map dimensions. Standardizing filenames
|
|
34
37
|
ensures that results can be reliably stored and retrieved, avoiding potential filesystem incompatibilities or Python
|
|
35
38
|
naming restrictions.
|
|
36
39
|
|
|
37
|
-
Parameters
|
|
38
|
-
|
|
40
|
+
Parameters
|
|
41
|
+
----------
|
|
42
|
+
mapShape : tuple[int, ...]
|
|
43
|
+
A sequence of integers representing the dimensions of the map.
|
|
44
|
+
|
|
45
|
+
Returns
|
|
46
|
+
-------
|
|
47
|
+
filenameFoldsTotal : str
|
|
48
|
+
A filename string in format 'pMxN.foldsTotal' where M,N are sorted dimensions.
|
|
39
49
|
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
Notes
|
|
51
|
+
-----
|
|
52
|
+
The filename format ensures no spaces in the filename, safe filesystem characters, unique extension (.foldsTotal),
|
|
53
|
+
Python-safe strings (no starting with numbers, no reserved words), and the 'p' prefix comes from Lunnon's original code.
|
|
42
54
|
|
|
43
|
-
Notes:
|
|
44
|
-
The filename format ensures:
|
|
45
|
-
- No spaces in the filename
|
|
46
|
-
- Safe filesystem characters
|
|
47
|
-
- Unique extension (.foldsTotal)
|
|
48
|
-
- Python-safe strings (no starting with numbers, no reserved words)
|
|
49
|
-
- The 'p' prefix comes from Lunnon's original code.
|
|
50
55
|
"""
|
|
51
56
|
return 'p' + 'x'.join(str(dimension) for dimension in sorted(mapShape)) + '.foldsTotal'
|
|
52
57
|
|
|
53
58
|
def getPathFilenameFoldsTotal(mapShape: tuple[int, ...], pathLikeWriteFoldsTotal: PathLike[str] | PurePath | None = None) -> Path:
|
|
54
|
-
"""
|
|
55
|
-
|
|
59
|
+
"""Get a standardized path and filename for the computed `foldsTotal` value.
|
|
60
|
+
|
|
61
|
+
(AI generated docstring)
|
|
56
62
|
|
|
57
63
|
This function resolves paths for storing computation results, handling different input types including directories,
|
|
58
64
|
absolute paths, or relative paths. It ensures that all parent directories exist in the resulting path.
|
|
59
|
-
Parameters:
|
|
60
|
-
mapShape: A sequence of integers representing the map dimensions.
|
|
61
|
-
pathLikeWriteFoldsTotal (getPathRootJobDEFAULT): Path, filename, or relative path and filename. If None, uses
|
|
62
|
-
default path. If a directory, appends standardized filename.
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
Parameters
|
|
67
|
+
----------
|
|
68
|
+
mapShape : tuple[int, ...]
|
|
69
|
+
A sequence of integers representing the map dimensions.
|
|
70
|
+
pathLikeWriteFoldsTotal : PathLike[str] | PurePath | None = getPathRootJobDEFAULT()
|
|
71
|
+
Path, filename, or relative path and filename. If None, uses default path. If a directory, appends standardized filename.
|
|
66
72
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
Returns
|
|
74
|
+
-------
|
|
75
|
+
pathFilenameFoldsTotal : Path
|
|
76
|
+
Absolute path and filename for storing the `foldsTotal` value.
|
|
70
77
|
|
|
78
|
+
Notes
|
|
79
|
+
-----
|
|
80
|
+
The function creates any necessary directories in the path if they don't exist.
|
|
81
|
+
|
|
82
|
+
"""
|
|
71
83
|
if pathLikeWriteFoldsTotal is None:
|
|
72
84
|
pathFilenameFoldsTotal = getPathRootJobDEFAULT() / getFilenameFoldsTotal(mapShape)
|
|
73
85
|
else:
|
|
@@ -83,133 +95,170 @@ def getPathFilenameFoldsTotal(mapShape: tuple[int, ...], pathLikeWriteFoldsTotal
|
|
|
83
95
|
return pathFilenameFoldsTotal
|
|
84
96
|
|
|
85
97
|
def getPathRootJobDEFAULT() -> Path:
|
|
86
|
-
"""
|
|
87
|
-
|
|
98
|
+
"""Get the default root directory for map folding computation jobs.
|
|
99
|
+
|
|
100
|
+
(AI generated docstring)
|
|
88
101
|
|
|
89
102
|
This function determines the appropriate default directory for storing computation results based on the current
|
|
90
103
|
runtime environment. It uses platform-specific directories for normal environments and adapts to special
|
|
91
104
|
environments like Google Colab.
|
|
92
105
|
|
|
93
|
-
Returns
|
|
94
|
-
|
|
106
|
+
Returns
|
|
107
|
+
-------
|
|
108
|
+
pathJobDEFAULT : Path
|
|
109
|
+
Path to the default directory for storing computation results.
|
|
110
|
+
|
|
111
|
+
Notes
|
|
112
|
+
-----
|
|
113
|
+
For standard environments, uses `platformdirs` to find appropriate user data directory.
|
|
114
|
+
For Google Colab, uses a specific path in Google Drive.
|
|
115
|
+
Creates the directory if it doesn't exist.
|
|
95
116
|
|
|
96
|
-
Notes:
|
|
97
|
-
- For standard environments, uses `platformdirs` to find appropriate user data directory.
|
|
98
|
-
- For Google Colab, uses a specific path in Google Drive.
|
|
99
|
-
- Creates the directory if it doesn't exist.
|
|
100
117
|
"""
|
|
101
|
-
pathJobDEFAULT = Path(platformdirs.user_data_dir(appname=packageSettings.
|
|
118
|
+
pathJobDEFAULT = Path(platformdirs.user_data_dir(appname=packageSettings.identifierPackage, appauthor=False, ensure_exists=True))
|
|
102
119
|
if 'google.colab' in sysModules:
|
|
103
|
-
pathJobDEFAULT = Path("/content/drive/MyDrive") / packageSettings.
|
|
120
|
+
pathJobDEFAULT = Path("/content/drive/MyDrive") / packageSettings.identifierPackage
|
|
104
121
|
pathJobDEFAULT.mkdir(parents=True, exist_ok=True)
|
|
105
122
|
return pathJobDEFAULT
|
|
106
123
|
|
|
107
124
|
def _saveFoldsTotal(pathFilename: PathLike[str] | PurePath, foldsTotal: int) -> None:
|
|
108
|
-
"""
|
|
109
|
-
|
|
125
|
+
"""Save a `foldsTotal` value to a file.
|
|
126
|
+
|
|
127
|
+
(AI generated docstring)
|
|
110
128
|
|
|
111
129
|
This function provides the core file writing functionality used by the public `saveFoldsTotal` function. It handles
|
|
112
130
|
the basic operations of creating parent directories and writing the integer value as text to the specified file
|
|
113
131
|
location.
|
|
114
132
|
|
|
115
|
-
Parameters
|
|
116
|
-
|
|
117
|
-
|
|
133
|
+
Parameters
|
|
134
|
+
----------
|
|
135
|
+
pathFilename : PathLike[str] | PurePath
|
|
136
|
+
Path where the `foldsTotal` value should be saved.
|
|
137
|
+
foldsTotal : int
|
|
138
|
+
The integer value to save.
|
|
139
|
+
|
|
140
|
+
Notes
|
|
141
|
+
-----
|
|
142
|
+
This is an internal function that doesn't include error handling or fallback mechanisms. Use `saveFoldsTotal`
|
|
143
|
+
for production code that requires robust error handling.
|
|
118
144
|
|
|
119
|
-
Notes:
|
|
120
|
-
This is an internal function that doesn't include error handling or fallback mechanisms. Use `saveFoldsTotal`
|
|
121
|
-
for production code that requires robust error handling.
|
|
122
145
|
"""
|
|
123
146
|
pathFilenameFoldsTotal = Path(pathFilename)
|
|
124
147
|
pathFilenameFoldsTotal.parent.mkdir(parents=True, exist_ok=True)
|
|
125
148
|
pathFilenameFoldsTotal.write_text(str(foldsTotal))
|
|
126
149
|
|
|
127
150
|
def saveFoldsTotal(pathFilename: PathLike[str] | PurePath, foldsTotal: int) -> None:
|
|
128
|
-
"""
|
|
129
|
-
|
|
151
|
+
"""Save `foldsTotal` value to disk with multiple fallback mechanisms.
|
|
152
|
+
|
|
153
|
+
(AI generated docstring)
|
|
130
154
|
|
|
131
155
|
This function attempts to save the computed `foldsTotal` value to the specified location, with backup strategies in
|
|
132
156
|
case the primary save attempt fails. The robustness is critical since these computations may take days to complete.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
157
|
+
|
|
158
|
+
Parameters
|
|
159
|
+
----------
|
|
160
|
+
pathFilename : PathLike[str] | PurePath
|
|
161
|
+
Target save location for the `foldsTotal` value.
|
|
162
|
+
foldsTotal : int
|
|
163
|
+
The computed value to save.
|
|
164
|
+
|
|
165
|
+
Notes
|
|
166
|
+
-----
|
|
167
|
+
If the primary save fails, the function will attempt alternative save methods.
|
|
168
|
+
Print the value prominently to `stdout`.
|
|
169
|
+
Create a fallback file in the current working directory.
|
|
170
|
+
As a last resort, simply print the value.
|
|
171
|
+
|
|
172
|
+
The fallback filename includes a unique identifier based on the value itself to prevent conflicts.
|
|
173
|
+
|
|
143
174
|
"""
|
|
144
175
|
try:
|
|
145
176
|
_saveFoldsTotal(pathFilename, foldsTotal)
|
|
146
|
-
except Exception as ERRORmessage:
|
|
177
|
+
except Exception as ERRORmessage: # noqa: BLE001
|
|
147
178
|
try:
|
|
148
|
-
print(f"\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n\n{foldsTotal = }\n\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n")
|
|
149
|
-
print(ERRORmessage)
|
|
150
|
-
print(f"\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n\n{foldsTotal = }\n\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n")
|
|
179
|
+
print(f"\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n\n{foldsTotal = }\n\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n") # noqa: T201
|
|
180
|
+
print(ERRORmessage) # noqa: T201
|
|
181
|
+
print(f"\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n\n{foldsTotal = }\n\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n") # noqa: T201
|
|
151
182
|
randomnessPlanB = (int(str(foldsTotal).strip()[-1]) + 1) * ['YO_']
|
|
152
183
|
filenameInfixUnique = ''.join(randomnessPlanB)
|
|
153
|
-
pathFilenamePlanB = os.path.join(os.getcwd(), 'foldsTotal' + filenameInfixUnique + '.txt')
|
|
154
|
-
writeStreamFallback = open(pathFilenamePlanB, 'w')
|
|
184
|
+
pathFilenamePlanB = os.path.join(os.getcwd(), 'foldsTotal' + filenameInfixUnique + '.txt') # noqa: PTH109, PTH118
|
|
185
|
+
writeStreamFallback = open(pathFilenamePlanB, 'w') # noqa: PTH123, SIM115
|
|
155
186
|
writeStreamFallback.write(str(foldsTotal))
|
|
156
187
|
writeStreamFallback.close()
|
|
157
|
-
print(str(pathFilenamePlanB))
|
|
158
|
-
except Exception:
|
|
159
|
-
print(foldsTotal)
|
|
160
|
-
return None
|
|
188
|
+
print(str(pathFilenamePlanB)) # noqa: T201
|
|
189
|
+
except Exception: # noqa: BLE001
|
|
190
|
+
print(foldsTotal) # noqa: T201
|
|
161
191
|
|
|
162
192
|
def saveFoldsTotalFAILearly(pathFilename: PathLike[str] | PurePath) -> None:
|
|
163
|
-
"""
|
|
164
|
-
Preemptively test file write capabilities before beginning computation.
|
|
193
|
+
"""Preemptively test file write capabilities before beginning computation.
|
|
165
194
|
|
|
166
|
-
|
|
167
|
-
begins. It tests several critical aspects of filesystem functionality to ensure results can be saved:
|
|
195
|
+
(AI generated docstring)
|
|
168
196
|
|
|
197
|
+
This function performs validation checks on the target file location before a potentially long-running computation
|
|
198
|
+
begins. It tests several critical aspects of filesystem functionality to ensure results can be saved.
|
|
199
|
+
|
|
200
|
+
Parameters
|
|
201
|
+
----------
|
|
202
|
+
pathFilename : PathLike[str] | PurePath
|
|
203
|
+
The path and filename where computation results will be saved.
|
|
204
|
+
|
|
205
|
+
Raises
|
|
206
|
+
------
|
|
207
|
+
FileExistsError
|
|
208
|
+
If the target file already exists.
|
|
209
|
+
FileNotFoundError
|
|
210
|
+
If parent directories don't exist or if write tests fail.
|
|
211
|
+
|
|
212
|
+
Notes
|
|
213
|
+
-----
|
|
214
|
+
Checks performed:
|
|
169
215
|
1. Checks if the file already exists to prevent accidental overwrites.
|
|
170
216
|
2. Verifies that parent directories exist.
|
|
171
217
|
3. Tests if the system can write a test value to the file.
|
|
172
218
|
4. Confirms that the written value can be read back correctly.
|
|
173
219
|
|
|
174
|
-
|
|
175
|
-
|
|
220
|
+
This function helps prevent a situation where a computation runs for hours or days only to discover at the end
|
|
221
|
+
that results cannot be saved. The test value used is a large integer that exercises both the writing and
|
|
222
|
+
reading mechanisms thoroughly.
|
|
176
223
|
|
|
177
|
-
Raises:
|
|
178
|
-
FileExistsError: If the target file already exists.
|
|
179
|
-
FileNotFoundError: If parent directories don't exist or if write tests fail.
|
|
180
|
-
Notes:
|
|
181
|
-
This function helps prevent a situation where a computation runs for hours or days only to discover at the end
|
|
182
|
-
that results cannot be saved. The test value used is a large integer that exercises both the writing and
|
|
183
|
-
reading mechanisms thoroughly.
|
|
184
224
|
"""
|
|
185
225
|
if Path(pathFilename).exists():
|
|
186
|
-
|
|
226
|
+
message = f"`{pathFilename = }` exists: a battle of overwriting might cause tears."
|
|
227
|
+
raise FileExistsError(message)
|
|
187
228
|
if not Path(pathFilename).parent.exists():
|
|
188
|
-
|
|
229
|
+
message = f"I received `{pathFilename = }` 0.000139 seconds ago from a function that promised it created the parent directory, but the parent directory does not exist. Fix that now, so your computation doesn't get deleted later. And be compassionate to others."
|
|
230
|
+
raise FileNotFoundError(message)
|
|
189
231
|
foldsTotal = 149302889205120
|
|
190
232
|
_saveFoldsTotal(pathFilename, foldsTotal)
|
|
191
233
|
if not Path(pathFilename).exists():
|
|
192
|
-
|
|
193
|
-
|
|
234
|
+
message = f"I just wrote a test file to `{pathFilename = }`, but it does not exist. Fix that now, so your computation doesn't get deleted later. And continually improve your empathy skills."
|
|
235
|
+
raise FileNotFoundError(message)
|
|
236
|
+
foldsTotalRead = int(Path(pathFilename).read_text(encoding="utf-8"))
|
|
194
237
|
if foldsTotalRead != foldsTotal:
|
|
195
|
-
|
|
238
|
+
message = f"I wrote a test file to `{pathFilename = }` with contents of `{str(foldsTotal) = }`, but I read `{foldsTotalRead = }` from the file. Python says the values are not equal. Fix that now, so your computation doesn't get corrupted later. And be pro-social."
|
|
239
|
+
raise FileNotFoundError(message)
|
|
196
240
|
|
|
197
241
|
def writeStringToHere(this: str, pathFilename: PathLike[str] | PurePath) -> None:
|
|
198
|
-
"""
|
|
199
|
-
|
|
242
|
+
"""Write a string to a file, creating parent directories if needed.
|
|
243
|
+
|
|
244
|
+
(AI generated docstring)
|
|
200
245
|
|
|
201
246
|
This utility function provides a consistent interface for writing string content to files across the package. It
|
|
202
247
|
handles path creation and ensures proper string conversion.
|
|
203
248
|
|
|
204
|
-
Parameters
|
|
205
|
-
|
|
206
|
-
|
|
249
|
+
Parameters
|
|
250
|
+
----------
|
|
251
|
+
this : str
|
|
252
|
+
The string content to write to the file.
|
|
253
|
+
pathFilename : PathLike[str] | PurePath
|
|
254
|
+
The target file path where the string should be written.
|
|
255
|
+
|
|
256
|
+
Notes
|
|
257
|
+
-----
|
|
258
|
+
This function creates all parent directories in the path if they don't exist, making it safe to use with newly
|
|
259
|
+
created directory structures.
|
|
207
260
|
|
|
208
|
-
Notes:
|
|
209
|
-
This function creates all parent directories in the path if they don't exist, making it safe to use with newly
|
|
210
|
-
created directory structures.
|
|
211
261
|
"""
|
|
212
262
|
pathFilename = Path(pathFilename)
|
|
213
263
|
pathFilename.parent.mkdir(parents=True, exist_ok=True)
|
|
214
264
|
pathFilename.write_text(str(this))
|
|
215
|
-
return None
|