mapFolding 0.12.1__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.
Files changed (37) hide show
  1. mapFolding/__init__.py +46 -20
  2. mapFolding/_theSSOT.py +81 -0
  3. mapFolding/_theTypes.py +148 -0
  4. mapFolding/basecamp.py +62 -47
  5. mapFolding/beDRY.py +100 -73
  6. mapFolding/dataBaskets.py +226 -31
  7. mapFolding/filesystemToolkit.py +161 -107
  8. mapFolding/oeis.py +388 -174
  9. mapFolding/reference/flattened.py +1 -1
  10. mapFolding/someAssemblyRequired/RecipeJob.py +146 -20
  11. mapFolding/someAssemblyRequired/__init__.py +60 -38
  12. mapFolding/someAssemblyRequired/_toolIfThis.py +125 -35
  13. mapFolding/someAssemblyRequired/_toolkitContainers.py +125 -44
  14. mapFolding/someAssemblyRequired/getLLVMforNoReason.py +35 -26
  15. mapFolding/someAssemblyRequired/infoBooth.py +37 -2
  16. mapFolding/someAssemblyRequired/makeAllModules.py +785 -0
  17. mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +161 -74
  18. mapFolding/someAssemblyRequired/toolkitNumba.py +218 -36
  19. mapFolding/someAssemblyRequired/transformationTools.py +125 -58
  20. mapfolding-0.12.3.dist-info/METADATA +163 -0
  21. mapfolding-0.12.3.dist-info/RECORD +53 -0
  22. {mapfolding-0.12.1.dist-info → mapfolding-0.12.3.dist-info}/WHEEL +1 -1
  23. tests/__init__.py +28 -44
  24. tests/conftest.py +66 -61
  25. tests/test_computations.py +64 -89
  26. tests/test_filesystem.py +25 -1
  27. tests/test_oeis.py +37 -7
  28. tests/test_other.py +29 -2
  29. tests/test_tasks.py +30 -2
  30. mapFolding/datatypes.py +0 -18
  31. mapFolding/someAssemblyRequired/Z0Z_makeAllModules.py +0 -433
  32. mapFolding/theSSOT.py +0 -34
  33. mapfolding-0.12.1.dist-info/METADATA +0 -184
  34. mapfolding-0.12.1.dist-info/RECORD +0 -53
  35. {mapfolding-0.12.1.dist-info → mapfolding-0.12.3.dist-info}/entry_points.txt +0 -0
  36. {mapfolding-0.12.1.dist-info → mapfolding-0.12.3.dist-info}/licenses/LICENSE +0 -0
  37. {mapfolding-0.12.1.dist-info → mapfolding-0.12.3.dist-info}/top_level.txt +0 -0
@@ -1,26 +1,26 @@
1
1
  """
2
- Filesystem utilities for managing map folding computation results.
3
-
4
- This module provides functions for standardized handling of files related to the mapFolding package, with a focus on
5
- saving, retrieving, and naming computation results. It implements consistent naming conventions and path resolution
6
- strategies to ensure that:
7
-
8
- 1. Computation results are stored in a predictable location.
9
- 2. Filenames follow a consistent pattern based on map dimensions.
10
- 3. Results can be reliably retrieved for future reference.
11
- 4. The system handles file operations safely with appropriate error handling.
12
-
13
- The module serves as the standardized interface between the computational components of the package and the filesystem,
14
- abstracting away the details of file operations and path management. It provides robust fallback mechanisms to preserve
15
- computation results even in the face of filesystem errors, which is critical for long-running computations that may take
16
- days to complete.
17
-
18
- The functions here adhere to a consistent approach to path handling:
19
- - Cross-platform compatibility through the use of `pathlib`.
20
- - Default locations determined intelligently based on the runtime environment.
21
- - Progressive fallback strategies for saving critical computation results.
22
- - Preemptive filesystem validation to detect issues before computation begins.
2
+ Persistent storage infrastructure for map folding computation results.
3
+
4
+ (AI generated docstring)
5
+
6
+ As computational state management orchestrates the complex recursive analysis,
7
+ this module ensures that the valuable results of potentially multi-day computations
8
+ are safely preserved and reliably retrievable. Map folding problems can require
9
+ extensive computational time, making robust result persistence critical for
10
+ practical research and application.
11
+
12
+ The storage system provides standardized filename generation, platform-independent
13
+ path resolution, and multiple fallback strategies to prevent data loss. Special
14
+ attention is given to environments like Google Colab and cross-platform deployment
15
+ scenarios. The storage patterns integrate with the configuration foundation to
16
+ provide consistent behavior across different installation contexts.
17
+
18
+ This persistence layer serves as the crucial bridge between the computational
19
+ framework and the user interface, ensuring that computation results are available
20
+ for the main interface to retrieve, validate, and present to users seeking
21
+ solutions to their map folding challenges.
23
22
  """
