mapFolding 0.16.4__py3-none-any.whl → 0.17.1__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.
- easyRun/NOTcountingFolds.py +28 -11
- easyRun/__init__.py +1 -0
- easyRun/countFolds.py +16 -2
- easyRun/eliminateFolds.py +60 -0
- easyRun/meanders.py +3 -3
- mapFolding/__init__.py +2 -1
- mapFolding/_theTypes.py +0 -1
- mapFolding/algorithms/A086345.py +8 -3
- mapFolding/algorithms/__init__.py +1 -1
- mapFolding/algorithms/constraintPropagation.py +184 -0
- mapFolding/algorithms/elimination.py +131 -0
- mapFolding/algorithms/eliminationCount.py +26 -0
- mapFolding/algorithms/eliminationPinned.py +35 -0
- mapFolding/algorithms/iff.py +206 -0
- mapFolding/algorithms/matrixMeanders.py +59 -18
- mapFolding/algorithms/matrixMeandersNumPyndas.py +841 -0
- mapFolding/algorithms/patternFinder.py +280 -0
- mapFolding/algorithms/pinning2Dn.py +345 -0
- mapFolding/algorithms/pinning2DnAnnex.py +43 -0
- mapFolding/algorithms/symmetricFolds.py +24 -25
- mapFolding/basecamp.py +84 -14
- mapFolding/beDRY.py +14 -1
- mapFolding/dataBaskets.py +86 -71
- mapFolding/reference/irvineJavaPort.py +3 -3
- mapFolding/reference/meandersDumpingGround/matrixMeandersNumPyV1finalForm.py +1 -1
- mapFolding/someAssemblyRequired/A007822/_asynchronousAnnex.py +1 -1
- mapFolding/someAssemblyRequired/A007822/makeA007822AsynchronousModules.py +5 -3
- mapFolding/someAssemblyRequired/A007822/makeA007822Modules.py +22 -6
- mapFolding/someAssemblyRequired/RecipeJob.py +14 -24
- mapFolding/someAssemblyRequired/__init__.py +1 -0
- mapFolding/someAssemblyRequired/_toolkitContainers.py +6 -4
- mapFolding/someAssemblyRequired/infoBooth.py +2 -1
- mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +75 -20
- mapFolding/someAssemblyRequired/makeJobTheorem2codon.py +9 -10
- mapFolding/someAssemblyRequired/makingModules_count.py +20 -22
- mapFolding/someAssemblyRequired/makingModules_doTheNeedful.py +9 -9
- mapFolding/someAssemblyRequired/mapFoldingModules/makeMapFoldingModules.py +6 -5
- mapFolding/someAssemblyRequired/meanders/makeMeandersModules.py +6 -6
- mapFolding/someAssemblyRequired/toolkitMakeModules.py +3 -29
- mapFolding/someAssemblyRequired/toolkitNumba.py +2 -1
- mapFolding/someAssemblyRequired/transformationTools.py +2 -3
- mapFolding/syntheticModules/A007822/algorithm.py +8 -8
- mapFolding/syntheticModules/A007822/asynchronous.py +12 -13
- mapFolding/syntheticModules/A007822/initializeState.py +10 -8
- mapFolding/syntheticModules/A007822/theorem2.py +10 -8
- mapFolding/syntheticModules/A007822/theorem2Numba.py +20 -16
- mapFolding/syntheticModules/A007822/theorem2Trimmed.py +10 -8
- mapFolding/syntheticModules/countParallelNumba.py +5 -2
- mapFolding/syntheticModules/daoOfMapFoldingNumba.py +4 -2
- mapFolding/syntheticModules/initializeState.py +1 -1
- mapFolding/syntheticModules/meanders/bigInt.py +52 -15
- mapFolding/syntheticModules/theorem2.py +1 -1
- mapFolding/syntheticModules/theorem2Numba.py +4 -2
- mapFolding/syntheticModules/theorem2Trimmed.py +1 -1
- mapFolding/tests/conftest.py +1 -1
- mapFolding/tests/test_computations.py +21 -4
- mapFolding/tests/verify.py +323 -0
- {mapfolding-0.16.4.dist-info → mapfolding-0.17.1.dist-info}/METADATA +14 -11
- mapfolding-0.17.1.dist-info/RECORD +112 -0
- easyRun/A000682.py +0 -25
- easyRun/A005316.py +0 -20
- mapFolding/algorithms/matrixMeandersBeDry.py +0 -182
- mapFolding/algorithms/matrixMeandersNumPy.py +0 -333
- mapFolding/algorithms/matrixMeandersPandas.py +0 -334
- mapfolding-0.16.4.dist-info/RECORD +0 -106
- {mapfolding-0.16.4.dist-info → mapfolding-0.17.1.dist-info}/WHEEL +0 -0
- {mapfolding-0.16.4.dist-info → mapfolding-0.17.1.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.16.4.dist-info → mapfolding-0.17.1.dist-info}/licenses/LICENSE +0 -0
- {mapfolding-0.16.4.dist-info → mapfolding-0.17.1.dist-info}/top_level.txt +0 -0
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"""Configuration by dataclass."""
|
|
2
2
|
|
|
3
|
-
from astToolkit import identifierDotAttribute,
|
|
3
|
+
from astToolkit import identifierDotAttribute, parseLogicalPath2astModule
|
|
4
|
+
from astToolkit.containers import IngredientsFunction, IngredientsModule, LedgerOfImports
|
|
4
5
|
from astToolkit.transformationTools import pythonCode2ast_expr
|
|
5
6
|
from hunterMakesPy import autoDecodingRLE
|
|
6
|
-
# TODO '
|
|
7
|
+
# TODO 'The____' identifiers are a vestigial semiotic system. Do I still need to import `asname`? If so, would different
|
|
7
8
|
# identifiers better integrate into the current semiotics?
|
|
8
9
|
from mapFolding import (
|
|
9
10
|
DatatypeElephino as TheDatatypeElephino, DatatypeFoldsTotal as TheDatatypeFoldsTotal,
|
|
10
11
|
DatatypeLeavesTotal as TheDatatypeLeavesTotal, getPathFilenameFoldsTotal, getPathRootJobDEFAULT, packageSettings)
|
|
11
|
-
from mapFolding.dataBaskets import MapFoldingState
|
|
12
|
-
from mapFolding.someAssemblyRequired import DatatypeConfiguration, default
|
|
13
|
-
from mapFolding.someAssemblyRequired._toolkitContainers import ShatteredDataclass
|
|
12
|
+
from mapFolding.dataBaskets import MapFoldingState, SymmetricFoldsState
|
|
13
|
+
from mapFolding.someAssemblyRequired import DatatypeConfiguration, default, ShatteredDataclass
|
|
14
14
|
from mapFolding.someAssemblyRequired.transformationTools import shatter_dataclassesDOTdataclass
|
|
15
15
|
from pathlib import Path, PurePosixPath
|
|
16
16
|
from typing import cast
|
|
@@ -22,18 +22,8 @@ class RecipeJobTheorem2:
|
|
|
22
22
|
"""Configuration recipe for generating map folding computation jobs.
|
|
23
23
|
|
|
24
24
|
This dataclass serves as the central configuration hub for the code transformation
|
|
25
|
-
assembly line that converts generic map folding algorithms into
|
|
26
|
-
specialized
|
|
27
|
-
for source code analysis, target file generation, datatype mapping, and compilation
|
|
28
|
-
optimization settings.
|
|
29
|
-
|
|
30
|
-
The transformation process operates by extracting functions from source modules,
|
|
31
|
-
embedding concrete parameter values, eliminating dead code paths, and generating
|
|
32
|
-
standalone Python modules optimized for specific map dimensions.
|
|
33
|
-
|
|
34
|
-
The recipe maintains both source configuration (where to find the generic algorithm)
|
|
35
|
-
and target configuration (where to write the optimized module), along with the
|
|
36
|
-
computational state that provides concrete values for the transformation process.
|
|
25
|
+
assembly line that converts generic map folding algorithms into optimized,
|
|
26
|
+
specialized modules.
|
|
37
27
|
|
|
38
28
|
Attributes
|
|
39
29
|
----------
|
|
@@ -87,7 +77,7 @@ class RecipeJobTheorem2:
|
|
|
87
77
|
Type alias for leaf count datatype.
|
|
88
78
|
"""
|
|
89
79
|
|
|
90
|
-
state: MapFoldingState
|
|
80
|
+
state: MapFoldingState | SymmetricFoldsState
|
|
91
81
|
"""The map folding computation state containing dimensions and initial values."""
|
|
92
82
|
foldsTotalEstimated: int = 0
|
|
93
83
|
"""Estimated total number of folds for progress tracking."""
|
|
@@ -129,7 +119,7 @@ class RecipeJobTheorem2:
|
|
|
129
119
|
"""Logical path root; probably corresponds to physical filesystem directory."""
|
|
130
120
|
moduleIdentifier: str = dataclasses.field(default=None, init=True) # pyright: ignore[reportAssignmentType]
|
|
131
121
|
"""Target module identifier."""
|
|
132
|
-
|
|
122
|
+
identifierCallable: str = identifierCallableSource
|
|
133
123
|
"""Name of the counting function in generated module."""
|
|
134
124
|
identifierDataclass: str | None = sourceDataclassIdentifier
|
|
135
125
|
"""Target dataclass identifier."""
|
|
@@ -211,12 +201,12 @@ class RecipeJobTheorem2:
|
|
|
211
201
|
"""
|
|
212
202
|
pathFilenameFoldsTotal = PurePosixPath(getPathFilenameFoldsTotal(self.state.mapShape))
|
|
213
203
|
|
|
214
|
-
if self.moduleIdentifier is None: # pyright: ignore[reportUnnecessaryComparison]
|
|
215
|
-
self.moduleIdentifier = pathFilenameFoldsTotal.stem
|
|
216
|
-
|
|
217
204
|
if self.pathFilenameFoldsTotal is None: # pyright: ignore[reportUnnecessaryComparison]
|
|
218
205
|
self.pathFilenameFoldsTotal = pathFilenameFoldsTotal
|
|
219
206
|
|
|
207
|
+
if self.moduleIdentifier is None: # pyright: ignore[reportUnnecessaryComparison]
|
|
208
|
+
self.moduleIdentifier = self.pathFilenameFoldsTotal.stem
|
|
209
|
+
|
|
220
210
|
if self.shatteredDataclass is None and self.logicalPathModuleDataclass and self.identifierDataclass and self.identifierDataclassInstance: # pyright: ignore[reportUnnecessaryComparison]
|
|
221
211
|
self.shatteredDataclass = shatter_dataclassesDOTdataclass(self.logicalPathModuleDataclass, self.identifierDataclass, self.identifierDataclassInstance)
|
|
222
212
|
|
|
@@ -245,11 +235,11 @@ def moveShatteredDataclass_arg2body(identifier: str, job: RecipeJobTheorem2) ->
|
|
|
245
235
|
Ima___Assign, elementConstructor = job.shatteredDataclass.Z0Z_field2AnnAssign[identifier]
|
|
246
236
|
match elementConstructor:
|
|
247
237
|
case 'scalar':
|
|
248
|
-
cast(
|
|
238
|
+
cast(ast.Constant, cast(ast.Call, Ima___Assign.value).args[0]).value = int(eval(f"job.state.{identifier}")) # noqa: S307
|
|
249
239
|
case 'array':
|
|
250
240
|
dataAsStrRLE: str = autoDecodingRLE(eval(f"job.state.{identifier}"), assumeAddSpaces=True) # noqa: S307
|
|
251
241
|
dataAs_ast_expr: ast.expr = pythonCode2ast_expr(dataAsStrRLE)
|
|
252
|
-
cast(
|
|
242
|
+
cast(ast.Call, Ima___Assign.value).args = [dataAs_ast_expr]
|
|
253
243
|
case _:
|
|
254
244
|
pass
|
|
255
245
|
return Ima___Assign
|
|
@@ -74,6 +74,7 @@ calculations through the strategic application of compiler optimization techniqu
|
|
|
74
74
|
|
|
75
75
|
from mapFolding.someAssemblyRequired.infoBooth import (
|
|
76
76
|
default as default,
|
|
77
|
+
Default as Default,
|
|
77
78
|
defaultA007822 as defaultA007822,
|
|
78
79
|
dictionaryEstimatesMapFolding as dictionaryEstimatesMapFolding,
|
|
79
80
|
)
|
|
@@ -25,7 +25,8 @@ to low-level optimized functions while maintaining semantic equivalence and type
|
|
|
25
25
|
the compilation process.
|
|
26
26
|
"""
|
|
27
27
|
|
|
28
|
-
from astToolkit import Be, DOT, identifierDotAttribute,
|
|
28
|
+
from astToolkit import Be, DOT, identifierDotAttribute, Make, NodeTourist, Then
|
|
29
|
+
from astToolkit.containers import LedgerOfImports
|
|
29
30
|
from collections.abc import Callable
|
|
30
31
|
from copy import deepcopy
|
|
31
32
|
from hunterMakesPy import raiseIfNone
|
|
@@ -220,7 +221,7 @@ class DeReConstructField2ast: # slots?
|
|
|
220
221
|
self.ast_keyword_field__field = Make.keyword(self.name, self.astName)
|
|
221
222
|
self.ast_nameDOTname = Make.Attribute(Make.Name(dataclassesDOTdataclassInstanceIdentifier), self.name)
|
|
222
223
|
|
|
223
|
-
self.astAnnotation = cast(
|
|
224
|
+
self.astAnnotation = cast(ast.Name, raiseIfNone(NodeTourist(
|
|
224
225
|
findThis = Be.AnnAssign.targetIs(IfThis.isNameIdentifier(self.name))
|
|
225
226
|
, doThat = Then.extractIt(DOT.annotation)
|
|
226
227
|
).captureLastMatch(dataclassClassDef)))
|
|
@@ -251,8 +252,9 @@ class DeReConstructField2ast: # slots?
|
|
|
251
252
|
self.astAnnAssignConstructor = Make.AnnAssign(self.astName, self.astAnnotation, Make.Call(self.astAnnotation, [Make.Constant(-1)]))
|
|
252
253
|
self.Z0Z_hack = (self.astAnnAssignConstructor, 'scalar')
|
|
253
254
|
elif isinstance(self.astAnnotation, ast.Subscript):
|
|
254
|
-
elementConstructor: str = self.metadata
|
|
255
|
-
|
|
255
|
+
elementConstructor: str = self.metadata.get('elementConstructor', 'generic')
|
|
256
|
+
if elementConstructor != 'generic':
|
|
257
|
+
self.ledger.addImportFrom_asStr(dataclassesDOTdataclassLogicalPathModule, elementConstructor)
|
|
256
258
|
takeTheTuple = deepcopy(self.astAnnotation.slice)
|
|
257
259
|
self.astAnnAssignConstructor = Make.AnnAssign(self.astName, self.astAnnotation, takeTheTuple)
|
|
258
260
|
self.Z0Z_hack = (self.astAnnAssignConstructor, elementConstructor)
|
|
@@ -44,6 +44,7 @@ default = Default(
|
|
|
44
44
|
},
|
|
45
45
|
module = {
|
|
46
46
|
'algorithm': 'daoOfMapFolding',
|
|
47
|
+
'dataBasket': 'dataBaskets',
|
|
47
48
|
'initializeState': 'initializeState',
|
|
48
49
|
},
|
|
49
50
|
variable = {
|
|
@@ -62,5 +63,5 @@ defaultA007822['logicalPath']['assembly'] = 'someAssemblyRequired.A007822'
|
|
|
62
63
|
defaultA007822['logicalPath']['synthetic'] += '.A007822'
|
|
63
64
|
defaultA007822['module']['algorithm'] = 'algorithm'
|
|
64
65
|
defaultA007822['module']['asynchronous'] = 'asynchronous'
|
|
65
|
-
|
|
66
|
+
defaultA007822['variable']['counting'] = 'symmetricFolds'
|
|
66
67
|
defaultA007822['variable']['stateDataclass'] = 'SymmetricFoldsState'
|
|
@@ -8,16 +8,16 @@ internalization to convert function parameters into embedded variables, Numba de
|
|
|
8
8
|
progress integration for long-running calculations, and launcher generation for standalone execution entry points.
|
|
9
9
|
"""
|
|
10
10
|
|
|
11
|
-
from astToolkit import
|
|
12
|
-
|
|
13
|
-
from
|
|
14
|
-
from
|
|
15
|
-
|
|
16
|
-
from mapFolding.dataBaskets import MapFoldingState
|
|
17
|
-
from mapFolding.someAssemblyRequired import DatatypeConfiguration, dictionaryEstimatesMapFolding, IfThis
|
|
11
|
+
from astToolkit import Be, Make, NodeChanger, NodeTourist, parseLogicalPath2astModule, Then
|
|
12
|
+
from astToolkit.containers import astModuleToIngredientsFunction, IngredientsFunction, IngredientsModule
|
|
13
|
+
from hunterMakesPy import autoDecodingRLE, identifierDotAttribute
|
|
14
|
+
from mapFolding import (
|
|
15
|
+
DatatypeLeavesTotal, dictionaryOEIS, getFoldsTotalKnown, getPathFilenameFoldsTotal, packageSettings)
|
|
16
|
+
from mapFolding.dataBaskets import MapFoldingState, SymmetricFoldsState
|
|
17
|
+
from mapFolding.someAssemblyRequired import DatatypeConfiguration, defaultA007822, dictionaryEstimatesMapFolding, IfThis
|
|
18
18
|
from mapFolding.someAssemblyRequired.RecipeJob import customizeDatatypeViaImport, RecipeJobTheorem2
|
|
19
19
|
from mapFolding.someAssemblyRequired.toolkitNumba import decorateCallableWithNumba, parametersNumbaLight, SpicesJobNumba
|
|
20
|
-
from mapFolding.
|
|
20
|
+
from mapFolding.someAssemblyRequired.transformationTools import shatter_dataclassesDOTdataclass
|
|
21
21
|
from pathlib import PurePosixPath
|
|
22
22
|
from typing import cast
|
|
23
23
|
import ast
|
|
@@ -42,7 +42,26 @@ def addLauncher(ingredientsModule: IngredientsModule, ingredientsCount: Ingredie
|
|
|
42
42
|
if __name__ == '__main__':
|
|
43
43
|
import time
|
|
44
44
|
timeStart = time.perf_counter()
|
|
45
|
-
foldsTotal = int({job.
|
|
45
|
+
foldsTotal = int({job.identifierCallable}() * {job.state.leavesTotal})
|
|
46
|
+
print(time.perf_counter() - timeStart)
|
|
47
|
+
print('\\nmap {job.state.mapShape} =', foldsTotal)
|
|
48
|
+
writeStream = open('{job.pathFilenameFoldsTotal.as_posix()}', 'w')
|
|
49
|
+
writeStream.write(str(foldsTotal))
|
|
50
|
+
writeStream.close()
|
|
51
|
+
"""
|
|
52
|
+
ingredientsModule.appendLauncher(ast.parse(linesLaunch))
|
|
53
|
+
NodeChanger(Be.Return, Then.replaceWith(Make.Return(job.shatteredDataclass.countingVariableName))).visit(ingredientsCount.astFunctionDef)
|
|
54
|
+
ingredientsCount.astFunctionDef.returns = job.shatteredDataclass.countingVariableAnnotation
|
|
55
|
+
|
|
56
|
+
return ingredientsModule, ingredientsCount
|
|
57
|
+
|
|
58
|
+
def addLauncherA007822(ingredientsModule: IngredientsModule, ingredientsCount: IngredientsFunction, job: RecipeJobTheorem2) -> tuple[IngredientsModule, IngredientsFunction]:
|
|
59
|
+
"""Add a standalone launcher section to a computation module."""
|
|
60
|
+
linesLaunch: str = f"""
|
|
61
|
+
if __name__ == '__main__':
|
|
62
|
+
import time
|
|
63
|
+
timeStart = time.perf_counter()
|
|
64
|
+
foldsTotal = int({job.identifierCallable}())
|
|
46
65
|
print(time.perf_counter() - timeStart)
|
|
47
66
|
print('\\nmap {job.state.mapShape} =', foldsTotal)
|
|
48
67
|
writeStream = open('{job.pathFilenameFoldsTotal.as_posix()}', 'w')
|
|
@@ -79,7 +98,7 @@ def addLauncherNumbaProgress(ingredientsModule: IngredientsModule, ingredientsFu
|
|
|
79
98
|
linesLaunch: str = f"""
|
|
80
99
|
if __name__ == '__main__':
|
|
81
100
|
with ProgressBar(total={job.foldsTotalEstimated//job.state.leavesTotal}, update_interval=2) as statusUpdate:
|
|
82
|
-
{job.
|
|
101
|
+
{job.identifierCallable}(statusUpdate)
|
|
83
102
|
foldsTotal = statusUpdate.n * {job.state.leavesTotal}
|
|
84
103
|
print('\\nmap {job.state.mapShape} =', foldsTotal)
|
|
85
104
|
writeStream = open('{job.pathFilenameFoldsTotal.as_posix()}', 'w')
|
|
@@ -153,19 +172,19 @@ def move_arg2FunctionDefDOTbodyAndAssignInitialValues(ingredientsFunction: Ingre
|
|
|
153
172
|
ImaAnnAssign, elementConstructor = job.shatteredDataclass.Z0Z_field2AnnAssign[ast_arg.arg]
|
|
154
173
|
match elementConstructor:
|
|
155
174
|
case 'scalar':
|
|
156
|
-
cast(
|
|
175
|
+
cast(ast.Constant, cast(ast.Call, ImaAnnAssign.value).args[0]).value = int(eval(f"job.state.{ast_arg.arg}")) # noqa: S307
|
|
157
176
|
case 'array':
|
|
158
177
|
dataAsStrRLE: str = autoDecodingRLE(eval(f"job.state.{ast_arg.arg}"), assumeAddSpaces=True) # noqa: S307
|
|
159
|
-
dataAs_astExpr: ast.expr = cast(
|
|
160
|
-
cast(
|
|
178
|
+
dataAs_astExpr: ast.expr = cast(ast.Expr, ast.parse(dataAsStrRLE).body[0]).value
|
|
179
|
+
cast(ast.Call, ImaAnnAssign.value).args = [dataAs_astExpr]
|
|
161
180
|
case _:
|
|
162
181
|
list_exprDOTannotation: list[ast.expr] = []
|
|
163
182
|
list_exprDOTvalue: list[ast.expr] = []
|
|
164
183
|
for dimension in job.state.mapShape:
|
|
165
184
|
list_exprDOTannotation.append(Make.Name(elementConstructor))
|
|
166
185
|
list_exprDOTvalue.append(Make.Call(Make.Name(elementConstructor), [Make.Constant(dimension)]))
|
|
167
|
-
cast(
|
|
168
|
-
cast(
|
|
186
|
+
cast(ast.Tuple, cast(ast.Subscript, cast(ast.AnnAssign, ImaAnnAssign).annotation).slice).elts = list_exprDOTannotation
|
|
187
|
+
cast(ast.Tuple, ImaAnnAssign.value).elts = list_exprDOTvalue
|
|
169
188
|
|
|
170
189
|
ingredientsFunction.astFunctionDef.body.insert(0, ImaAnnAssign)
|
|
171
190
|
|
|
@@ -204,7 +223,8 @@ def makeJobNumba(job: RecipeJobTheorem2, spices: SpicesJobNumba) -> None:
|
|
|
204
223
|
Optimization settings including Numba parameters and progress options.
|
|
205
224
|
|
|
206
225
|
"""
|
|
207
|
-
ingredientsCount: IngredientsFunction = IngredientsFunction(raiseIfNone(extractFunctionDef(job.source_astModule, job.
|
|
226
|
+
# ingredientsCount: IngredientsFunction = IngredientsFunction(raiseIfNone(extractFunctionDef(job.source_astModule, job.identifierCallableSource))) # noqa: ERA001
|
|
227
|
+
ingredientsCount: IngredientsFunction = astModuleToIngredientsFunction(job.source_astModule, job.identifierCallableSource)
|
|
208
228
|
|
|
209
229
|
for identifier in job.shatteredDataclass.listIdentifiersStaticScalars:
|
|
210
230
|
NodeChanger(IfThis.isNameIdentifier(identifier)
|
|
@@ -219,7 +239,8 @@ def makeJobNumba(job: RecipeJobTheorem2, spices: SpicesJobNumba) -> None:
|
|
|
219
239
|
ingredientsModule, ingredientsCount = addLauncherNumbaProgress(ingredientsModule, ingredientsCount, job, spices)
|
|
220
240
|
spices.parametersNumba['nogil'] = True
|
|
221
241
|
else:
|
|
222
|
-
ingredientsModule, ingredientsCount = addLauncher(ingredientsModule, ingredientsCount, job)
|
|
242
|
+
ingredientsModule, ingredientsCount = addLauncher(ingredientsModule, ingredientsCount, job) # noqa: ERA001
|
|
243
|
+
# ingredientsModule, ingredientsCount = addLauncherA007822(ingredientsModule, ingredientsCount, job)
|
|
223
244
|
|
|
224
245
|
ingredientsCount = move_arg2FunctionDefDOTbodyAndAssignInitialValues(ingredientsCount, job)
|
|
225
246
|
|
|
@@ -230,7 +251,7 @@ def makeJobNumba(job: RecipeJobTheorem2, spices: SpicesJobNumba) -> None:
|
|
|
230
251
|
ingredientsCount.astFunctionDef.decorator_list = [] # TODO low-priority, handle this more elegantly
|
|
231
252
|
ingredientsCount = decorateCallableWithNumba(ingredientsCount, spices.parametersNumba)
|
|
232
253
|
ingredientsModule.appendIngredientsFunction(ingredientsCount)
|
|
233
|
-
write_astModule(
|
|
254
|
+
ingredientsModule.write_astModule(job.pathFilenameModule, identifierPackage=job.packageIdentifier or '')
|
|
234
255
|
|
|
235
256
|
"""
|
|
236
257
|
Overview
|
|
@@ -245,6 +266,7 @@ def makeJobNumba(job: RecipeJobTheorem2, spices: SpicesJobNumba) -> None:
|
|
|
245
266
|
|
|
246
267
|
def fromMapShape(mapShape: tuple[DatatypeLeavesTotal, ...]) -> None:
|
|
247
268
|
"""Generate and write an optimized Numba-compiled map folding module for a specific map shape."""
|
|
269
|
+
from mapFolding.syntheticModules.initializeState import transitionOnGroupsOfFolds # noqa: PLC0415
|
|
248
270
|
state: MapFoldingState = transitionOnGroupsOfFolds(MapFoldingState(mapShape))
|
|
249
271
|
foldsTotalEstimated: int = getFoldsTotalKnown(state.mapShape) or dictionaryEstimatesMapFolding.get(state.mapShape, 0)
|
|
250
272
|
pathModule = PurePosixPath(packageSettings.pathPackage, 'jobs')
|
|
@@ -253,6 +275,39 @@ def fromMapShape(mapShape: tuple[DatatypeLeavesTotal, ...]) -> None:
|
|
|
253
275
|
spices = SpicesJobNumba(useNumbaProgressBar=True, parametersNumba=parametersNumbaLight)
|
|
254
276
|
makeJobNumba(aJob, spices)
|
|
255
277
|
|
|
278
|
+
def A007822(n: int) -> None:
|
|
279
|
+
"""Generate and write an optimized Numba-compiled map folding module for a specific map shape."""
|
|
280
|
+
from mapFolding.syntheticModules.A007822.initializeState import transitionOnGroupsOfFolds # noqa: PLC0415
|
|
281
|
+
state = transitionOnGroupsOfFolds(SymmetricFoldsState((1, 2 * n)))
|
|
282
|
+
foldsTotalEstimated: int = dictionaryOEIS['A007822']['valuesKnown'].get(n, 0)
|
|
283
|
+
shatteredDataclass = shatter_dataclassesDOTdataclass(f"{packageSettings.identifierPackage}.{defaultA007822['module']['dataBasket']}"
|
|
284
|
+
, defaultA007822['variable']['stateDataclass'], defaultA007822['variable']['stateInstance'])
|
|
285
|
+
source_astModule: ast.Module = parseLogicalPath2astModule(f'{packageSettings.identifierPackage}.{defaultA007822['logicalPath']['synthetic']}.theorem2Numba')
|
|
286
|
+
identifierCallableSource: str = defaultA007822['function']['counting']
|
|
287
|
+
sourceLogicalPathModuleDataclass: identifierDotAttribute = f'{packageSettings.identifierPackage}.dataBaskets'
|
|
288
|
+
sourceDataclassIdentifier: str = defaultA007822['variable']['stateDataclass']
|
|
289
|
+
sourceDataclassInstance: str = defaultA007822['variable']['stateInstance']
|
|
290
|
+
sourcePathPackage: PurePosixPath | None = PurePosixPath(packageSettings.pathPackage)
|
|
291
|
+
sourcePackageIdentifier: str | None = packageSettings.identifierPackage
|
|
292
|
+
pathPackage: PurePosixPath | None = None
|
|
293
|
+
pathModule = PurePosixPath(packageSettings.pathPackage, 'jobs')
|
|
294
|
+
fileExtension: str = packageSettings.fileExtension
|
|
295
|
+
pathFilenameFoldsTotal = pathModule / ('A007822_' + str(n))
|
|
296
|
+
packageIdentifier: str | None = None
|
|
297
|
+
logicalPathRoot: identifierDotAttribute | None = None
|
|
298
|
+
moduleIdentifier: str = pathFilenameFoldsTotal.stem
|
|
299
|
+
identifierCallable: str = identifierCallableSource
|
|
300
|
+
identifierDataclass: str | None = sourceDataclassIdentifier
|
|
301
|
+
identifierDataclassInstance: str | None = sourceDataclassInstance
|
|
302
|
+
logicalPathModuleDataclass: identifierDotAttribute | None = sourceLogicalPathModuleDataclass
|
|
303
|
+
aJob = RecipeJobTheorem2(state, foldsTotalEstimated, shatteredDataclass, source_astModule, identifierCallableSource, sourceLogicalPathModuleDataclass
|
|
304
|
+
, sourceDataclassIdentifier, sourceDataclassInstance, sourcePathPackage, sourcePackageIdentifier, pathPackage, pathModule, fileExtension
|
|
305
|
+
, pathFilenameFoldsTotal, packageIdentifier, logicalPathRoot, moduleIdentifier, identifierCallable, identifierDataclass, identifierDataclassInstance
|
|
306
|
+
, logicalPathModuleDataclass)
|
|
307
|
+
spices = SpicesJobNumba(useNumbaProgressBar=False, parametersNumba=parametersNumbaLight)
|
|
308
|
+
makeJobNumba(aJob, spices)
|
|
309
|
+
|
|
256
310
|
if __name__ == '__main__':
|
|
257
|
-
mapShape: tuple[DatatypeLeavesTotal, ...] = (
|
|
258
|
-
fromMapShape(mapShape)
|
|
311
|
+
mapShape: tuple[DatatypeLeavesTotal, ...] = (2,21) # noqa: ERA001
|
|
312
|
+
fromMapShape(mapShape) # noqa: ERA001
|
|
313
|
+
# A007822(8)
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
https://docs.exaloop.io/start/install/
|
|
4
4
|
"""
|
|
5
|
-
|
|
6
5
|
from astToolkit import (
|
|
7
|
-
Be, extractFunctionDef, Grab, identifierDotAttribute,
|
|
8
|
-
|
|
6
|
+
Be, extractFunctionDef, Grab, identifierDotAttribute, Make, NodeChanger, parseLogicalPath2astModule, Then)
|
|
7
|
+
from astToolkit.containers import IngredientsFunction, IngredientsModule
|
|
9
8
|
from astToolkit.transformationTools import removeUnusedParameters, write_astModule
|
|
10
9
|
from hunterMakesPy import raiseIfNone
|
|
11
10
|
from mapFolding import DatatypeLeavesTotal, getPathFilenameFoldsTotal, packageSettings
|
|
@@ -106,8 +105,8 @@ def _variableCompatibility(ingredientsFunction: IngredientsFunction, job: Recipe
|
|
|
106
105
|
, Be.Subscript.sliceIs(Be.Tuple))
|
|
107
106
|
, doThat=lambda node: Grab.sliceAttribute(Grab.eltsAttribute(
|
|
108
107
|
Then.replaceWith([
|
|
109
|
-
Make.Call(Make.Name('int'), listParameters=[cast(
|
|
110
|
-
for index in range(len(cast(
|
|
108
|
+
Make.Call(Make.Name('int'), listParameters=[cast(ast.Tuple, node.slice).elts[index]])
|
|
109
|
+
for index in range(len(cast(ast.Tuple, node.slice).elts))])))(node)
|
|
111
110
|
).visit(ingredientsFunction.astFunctionDef)
|
|
112
111
|
|
|
113
112
|
return ingredientsFunction
|
|
@@ -124,7 +123,7 @@ def makeJob(job: RecipeJobTheorem2) -> None:
|
|
|
124
123
|
Configuration recipe containing source locations, target paths, raw materials, and state.
|
|
125
124
|
|
|
126
125
|
"""
|
|
127
|
-
ingredientsCount: IngredientsFunction = IngredientsFunction(raiseIfNone(extractFunctionDef(job.source_astModule, job.
|
|
126
|
+
ingredientsCount: IngredientsFunction = IngredientsFunction(raiseIfNone(extractFunctionDef(job.source_astModule, job.identifierCallable)))
|
|
128
127
|
ingredientsCount.astFunctionDef.decorator_list = []
|
|
129
128
|
|
|
130
129
|
# Replace identifiers-with-static-values with their values.
|
|
@@ -134,7 +133,7 @@ def makeJob(job: RecipeJobTheorem2) -> None:
|
|
|
134
133
|
).visit(ingredientsCount.astFunctionDef)
|
|
135
134
|
|
|
136
135
|
ingredientsCount.imports.update(job.shatteredDataclass.imports)
|
|
137
|
-
ingredientsCount
|
|
136
|
+
ingredientsCount.removeUnusedParameters()
|
|
138
137
|
NodeChanger(Be.arg, lambda removeIt: ingredientsCount.astFunctionDef.body.insert(0, moveShatteredDataclass_arg2body(removeIt.arg, job))).visit(ingredientsCount.astFunctionDef)
|
|
139
138
|
|
|
140
139
|
ingredientsCount = _addWriteFoldsTotal(ingredientsCount, job)
|
|
@@ -142,7 +141,7 @@ def makeJob(job: RecipeJobTheorem2) -> None:
|
|
|
142
141
|
|
|
143
142
|
ingredientsModule = IngredientsModule(launcher=Make.Module([
|
|
144
143
|
Make.If(Make.Compare(Make.Name('__name__'), [Make.Eq()], [Make.Constant('__main__')])
|
|
145
|
-
, body=[Make.Expr(Make.Call(Make.Name(job.
|
|
144
|
+
, body=[Make.Expr(Make.Call(Make.Name(job.identifierCallable)))])]))
|
|
146
145
|
|
|
147
146
|
ingredientsCount, ingredientsModule = customizeDatatypeViaImport(ingredientsCount, ingredientsModule, listDatatypeConfigurations)
|
|
148
147
|
|
|
@@ -159,13 +158,13 @@ def makeJob(job: RecipeJobTheorem2) -> None:
|
|
|
159
158
|
'-']
|
|
160
159
|
streamText = subprocess.Popen(buildCommand, stdin=subprocess.PIPE, text=True)
|
|
161
160
|
if streamText.stdin is not None:
|
|
162
|
-
write_astModule(ingredientsModule, pathFilename=cast(
|
|
161
|
+
write_astModule(ingredientsModule, pathFilename=cast(TextIOBase, streamText.stdin), packageName=job.packageIdentifier)
|
|
163
162
|
streamText.stdin.close()
|
|
164
163
|
streamText.wait()
|
|
165
164
|
subprocess.run(['/usr/bin/strip', str(job.pathFilenameModule.with_suffix(''))], check=False)
|
|
166
165
|
sys.stdout.write(f"sudo systemd-run --unit={job.moduleIdentifier} --nice=-10 --property=CPUAffinity=0 {job.pathFilenameModule.with_suffix('')}\n")
|
|
167
166
|
else:
|
|
168
|
-
write_astModule(
|
|
167
|
+
ingredientsModule.write_astModule(job.pathFilenameModule, identifierPackage=job.packageIdentifier or '')
|
|
169
168
|
sys.stdout.write(f"python {Path(job.pathFilenameModule)}\n")
|
|
170
169
|
|
|
171
170
|
def fromMapShape(mapShape: tuple[DatatypeLeavesTotal, ...]) -> None:
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
These transformation functions will work on at least two different algorithms. If a transformation function only works on a
|
|
4
4
|
specific type of algorithm, it will be in a subdirectory.
|
|
5
5
|
"""
|
|
6
|
-
from astToolkit import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
from astToolkit.transformationTools import inlineFunctionDef
|
|
6
|
+
from astToolkit import Be, DOT, Grab, identifierDotAttribute, Make, NodeChanger, NodeTourist, Then
|
|
7
|
+
from astToolkit.containers import (
|
|
8
|
+
astModuleToIngredientsFunction, IngredientsFunction, IngredientsModule, LedgerOfImports)
|
|
9
|
+
from astToolkit.transformationTools import inlineFunctionDef
|
|
10
10
|
from hunterMakesPy import raiseIfNone
|
|
11
11
|
from mapFolding import packageSettings
|
|
12
|
-
from mapFolding.someAssemblyRequired import default, IfThis, ShatteredDataclass
|
|
12
|
+
from mapFolding.someAssemblyRequired import default, Default, IfThis, ShatteredDataclass
|
|
13
13
|
from mapFolding.someAssemblyRequired.toolkitMakeModules import findDataclass, getLogicalPath, getPathFilename
|
|
14
14
|
from mapFolding.someAssemblyRequired.toolkitNumba import decorateCallableWithNumba, parametersNumbaLight
|
|
15
15
|
from mapFolding.someAssemblyRequired.transformationTools import (
|
|
@@ -48,7 +48,7 @@ def makeMapFoldingNumba(astModule: ast.Module, identifierModule: str, identifier
|
|
|
48
48
|
|
|
49
49
|
ingredientsFunction.imports.update(shatteredDataclass.imports)
|
|
50
50
|
ingredientsFunction: IngredientsFunction = removeDataclassFromFunction(ingredientsFunction, shatteredDataclass)
|
|
51
|
-
ingredientsFunction
|
|
51
|
+
ingredientsFunction.removeUnusedParameters()
|
|
52
52
|
ingredientsFunction = decorateCallableWithNumba(ingredientsFunction, parametersNumbaLight)
|
|
53
53
|
|
|
54
54
|
ingredientsModule = IngredientsModule(ingredientsFunction)
|
|
@@ -59,7 +59,7 @@ def makeMapFoldingNumba(astModule: ast.Module, identifierModule: str, identifier
|
|
|
59
59
|
ingredientsFunctionDispatcher.imports.update(shatteredDataclass.imports)
|
|
60
60
|
targetCallableIdentifier = ingredientsFunction.astFunctionDef.name
|
|
61
61
|
ingredientsFunctionDispatcher = unpackDataclassCallFunctionRepackDataclass(ingredientsFunctionDispatcher, targetCallableIdentifier, shatteredDataclass)
|
|
62
|
-
astTuple: ast.Tuple = cast(
|
|
62
|
+
astTuple: ast.Tuple = cast(ast.Tuple, raiseIfNone(NodeTourist(Be.Return.valueIs(Be.Tuple)
|
|
63
63
|
, doThat=Then.extractIt(DOT.value)).captureLastMatch(ingredientsFunction.astFunctionDef)))
|
|
64
64
|
astTuple.ctx = Make.Store()
|
|
65
65
|
|
|
@@ -74,11 +74,11 @@ def makeMapFoldingNumba(astModule: ast.Module, identifierModule: str, identifier
|
|
|
74
74
|
|
|
75
75
|
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix, identifierModule)
|
|
76
76
|
|
|
77
|
-
write_astModule(
|
|
77
|
+
ingredientsModule.write_astModule(pathFilename, identifierPackage=packageSettings.identifierPackage)
|
|
78
78
|
|
|
79
79
|
return pathFilename
|
|
80
80
|
|
|
81
|
-
def makeTheorem2(astModule: ast.Module, identifierModule: str, identifierCallable: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
|
|
81
|
+
def makeTheorem2(astModule: ast.Module, identifierModule: str, identifierCallable: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None, identifiers: Default | None = None) -> PurePath:
|
|
82
82
|
"""Generate module by applying optimization predicted by Theorem 2.
|
|
83
83
|
|
|
84
84
|
Parameters
|
|
@@ -99,19 +99,17 @@ def makeTheorem2(astModule: ast.Module, identifierModule: str, identifierCallabl
|
|
|
99
99
|
pathFilename : PurePath
|
|
100
100
|
Filesystem path where the theorem-optimized module was written.
|
|
101
101
|
"""
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
dictionaryIdentifiers = identifiers or default
|
|
103
|
+
identifierCallableInitializeDataclass = dictionaryIdentifiers['function']['initializeState']
|
|
104
|
+
identifierModuleInitializeDataclass = dictionaryIdentifiers['module']['initializeState']
|
|
104
105
|
|
|
105
|
-
|
|
106
|
-
identifierModuleInitializeDataclass = identifierModuleInitializeDataclassHARDCODED
|
|
107
|
-
|
|
108
|
-
sourceCallableIdentifier = default['function']['counting']
|
|
106
|
+
sourceCallableIdentifier = dictionaryIdentifiers['function']['counting']
|
|
109
107
|
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
110
108
|
ingredientsFunction.astFunctionDef.name = identifierCallable or sourceCallableIdentifier
|
|
111
109
|
|
|
112
110
|
dataclassInstanceIdentifier: str = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
113
111
|
|
|
114
|
-
theCountingIdentifier: str =
|
|
112
|
+
theCountingIdentifier: str = dictionaryIdentifiers['variable']['counting']
|
|
115
113
|
doubleTheCount: ast.AugAssign = Make.AugAssign(Make.Attribute(Make.Name(dataclassInstanceIdentifier), theCountingIdentifier), Make.Mult(), Make.Constant(2))
|
|
116
114
|
|
|
117
115
|
NodeChanger(
|
|
@@ -160,7 +158,7 @@ def makeTheorem2(astModule: ast.Module, identifierModule: str, identifierCallabl
|
|
|
160
158
|
|
|
161
159
|
# Update any calls to the original function name with the new target function name
|
|
162
160
|
NodeChanger(
|
|
163
|
-
findThis = Be.Call.funcIs(Be.Name.idIs(IfThis.isIdentifier(
|
|
161
|
+
findThis = Be.Call.funcIs(Be.Name.idIs(IfThis.isIdentifier(dictionaryIdentifiers['function']['counting'])))
|
|
164
162
|
, doThat = Grab.funcAttribute(Grab.idAttribute(Then.replaceWith(targetCallableIdentifier)))
|
|
165
163
|
).visit(ingredientsFunctionDispatcher.astFunctionDef)
|
|
166
164
|
|
|
@@ -176,7 +174,7 @@ def makeTheorem2(astModule: ast.Module, identifierModule: str, identifierCallabl
|
|
|
176
174
|
|
|
177
175
|
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix, identifierModule)
|
|
178
176
|
|
|
179
|
-
write_astModule(
|
|
177
|
+
ingredientsModule.write_astModule(pathFilename, identifierPackage=packageSettings.identifierPackage)
|
|
180
178
|
|
|
181
179
|
return pathFilename
|
|
182
180
|
|
|
@@ -212,7 +210,7 @@ def numbaOnTheorem2(astModule: ast.Module, identifierModule: str, identifierCall
|
|
|
212
210
|
|
|
213
211
|
ingredientsFunction.imports.update(shatteredDataclass.imports)
|
|
214
212
|
ingredientsFunction: IngredientsFunction = removeDataclassFromFunction(ingredientsFunction, shatteredDataclass)
|
|
215
|
-
ingredientsFunction
|
|
213
|
+
ingredientsFunction.removeUnusedParameters()
|
|
216
214
|
ingredientsFunction = decorateCallableWithNumba(ingredientsFunction, parametersNumbaLight)
|
|
217
215
|
|
|
218
216
|
ingredientsModule = IngredientsModule(ingredientsFunction)
|
|
@@ -223,7 +221,7 @@ def numbaOnTheorem2(astModule: ast.Module, identifierModule: str, identifierCall
|
|
|
223
221
|
ingredientsFunctionDispatcher.imports.update(shatteredDataclass.imports)
|
|
224
222
|
targetCallableIdentifier = ingredientsFunction.astFunctionDef.name
|
|
225
223
|
ingredientsFunctionDispatcher = unpackDataclassCallFunctionRepackDataclass(ingredientsFunctionDispatcher, targetCallableIdentifier, shatteredDataclass)
|
|
226
|
-
astTuple: ast.Tuple = cast(
|
|
224
|
+
astTuple: ast.Tuple = cast(ast.Tuple, raiseIfNone(NodeTourist(Be.Return.valueIs(Be.Tuple)
|
|
227
225
|
, doThat=Then.extractIt(DOT.value)).captureLastMatch(ingredientsFunction.astFunctionDef)))
|
|
228
226
|
astTuple.ctx = Make.Store()
|
|
229
227
|
|
|
@@ -238,7 +236,7 @@ def numbaOnTheorem2(astModule: ast.Module, identifierModule: str, identifierCall
|
|
|
238
236
|
|
|
239
237
|
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix, identifierModule)
|
|
240
238
|
|
|
241
|
-
write_astModule(
|
|
239
|
+
ingredientsModule.write_astModule(pathFilename, identifierPackage=packageSettings.identifierPackage)
|
|
242
240
|
|
|
243
241
|
return pathFilename
|
|
244
242
|
|
|
@@ -292,7 +290,7 @@ def trimTheorem2(astModule: ast.Module, identifierModule: str, identifierCallabl
|
|
|
292
290
|
|
|
293
291
|
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix, identifierModule)
|
|
294
292
|
|
|
295
|
-
write_astModule(
|
|
293
|
+
ingredientsModule.write_astModule(pathFilename, identifierPackage=packageSettings.identifierPackage)
|
|
296
294
|
|
|
297
295
|
return pathFilename
|
|
298
296
|
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"""Make functions that are complementary to the `count` function and are often called by `doTheNeedful`."""
|
|
2
|
-
from astToolkit import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
from astToolkit.transformationTools import inlineFunctionDef, write_astModule
|
|
2
|
+
from astToolkit import Be, DOT, Grab, identifierDotAttribute, NodeChanger, NodeTourist, Then
|
|
3
|
+
from astToolkit.containers import IngredientsFunction, IngredientsModule, LedgerOfImports
|
|
4
|
+
from astToolkit.transformationTools import inlineFunctionDef
|
|
6
5
|
from hunterMakesPy import raiseIfNone
|
|
7
6
|
from mapFolding import packageSettings
|
|
8
|
-
from mapFolding.someAssemblyRequired import default, IfThis
|
|
7
|
+
from mapFolding.someAssemblyRequired import default, Default, IfThis
|
|
9
8
|
from mapFolding.someAssemblyRequired.toolkitMakeModules import getPathFilename
|
|
10
9
|
from pathlib import PurePath
|
|
11
10
|
import ast
|
|
12
11
|
|
|
13
|
-
def makeInitializeState(astModule: ast.Module, moduleIdentifier: str, callableIdentifier: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath: # noqa: ARG001
|
|
12
|
+
def makeInitializeState(astModule: ast.Module, moduleIdentifier: str, callableIdentifier: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None, identifiers: Default | None = None) -> PurePath: # noqa: ARG001
|
|
14
13
|
"""Generate initialization module for counting variable setup.
|
|
15
14
|
|
|
16
15
|
(AI generated docstring)
|
|
@@ -42,18 +41,19 @@ def makeInitializeState(astModule: ast.Module, moduleIdentifier: str, callableId
|
|
|
42
41
|
Filesystem path where the initialization module was written.
|
|
43
42
|
|
|
44
43
|
"""
|
|
45
|
-
|
|
44
|
+
dictionaryIdentifiers: Default = identifiers or default
|
|
45
|
+
sourceCallableIdentifier: identifierDotAttribute = dictionaryIdentifiers['function']['counting']
|
|
46
46
|
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
47
47
|
ingredientsFunction.astFunctionDef.name = callableIdentifier or sourceCallableIdentifier
|
|
48
48
|
|
|
49
49
|
dataclassInstanceIdentifier: identifierDotAttribute = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
50
|
-
theCountingIdentifier: identifierDotAttribute =
|
|
50
|
+
theCountingIdentifier: identifierDotAttribute = dictionaryIdentifiers['variable']['counting']
|
|
51
51
|
|
|
52
52
|
findThis = IfThis.isWhileAttributeNamespaceIdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
|
|
53
53
|
doThat = Grab.testAttribute(Grab.andDoAllOf([Grab.opsAttribute(Then.replaceWith([ast.Eq()])), Grab.leftAttribute(Grab.attrAttribute(Then.replaceWith(theCountingIdentifier)))]))
|
|
54
54
|
NodeChanger(findThis, doThat).visit(ingredientsFunction.astFunctionDef.body[0])
|
|
55
55
|
|
|
56
56
|
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix, moduleIdentifier)
|
|
57
|
-
|
|
57
|
+
IngredientsModule(ingredientsFunction).write_astModule(pathFilename, identifierPackage=packageSettings.identifierPackage)
|
|
58
58
|
|
|
59
59
|
return pathFilename
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"""makeMapFoldingModules."""
|
|
2
2
|
from astToolkit import (
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Be, DOT, extractClassDef, Grab, hasDOTbody, identifierDotAttribute, Make, NodeChanger, NodeTourist,
|
|
4
|
+
parseLogicalPath2astModule, parsePathFilename2astModule, Then)
|
|
5
|
+
from astToolkit.containers import (
|
|
6
|
+
astModuleToIngredientsFunction, IngredientsFunction, IngredientsModule, LedgerOfImports)
|
|
6
7
|
from astToolkit.transformationTools import inlineFunctionDef, removeUnusedParameters, write_astModule
|
|
7
8
|
from hunterMakesPy import importLogicalPath2Identifier, raiseIfNone
|
|
8
9
|
from mapFolding import packageSettings
|
|
@@ -126,7 +127,7 @@ def makeDaoOfMapFoldingParallelNumba(astModule: ast.Module, identifierModule: st
|
|
|
126
127
|
|
|
127
128
|
# END add the parallel logic to the count function ------------------------------------------------
|
|
128
129
|
|
|
129
|
-
ingredientsFunction
|
|
130
|
+
ingredientsFunction.removeUnusedParameters()
|
|
130
131
|
|
|
131
132
|
ingredientsFunction = decorateCallableWithNumba(ingredientsFunction, parametersNumbaLight)
|
|
132
133
|
|
|
@@ -186,7 +187,7 @@ def makeDaoOfMapFoldingParallelNumba(astModule: ast.Module, identifierModule: st
|
|
|
186
187
|
|
|
187
188
|
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix, identifierModule)
|
|
188
189
|
|
|
189
|
-
write_astModule(
|
|
190
|
+
ingredientsModule.write_astModule(pathFilename, packageSettings.identifierPackage)
|
|
190
191
|
|
|
191
192
|
return pathFilename
|
|
192
193
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"""makeMeandersModules."""
|
|
2
|
-
from astToolkit import
|
|
3
|
-
|
|
2
|
+
from astToolkit import Be, Grab, identifierDotAttribute, Make, NodeChanger, NodeTourist, Then
|
|
3
|
+
from astToolkit.containers import astModuleToIngredientsFunction
|
|
4
|
+
from astToolkit.transformationTools import write_astModule
|
|
4
5
|
from hunterMakesPy import raiseIfNone
|
|
5
6
|
from mapFolding import packageSettings
|
|
6
7
|
from mapFolding.someAssemblyRequired import default, IfThis
|
|
7
|
-
from mapFolding.someAssemblyRequired.toolkitMakeModules import
|
|
8
|
-
findDataclass, getModule, getPathFilename, write_astModule)
|
|
8
|
+
from mapFolding.someAssemblyRequired.toolkitMakeModules import findDataclass, getModule, getPathFilename
|
|
9
9
|
from pathlib import PurePath
|
|
10
10
|
import ast
|
|
11
11
|
|
|
@@ -51,14 +51,14 @@ def makeCountBigInt(astModule: ast.Module, identifierModule: str, callableIdenti
|
|
|
51
51
|
|
|
52
52
|
pathFilename: PurePath = getPathFilename(logicalPathInfix=logicalPathInfix, identifierModule=identifierModule)
|
|
53
53
|
|
|
54
|
-
write_astModule(astModule, pathFilename, packageSettings.identifierPackage)
|
|
54
|
+
write_astModule(astModule, pathFilename, identifierPackage=packageSettings.identifierPackage)
|
|
55
55
|
|
|
56
56
|
return pathFilename
|
|
57
57
|
|
|
58
58
|
def makeMeandersModules() -> None:
|
|
59
59
|
"""Make meanders modules."""
|
|
60
60
|
astModule: ast.Module = getModule(logicalPathInfix='algorithms', identifierModule='matrixMeanders')
|
|
61
|
-
pathFilename: PurePath = makeCountBigInt(astModule, 'bigInt', 'countBigInt', logicalPathInfixMeanders, default['function']['dispatcher'])
|
|
61
|
+
pathFilename: PurePath = makeCountBigInt(astModule, 'bigInt', 'countBigInt', logicalPathInfixMeanders, default['function']['dispatcher']) # pyright: ignore[reportUnusedVariable] # noqa: F841
|
|
62
62
|
|
|
63
63
|
if __name__ == '__main__':
|
|
64
64
|
makeMeandersModules()
|