23
+
24
24
  from mapFolding import packageSettings
25
25
  from os import PathLike
26
26
  from pathlib import Path, PurePath
@@ -29,48 +29,57 @@ import os
29
29
  import platformdirs
30
30
 
31
31
  def getFilenameFoldsTotal(mapShape: tuple[int, ...]) -> str:
32
- """
33
- Create a standardized filename for a computed `foldsTotal` value.
32
+ """Create a standardized filename for a computed `foldsTotal` value.
33
+
34
+ (AI generated docstring)
34
35
 
35
36
  This function generates a consistent, filesystem-safe filename based on map dimensions. Standardizing filenames
36
37
  ensures that results can be reliably stored and retrieved, avoiding potential filesystem incompatibilities or Python
37
38
  naming restrictions.
38
39
 
39
- Parameters:
40
- mapShape: A sequence of integers representing the dimensions of the map.
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.
41
49
 
42
- Returns:
43
- filenameFoldsTotal: A filename string in format 'pMxN.foldsTotal' where M,N are sorted dimensions.
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.
44
54
 
45
- Notes:
46
- The filename format ensures:
47
- - No spaces in the filename
48
- - Safe filesystem characters
49
- - Unique extension (.foldsTotal)
50
- - Python-safe strings (no starting with numbers, no reserved words)
51
- - The 'p' prefix comes from Lunnon's original code.
52
55
  """
53
56
  return 'p' + 'x'.join(str(dimension) for dimension in sorted(mapShape)) + '.foldsTotal'
54
57
 
55
58
  def getPathFilenameFoldsTotal(mapShape: tuple[int, ...], pathLikeWriteFoldsTotal: PathLike[str] | PurePath | None = None) -> Path:
56
- """
57
- Get a standardized path and filename for the computed `foldsTotal` value.
59
+ """Get a standardized path and filename for the computed `foldsTotal` value.
60
+
61
+ (AI generated docstring)
58
62
 
59
63
  This function resolves paths for storing computation results, handling different input types including directories,
60
64
  absolute paths, or relative paths. It ensures that all parent directories exist in the resulting path.
61
65
 
62
- Parameters:
63
- mapShape: List of dimensions for the map folding problem.
64
- pathLikeWriteFoldsTotal (getPathJobRootDEFAULT): Path, filename, or relative path and filename. If None, uses
65
- default path. If a directory, appends standardized filename.
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
- Returns:
68
- pathFilenameFoldsTotal: Absolute path and filename for storing the `foldsTotal` value.
73
+ Returns
74
+ -------
75
+ pathFilenameFoldsTotal : Path
76
+ Absolute path and filename for storing the `foldsTotal` value.
69
77
 
70
- Notes:
71
- The function creates any necessary directories in the path if they don't exist.
72
- """
78
+ Notes
79
+ -----
80
+ The function creates any necessary directories in the path if they don't exist.
73
81
 
82
+ """
74
83
  if pathLikeWriteFoldsTotal is None:
75
84
  pathFilenameFoldsTotal = getPathRootJobDEFAULT() / getFilenameFoldsTotal(mapShape)
76
85
  else:
@@ -86,125 +95,170 @@ def getPathFilenameFoldsTotal(mapShape: tuple[int, ...], pathLikeWriteFoldsTotal
86
95
  return pathFilenameFoldsTotal
87
96
 
88
97
  def getPathRootJobDEFAULT() -> Path:
89
- """
90
- Get the default root directory for map folding computation jobs.
98
+ """Get the default root directory for map folding computation jobs.
99
+
100
+ (AI generated docstring)
91
101
 
92
102
  This function determines the appropriate default directory for storing computation results based on the current
93
103
  runtime environment. It uses platform-specific directories for normal environments and adapts to special
94
104
  environments like Google Colab.
95
105
 
96
- Returns:
97
- pathJobDEFAULT: Path to the default directory for storing computation results
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.
98
116
 
99
- Notes:
100
- - For standard environments, uses `platformdirs` to find appropriate user data directory.
101
- - For Google Colab, uses a specific path in Google Drive.
102
- - Creates the directory if it doesn't exist.
103
117
  """
104
- pathJobDEFAULT = Path(platformdirs.user_data_dir(appname=packageSettings.packageName, appauthor=False, ensure_exists=True))
118
+ pathJobDEFAULT = Path(platformdirs.user_data_dir(appname=packageSettings.identifierPackage, appauthor=False, ensure_exists=True))
105
119
  if 'google.colab' in sysModules:
106
- pathJobDEFAULT = Path("/content/drive/MyDrive") / packageSettings.packageName
120
+ pathJobDEFAULT = Path("/content/drive/MyDrive") / packageSettings.identifierPackage
107
121
  pathJobDEFAULT.mkdir(parents=True, exist_ok=True)
108
122
  return pathJobDEFAULT
109
123
 
110
124
  def _saveFoldsTotal(pathFilename: PathLike[str] | PurePath, foldsTotal: int) -> None:
111
- """
112
- Standardized function to save a `foldsTotal` value to a file.
125
+ """Save a `foldsTotal` value to a file.
126
+
127
+ (AI generated docstring)
128
+
129
+ This function provides the core file writing functionality used by the public `saveFoldsTotal` function. It handles
130
+ the basic operations of creating parent directories and writing the integer value as text to the specified file
131
+ location.
132
+
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.
113
144
 
114
- Parameters:
115
- pathFilename: Path where the `foldsTotal` value should be saved
116
- foldsTotal: The integer value to save
117
145
  """
118
146
  pathFilenameFoldsTotal = Path(pathFilename)
119
147
  pathFilenameFoldsTotal.parent.mkdir(parents=True, exist_ok=True)
120
148
  pathFilenameFoldsTotal.write_text(str(foldsTotal))
121
149
 
122
150
  def saveFoldsTotal(pathFilename: PathLike[str] | PurePath, foldsTotal: int) -> None:
123
- """
124
- Save `foldsTotal` value to disk with multiple fallback mechanisms.
151
+ """Save `foldsTotal` value to disk with multiple fallback mechanisms.
152
+
153
+ (AI generated docstring)
125
154
 
126
155
  This function attempts to save the computed `foldsTotal` value to the specified location, with backup strategies in
127
156
  case the primary save attempt fails. The robustness is critical since these computations may take days to complete.
128
157
 
129
- Parameters:
130
- pathFilename: Target save location for the `foldsTotal` value
131
- foldsTotal: The computed value to save
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.
132
173
 
133
- Notes:
134
- If the primary save fails, the function will attempt alternative save methods:
135
- 1. Print the value prominently to `stdout`.
136
- 2. Create a fallback file in the current working directory.
137
- 3. As a last resort, simply print the value.
138
174
  """
139
175
  try:
140
176
  _saveFoldsTotal(pathFilename, foldsTotal)
141
- except Exception as ERRORmessage:
177
+ except Exception as ERRORmessage: # noqa: BLE001
142
178
  try:
143
- print(f"\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n\n{foldsTotal = }\n\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n")
144
- print(ERRORmessage)
145
- 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
146
182
  randomnessPlanB = (int(str(foldsTotal).strip()[-1]) + 1) * ['YO_']
147
183
  filenameInfixUnique = ''.join(randomnessPlanB)
148
- pathFilenamePlanB = os.path.join(os.getcwd(), 'foldsTotal' + filenameInfixUnique + '.txt')
149
- 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
150
186
  writeStreamFallback.write(str(foldsTotal))
151
187
  writeStreamFallback.close()
152
- print(str(pathFilenamePlanB))
153
- except Exception:
154
- print(foldsTotal)
155
- return None
188
+ print(str(pathFilenamePlanB)) # noqa: T201
189
+ except Exception: # noqa: BLE001
190
+ print(foldsTotal) # noqa: T201
156
191
 
157
192
  def saveFoldsTotalFAILearly(pathFilename: PathLike[str] | PurePath) -> None:
158
- """
159
- Preemptively test file write capabilities before beginning computation.
193
+ """Preemptively test file write capabilities before beginning computation.
160
194
 
161
- This function performs validation checks on the target file location before a potentially long-running computation
162
- begins. It tests several critical aspects of filesystem functionality to ensure results can be saved:
195
+ (AI generated docstring)
163
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:
164
215
  1. Checks if the file already exists to prevent accidental overwrites.
165
216
  2. Verifies that parent directories exist.
166
217
  3. Tests if the system can write a test value to the file.
167
218
  4. Confirms that the written value can be read back correctly.
168
219
 
169
- Parameters:
170
- pathFilename: The path and filename where computation results will be saved.
171
-
172
- Raises:
173
- FileExistsError: If the target file already exists.
174
- FileNotFoundError: If parent directories don't exist or if write tests fail.
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.
175
223
 
176
- Notes:
177
- This function helps prevent a situation where a computation runs for hours or days only to discover at the end
178
- that results cannot be saved.
179
224
  """
180
225
  if Path(pathFilename).exists():
181
- raise FileExistsError(f"`{pathFilename = }` exists: a battle of overwriting might cause tears.")
226
+ message = f"`{pathFilename = }` exists: a battle of overwriting might cause tears."
227
+ raise FileExistsError(message)
182
228
  if not Path(pathFilename).parent.exists():
183
- raise FileNotFoundError(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.")
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)
184
231
  foldsTotal = 149302889205120
185
232
  _saveFoldsTotal(pathFilename, foldsTotal)
186
233
  if not Path(pathFilename).exists():
187
- raise FileNotFoundError(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.")
188
- foldsTotalRead = int(Path(pathFilename).read_text())
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"))
189
237
  if foldsTotalRead != foldsTotal:
190
- raise FileNotFoundError(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.")
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)
191
240
 
192
241
  def writeStringToHere(this: str, pathFilename: PathLike[str] | PurePath) -> None:
193
- """
194
- Write a string to a file, creating parent directories if needed.
242
+ """Write a string to a file, creating parent directories if needed.
243
+
244
+ (AI generated docstring)
195
245
 
196
246
  This utility function provides a consistent interface for writing string content to files across the package. It
197
247
  handles path creation and ensures proper string conversion.
198
248
 
199
- Parameters:
200
- this: The string content to write to the file.
201
- pathFilename: The target file path where the string should be written.
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.
202
260
 
203
- Notes:
204
- This function creates all parent directories in the path if they don't exist, making it safe to use with newly
205
- created directory structures.
206
261
  """
207
262
  pathFilename = Path(pathFilename)
208
263
  pathFilename.parent.mkdir(parents=True, exist_ok=True)
209
264
  pathFilename.write_text(str(this))
210
- return None