mapFolding 0.16.2__py3-none-any.whl → 0.16.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- easyRun/NOTcountingFolds.py +6 -5
- easyRun/countFolds.py +1 -1
- easyRun/generateAllModules.py +14 -0
- easyRun/meanders.py +1 -1
- mapFolding/__init__.py +1 -0
- mapFolding/_theSSOT.py +3 -2
- mapFolding/_theTypes.py +3 -0
- mapFolding/algorithms/A086345.py +75 -0
- mapFolding/algorithms/oeisIDbyFormula.py +2 -2
- mapFolding/algorithms/symmetricFolds.py +36 -0
- mapFolding/basecamp.py +80 -149
- mapFolding/dataBaskets.py +123 -5
- mapFolding/filesystemToolkit.py +4 -32
- mapFolding/oeis.py +5 -12
- mapFolding/reference/A086345Wu.py +25 -0
- mapFolding/reference/matrixMeandersAnalysis/signatures.py +3 -0
- mapFolding/someAssemblyRequired/A007822/A007822rawMaterials.py +10 -45
- mapFolding/someAssemblyRequired/A007822/_asynchronousAnnex.py +51 -0
- mapFolding/someAssemblyRequired/A007822/makeA007822AsynchronousModules.py +36 -195
- mapFolding/someAssemblyRequired/A007822/makeA007822Modules.py +42 -44
- mapFolding/someAssemblyRequired/RecipeJob.py +78 -18
- mapFolding/someAssemblyRequired/__init__.py +3 -8
- mapFolding/someAssemblyRequired/_toolkitContainers.py +32 -3
- mapFolding/someAssemblyRequired/infoBooth.py +40 -23
- mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +74 -153
- mapFolding/someAssemblyRequired/makeJobTheorem2codon.py +56 -88
- mapFolding/someAssemblyRequired/makingModules_count.py +10 -12
- mapFolding/someAssemblyRequired/makingModules_doTheNeedful.py +6 -68
- mapFolding/someAssemblyRequired/{mapFolding → mapFoldingModules}/makeMapFoldingModules.py +24 -30
- mapFolding/someAssemblyRequired/meanders/makeMeandersModules.py +8 -6
- mapFolding/someAssemblyRequired/toolkitMakeModules.py +2 -2
- mapFolding/someAssemblyRequired/toolkitNumba.py +1 -1
- mapFolding/someAssemblyRequired/transformationTools.py +10 -12
- mapFolding/syntheticModules/A007822/algorithm.py +45 -50
- mapFolding/syntheticModules/A007822/asynchronous.py +91 -34
- mapFolding/syntheticModules/A007822/initializeState.py +15 -21
- mapFolding/syntheticModules/A007822/theorem2.py +16 -22
- mapFolding/syntheticModules/A007822/theorem2Numba.py +20 -26
- mapFolding/syntheticModules/A007822/theorem2Trimmed.py +17 -23
- mapFolding/syntheticModules/countParallelNumba.py +3 -7
- mapFolding/syntheticModules/daoOfMapFoldingNumba.py +1 -2
- mapFolding/syntheticModules/meanders/bigInt.py +9 -9
- mapFolding/syntheticModules/theorem2Numba.py +28 -9
- mapFolding/syntheticModules/theorem2Trimmed.py +1 -1
- mapFolding/tests/test_computations.py +1 -1
- {mapfolding-0.16.2.dist-info → mapfolding-0.16.4.dist-info}/METADATA +4 -1
- {mapfolding-0.16.2.dist-info → mapfolding-0.16.4.dist-info}/RECORD +52 -61
- mapFolding/_dataPacking.py +0 -68
- mapFolding/reference/meandersDumpingGround/A005316intOptimized.py +0 -122
- mapFolding/reference/meandersDumpingGround/A005316optimized128bit.py +0 -79
- mapFolding/reference/meandersDumpingGround/matrixMeandersBaseline.py +0 -65
- mapFolding/reference/meandersDumpingGround/matrixMeandersBaselineAnnex.py +0 -84
- mapFolding/reference/meandersDumpingGround/matrixMeandersSimpleQueue.py +0 -90
- mapFolding/syntheticModules/A007822/algorithmNumba.py +0 -94
- mapFolding/syntheticModules/A007822/asynchronousAnnex.py +0 -66
- mapFolding/syntheticModules/A007822/asynchronousAnnexNumba.py +0 -70
- mapFolding/syntheticModules/A007822/asynchronousNumba.py +0 -79
- mapFolding/syntheticModules/A007822/asynchronousTheorem2.py +0 -65
- mapFolding/syntheticModules/A007822/asynchronousTrimmed.py +0 -56
- mapFolding/syntheticModules/dataPacking.py +0 -26
- mapFolding/syntheticModules/dataPackingA007822.py +0 -92
- /mapFolding/someAssemblyRequired/{mapFolding → mapFoldingModules}/__init__.py +0 -0
- {mapfolding-0.16.2.dist-info → mapfolding-0.16.4.dist-info}/WHEEL +0 -0
- {mapfolding-0.16.2.dist-info → mapfolding-0.16.4.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.16.2.dist-info → mapfolding-0.16.4.dist-info}/licenses/LICENSE +0 -0
- {mapfolding-0.16.2.dist-info → mapfolding-0.16.4.dist-info}/top_level.txt +0 -0
|
@@ -4,59 +4,31 @@ https://docs.exaloop.io/start/install/
|
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
6
|
from astToolkit import (
|
|
7
|
-
Be,
|
|
8
|
-
|
|
7
|
+
Be, extractFunctionDef, Grab, identifierDotAttribute, IngredientsFunction, IngredientsModule, Make, NodeChanger,
|
|
8
|
+
parseLogicalPath2astModule, Then)
|
|
9
9
|
from astToolkit.transformationTools import removeUnusedParameters, write_astModule
|
|
10
|
-
from hunterMakesPy import
|
|
11
|
-
from mapFolding import DatatypeLeavesTotal, getPathFilenameFoldsTotal
|
|
10
|
+
from hunterMakesPy import raiseIfNone
|
|
11
|
+
from mapFolding import DatatypeLeavesTotal, getPathFilenameFoldsTotal, packageSettings
|
|
12
12
|
from mapFolding.dataBaskets import MapFoldingState
|
|
13
|
-
from mapFolding.someAssemblyRequired import IfThis
|
|
14
|
-
from mapFolding.someAssemblyRequired.RecipeJob import
|
|
15
|
-
|
|
13
|
+
from mapFolding.someAssemblyRequired import DatatypeConfiguration, default, IfThis
|
|
14
|
+
from mapFolding.someAssemblyRequired.RecipeJob import (
|
|
15
|
+
customizeDatatypeViaImport, moveShatteredDataclass_arg2body, RecipeJobTheorem2)
|
|
16
|
+
from mapFolding.syntheticModules.initializeState import transitionOnGroupsOfFolds
|
|
16
17
|
from pathlib import Path, PurePosixPath
|
|
17
|
-
from typing import cast,
|
|
18
|
-
import ast
|
|
18
|
+
from typing import cast, TYPE_CHECKING
|
|
19
19
|
import subprocess
|
|
20
20
|
import sys
|
|
21
21
|
|
|
22
22
|
if TYPE_CHECKING:
|
|
23
23
|
from io import TextIOBase
|
|
24
|
+
import ast
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
"""Configuration for mapping framework datatypes to compiled datatypes.
|
|
26
|
+
# TODO Converge with `makeJobTheorem2Numba`.
|
|
27
27
|
|
|
28
|
-
This configuration class defines how abstract datatypes used in the map folding framework should be replaced with compiled
|
|
29
|
-
datatypes during code generation. Each configuration specifies the source module, target type name, and optional import alias
|
|
30
|
-
for the transformation.
|
|
31
|
-
|
|
32
|
-
Attributes
|
|
33
|
-
----------
|
|
34
|
-
datatypeIdentifier : str
|
|
35
|
-
Framework datatype identifier to be replaced.
|
|
36
|
-
typeModule : identifierDotAttribute
|
|
37
|
-
Module containing the target datatype (e.g., 'codon', 'numpy').
|
|
38
|
-
typeIdentifier : str
|
|
39
|
-
Concrete type name in the target module.
|
|
40
|
-
type_asname : str | None = None
|
|
41
|
-
Optional import alias for the type.
|
|
42
|
-
"""
|
|
43
|
-
|
|
44
|
-
datatypeIdentifier: str
|
|
45
|
-
typeModule: identifierDotAttribute
|
|
46
|
-
typeIdentifier: str
|
|
47
|
-
type_asname: str | None = None
|
|
48
|
-
|
|
49
|
-
# TODO replace with dynamic system. Probably use `Final` in the dataclass.
|
|
50
|
-
listIdentifiersStaticValuesHARDCODED: list[str] = ['dimensionsTotal', 'leavesTotal']
|
|
51
|
-
|
|
52
|
-
# TODO Dynamically calculate the bitwidth of each datatype.
|
|
53
28
|
listDatatypeConfigurations: list[DatatypeConfiguration] = [
|
|
54
29
|
DatatypeConfiguration(datatypeIdentifier='DatatypeLeavesTotal', typeModule='numpy', typeIdentifier='uint8', type_asname='DatatypeLeavesTotal'),
|
|
55
30
|
DatatypeConfiguration(datatypeIdentifier='DatatypeElephino', typeModule='numpy', typeIdentifier='uint8', type_asname='DatatypeElephino'),
|
|
56
31
|
DatatypeConfiguration(datatypeIdentifier='DatatypeFoldsTotal', typeModule='numpy', typeIdentifier='int64', type_asname='DatatypeFoldsTotal'),
|
|
57
|
-
]
|
|
58
|
-
|
|
59
|
-
listNumPy_dtype: list[DatatypeConfiguration] = [
|
|
60
32
|
DatatypeConfiguration(datatypeIdentifier='Array1DLeavesTotal', typeModule='numpy', typeIdentifier='uint8', type_asname='Array1DLeavesTotal'),
|
|
61
33
|
DatatypeConfiguration(datatypeIdentifier='Array1DElephino', typeModule='numpy', typeIdentifier='uint8', type_asname='Array1DElephino'),
|
|
62
34
|
DatatypeConfiguration(datatypeIdentifier='Array3DLeavesTotal', typeModule='numpy', typeIdentifier='uint8', type_asname='Array3DLeavesTotal'),
|
|
@@ -78,55 +50,60 @@ def _addWriteFoldsTotal(ingredientsFunction: IngredientsFunction, job: RecipeJob
|
|
|
78
50
|
|
|
79
51
|
return ingredientsFunction
|
|
80
52
|
|
|
81
|
-
def
|
|
82
|
-
|
|
83
|
-
ingredientsFunction.imports.removeImportFrom(datatypeConfig.typeModule, None, datatypeConfig.datatypeIdentifier)
|
|
84
|
-
ingredientsFunction.imports.addImportFrom_asStr(datatypeConfig.typeModule, datatypeConfig.typeIdentifier, datatypeConfig.type_asname)
|
|
85
|
-
|
|
86
|
-
ingredientsFunction.imports.removeImportFromModule('mapFolding.dataBaskets')
|
|
53
|
+
def _variableCompatibility(ingredientsFunction: IngredientsFunction, job: RecipeJobTheorem2) -> IngredientsFunction:
|
|
54
|
+
"""Ensure the variable is compiled to the correct type.
|
|
87
55
|
|
|
88
|
-
|
|
56
|
+
Add a type constructor to `identifier` to ensure compatibility if
|
|
57
|
+
- an incompatible type might be assigned to it,
|
|
58
|
+
- it might be compared with an incompatible type,
|
|
59
|
+
- it is used as an indexer but its type is not a valid indexer type.
|
|
89
60
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
61
|
+
Parameters
|
|
62
|
+
----------
|
|
63
|
+
ingredientsFunction : IngredientsFunction
|
|
64
|
+
Function to modify.
|
|
65
|
+
job : RecipeJobTheorem2
|
|
66
|
+
Configuration settings with identifiers and their type annotations.
|
|
93
67
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
68
|
+
Returns
|
|
69
|
+
-------
|
|
70
|
+
ingredientsFunction : IngredientsFunction
|
|
71
|
+
Modified function.
|
|
72
|
+
"""
|
|
97
73
|
for ast_arg in job.shatteredDataclass.list_argAnnotated4ArgumentsSpecification:
|
|
98
|
-
identifier = ast_arg.arg
|
|
99
|
-
annotation = raiseIfNone(ast_arg.annotation)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
74
|
+
identifier: str = ast_arg.arg
|
|
75
|
+
annotation: ast.expr = raiseIfNone(ast_arg.annotation)
|
|
76
|
+
|
|
77
|
+
# ------- `identifier` is target of Augmented Assignment, or --------------
|
|
78
|
+
# ------- `identifier` is target of Assignment and value is Constant. -----
|
|
79
|
+
NodeChanger(
|
|
80
|
+
IfThis.isAnyOf(
|
|
81
|
+
Be.AugAssign.targetIs(IfThis.isNestedNameIdentifier(identifier))
|
|
82
|
+
, IfThis.isAllOf(Be.Assign.targetsIs(Be.at(0, IfThis.isNestedNameIdentifier(identifier)))
|
|
83
|
+
, Be.Assign.valueIs(Be.Constant))
|
|
107
84
|
)
|
|
108
85
|
, doThat=lambda node, annotation=annotation: Grab.valueAttribute(Then.replaceWith(Make.Call(annotation, listParameters=[node.value])))(node)
|
|
109
86
|
).visit(ingredientsFunction.astFunctionDef)
|
|
110
87
|
|
|
111
|
-
|
|
88
|
+
# ------- `identifier` - 1. ----------------------------------------------
|
|
112
89
|
NodeChanger(Be.BinOp.leftIs(IfThis.isNestedNameIdentifier(identifier))
|
|
113
90
|
, doThat=lambda node, annotation=annotation: Grab.rightAttribute(Then.replaceWith(Make.Call(annotation, listParameters=[node.right])))(node)
|
|
114
91
|
).visit(ingredientsFunction.astFunctionDef)
|
|
115
92
|
|
|
116
|
-
|
|
93
|
+
# ------- `identifier` in Comparison. -------------------------------------
|
|
117
94
|
NodeChanger(Be.Compare.leftIs(IfThis.isNestedNameIdentifier(identifier))
|
|
118
95
|
, doThat=lambda node, annotation=annotation: Grab.comparatorsAttribute(lambda at, annotation=annotation: Then.replaceWith([Make.Call(annotation, listParameters=[node.comparators[0]])])(at[0]))(node)
|
|
119
96
|
).visit(ingredientsFunction.astFunctionDef)
|
|
120
97
|
|
|
121
|
-
|
|
98
|
+
# ------- `identifier` has exactly one index value. -----------------------
|
|
122
99
|
NodeChanger(IfThis.isAllOf(Be.Subscript.valueIs(IfThis.isNestedNameIdentifier(identifier))
|
|
123
100
|
, lambda node: not Be.Subscript.sliceIs(Be.Tuple)(node))
|
|
124
101
|
, doThat=lambda node: Grab.sliceAttribute(Then.replaceWith(Make.Call(Make.Name('int'), listParameters=[node.slice])))(node)
|
|
125
102
|
).visit(ingredientsFunction.astFunctionDef)
|
|
126
103
|
|
|
127
|
-
|
|
104
|
+
# ------- `identifier` has multiple index values. -------------------------
|
|
128
105
|
NodeChanger(IfThis.isAllOf(Be.Subscript.valueIs(IfThis.isNestedNameIdentifier(identifier))
|
|
129
|
-
|
|
106
|
+
, Be.Subscript.sliceIs(Be.Tuple))
|
|
130
107
|
, doThat=lambda node: Grab.sliceAttribute(Grab.eltsAttribute(
|
|
131
108
|
Then.replaceWith([
|
|
132
109
|
Make.Call(Make.Name('int'), listParameters=[cast('ast.Tuple', node.slice).elts[index]])
|
|
@@ -135,19 +112,6 @@ def _variableCompatibility(ingredientsFunction: IngredientsFunction, job: Recipe
|
|
|
135
112
|
|
|
136
113
|
return ingredientsFunction
|
|
137
114
|
|
|
138
|
-
def _move_arg2body(identifier: str, job: RecipeJobTheorem2) -> ast.AnnAssign | ast.Assign:
|
|
139
|
-
Ima___Assign, elementConstructor = job.shatteredDataclass.Z0Z_field2AnnAssign[identifier]
|
|
140
|
-
match elementConstructor:
|
|
141
|
-
case 'scalar':
|
|
142
|
-
cast('ast.Constant', cast('ast.Call', Ima___Assign.value).args[0]).value = int(job.state.__dict__[identifier])
|
|
143
|
-
case 'array':
|
|
144
|
-
dataAsStrRLE: str = autoDecodingRLE(job.state.__dict__[identifier], assumeAddSpaces=True)
|
|
145
|
-
dataAs_ast_expr: ast.expr = _pythonCode2expr(dataAsStrRLE)
|
|
146
|
-
cast('ast.Call', Ima___Assign.value).args = [dataAs_ast_expr]
|
|
147
|
-
case _:
|
|
148
|
-
pass
|
|
149
|
-
return Ima___Assign
|
|
150
|
-
|
|
151
115
|
def makeJob(job: RecipeJobTheorem2) -> None:
|
|
152
116
|
"""Generate an optimized module for map folding calculations.
|
|
153
117
|
|
|
@@ -157,22 +121,21 @@ def makeJob(job: RecipeJobTheorem2) -> None:
|
|
|
157
121
|
Parameters
|
|
158
122
|
----------
|
|
159
123
|
job : RecipeJobTheorem2
|
|
160
|
-
Configuration recipe containing source locations, target paths, and state.
|
|
124
|
+
Configuration recipe containing source locations, target paths, raw materials, and state.
|
|
161
125
|
|
|
162
126
|
"""
|
|
163
127
|
ingredientsCount: IngredientsFunction = IngredientsFunction(raiseIfNone(extractFunctionDef(job.source_astModule, job.countCallable)))
|
|
164
128
|
ingredientsCount.astFunctionDef.decorator_list = []
|
|
165
129
|
|
|
166
130
|
# Replace identifiers-with-static-values with their values.
|
|
167
|
-
|
|
168
|
-
for identifier in listIdentifiersStaticValues:
|
|
131
|
+
for identifier in job.shatteredDataclass.listIdentifiersStaticScalars:
|
|
169
132
|
NodeChanger(IfThis.isNameIdentifier(identifier)
|
|
170
|
-
, Then.replaceWith(Make.Constant(int(job.state.
|
|
133
|
+
, Then.replaceWith(Make.Constant(int(eval(f"job.state.{identifier}")))) # noqa: S307
|
|
171
134
|
).visit(ingredientsCount.astFunctionDef)
|
|
172
135
|
|
|
173
136
|
ingredientsCount.imports.update(job.shatteredDataclass.imports)
|
|
174
137
|
ingredientsCount = removeUnusedParameters(ingredientsCount)
|
|
175
|
-
NodeChanger(Be.arg, lambda removeIt: ingredientsCount.astFunctionDef.body.insert(0,
|
|
138
|
+
NodeChanger(Be.arg, lambda removeIt: ingredientsCount.astFunctionDef.body.insert(0, moveShatteredDataclass_arg2body(removeIt.arg, job))).visit(ingredientsCount.astFunctionDef)
|
|
176
139
|
|
|
177
140
|
ingredientsCount = _addWriteFoldsTotal(ingredientsCount, job)
|
|
178
141
|
ingredientsCount = _variableCompatibility(ingredientsCount, job)
|
|
@@ -181,11 +144,14 @@ def makeJob(job: RecipeJobTheorem2) -> None:
|
|
|
181
144
|
Make.If(Make.Compare(Make.Name('__name__'), [Make.Eq()], [Make.Constant('__main__')])
|
|
182
145
|
, body=[Make.Expr(Make.Call(Make.Name(job.countCallable)))])]))
|
|
183
146
|
|
|
184
|
-
ingredientsCount, ingredientsModule =
|
|
147
|
+
ingredientsCount, ingredientsModule = customizeDatatypeViaImport(ingredientsCount, ingredientsModule, listDatatypeConfigurations)
|
|
148
|
+
|
|
149
|
+
ingredientsCount.imports.removeImportFromModule('mapFolding.dataBaskets')
|
|
185
150
|
|
|
186
151
|
ingredientsModule.appendIngredientsFunction(ingredientsCount)
|
|
187
152
|
|
|
188
153
|
if sys.platform == 'linux':
|
|
154
|
+
Path(job.pathFilenameModule).parent.mkdir(parents=True, exist_ok=True)
|
|
189
155
|
buildCommand: list[str] = ['codon', 'build', '--exe', '--release',
|
|
190
156
|
'--fast-math', '--enable-unsafe-fp-math', '--disable-exceptions',
|
|
191
157
|
'--mcpu=native',
|
|
@@ -200,6 +166,7 @@ def makeJob(job: RecipeJobTheorem2) -> None:
|
|
|
200
166
|
sys.stdout.write(f"sudo systemd-run --unit={job.moduleIdentifier} --nice=-10 --property=CPUAffinity=0 {job.pathFilenameModule.with_suffix('')}\n")
|
|
201
167
|
else:
|
|
202
168
|
write_astModule(ingredientsModule, pathFilename=job.pathFilenameModule, packageName=job.packageIdentifier)
|
|
169
|
+
sys.stdout.write(f"python {Path(job.pathFilenameModule)}\n")
|
|
203
170
|
|
|
204
171
|
def fromMapShape(mapShape: tuple[DatatypeLeavesTotal, ...]) -> None:
|
|
205
172
|
"""Create a binary executable for a map-folding job from map dimensions.
|
|
@@ -214,14 +181,15 @@ def fromMapShape(mapShape: tuple[DatatypeLeavesTotal, ...]) -> None:
|
|
|
214
181
|
along one axis.
|
|
215
182
|
|
|
216
183
|
"""
|
|
217
|
-
state = transitionOnGroupsOfFolds(MapFoldingState(mapShape))
|
|
184
|
+
state: MapFoldingState = transitionOnGroupsOfFolds(MapFoldingState(mapShape))
|
|
218
185
|
pathModule = PurePosixPath(Path.home(), 'mapFolding', 'jobs')
|
|
219
|
-
|
|
186
|
+
logicalPath2astModule: identifierDotAttribute = f'{packageSettings.identifierPackage}.{default['logicalPath']['synthetic']}.theorem2Numba'
|
|
187
|
+
source_astModule: ast.Module = parseLogicalPath2astModule(logicalPath2astModule)
|
|
220
188
|
pathFilenameFoldsTotal = PurePosixPath(getPathFilenameFoldsTotal(state.mapShape, pathModule))
|
|
221
189
|
aJob = RecipeJobTheorem2(state, source_astModule=source_astModule, pathModule=pathModule, pathFilenameFoldsTotal=pathFilenameFoldsTotal)
|
|
222
190
|
makeJob(aJob)
|
|
223
191
|
|
|
224
192
|
if __name__ == '__main__':
|
|
225
|
-
mapShape = (1,
|
|
193
|
+
mapShape: tuple[DatatypeLeavesTotal, ...] = (1, 14)
|
|
226
194
|
fromMapShape(mapShape)
|
|
227
195
|
|
|
@@ -9,13 +9,11 @@ from astToolkit import (
|
|
|
9
9
|
from astToolkit.transformationTools import inlineFunctionDef, removeUnusedParameters, write_astModule
|
|
10
10
|
from hunterMakesPy import raiseIfNone
|
|
11
11
|
from mapFolding import packageSettings
|
|
12
|
-
from mapFolding.someAssemblyRequired import
|
|
13
|
-
identifierCallableSourceDEFAULT, identifierCountingDEFAULT, IfThis, ShatteredDataclass)
|
|
12
|
+
from mapFolding.someAssemblyRequired import default, IfThis, ShatteredDataclass
|
|
14
13
|
from mapFolding.someAssemblyRequired.toolkitMakeModules import findDataclass, getLogicalPath, getPathFilename
|
|
15
14
|
from mapFolding.someAssemblyRequired.toolkitNumba import decorateCallableWithNumba, parametersNumbaLight
|
|
16
15
|
from mapFolding.someAssemblyRequired.transformationTools import (
|
|
17
16
|
removeDataclassFromFunction, shatter_dataclassesDOTdataclass, unpackDataclassCallFunctionRepackDataclass)
|
|
18
|
-
from os import PathLike
|
|
19
17
|
from pathlib import PurePath
|
|
20
18
|
from typing import cast
|
|
21
19
|
import ast
|
|
@@ -42,7 +40,7 @@ def makeMapFoldingNumba(astModule: ast.Module, identifierModule: str, identifier
|
|
|
42
40
|
Filesystem path where the optimized module was written.
|
|
43
41
|
|
|
44
42
|
"""
|
|
45
|
-
sourceCallableIdentifier: str =
|
|
43
|
+
sourceCallableIdentifier: str = default['function']['counting']
|
|
46
44
|
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
47
45
|
ingredientsFunction.astFunctionDef.name = identifierCallable or sourceCallableIdentifier
|
|
48
46
|
|
|
@@ -107,13 +105,13 @@ def makeTheorem2(astModule: ast.Module, identifierModule: str, identifierCallabl
|
|
|
107
105
|
identifierCallableInitializeDataclass = identifierCallableInitializeDataclassHARDCODED
|
|
108
106
|
identifierModuleInitializeDataclass = identifierModuleInitializeDataclassHARDCODED
|
|
109
107
|
|
|
110
|
-
sourceCallableIdentifier =
|
|
108
|
+
sourceCallableIdentifier = default['function']['counting']
|
|
111
109
|
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
112
110
|
ingredientsFunction.astFunctionDef.name = identifierCallable or sourceCallableIdentifier
|
|
113
111
|
|
|
114
112
|
dataclassInstanceIdentifier: str = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
115
113
|
|
|
116
|
-
theCountingIdentifier: str =
|
|
114
|
+
theCountingIdentifier: str = default['variable']['counting']
|
|
117
115
|
doubleTheCount: ast.AugAssign = Make.AugAssign(Make.Attribute(Make.Name(dataclassInstanceIdentifier), theCountingIdentifier), Make.Mult(), Make.Constant(2))
|
|
118
116
|
|
|
119
117
|
NodeChanger(
|
|
@@ -162,7 +160,7 @@ def makeTheorem2(astModule: ast.Module, identifierModule: str, identifierCallabl
|
|
|
162
160
|
|
|
163
161
|
# Update any calls to the original function name with the new target function name
|
|
164
162
|
NodeChanger(
|
|
165
|
-
findThis = Be.Call.funcIs(Be.Name.idIs(IfThis.isIdentifier(
|
|
163
|
+
findThis = Be.Call.funcIs(Be.Name.idIs(IfThis.isIdentifier(default['function']['counting'])))
|
|
166
164
|
, doThat = Grab.funcAttribute(Grab.idAttribute(Then.replaceWith(targetCallableIdentifier)))
|
|
167
165
|
).visit(ingredientsFunctionDispatcher.astFunctionDef)
|
|
168
166
|
|
|
@@ -182,7 +180,7 @@ def makeTheorem2(astModule: ast.Module, identifierModule: str, identifierCallabl
|
|
|
182
180
|
|
|
183
181
|
return pathFilename
|
|
184
182
|
|
|
185
|
-
def numbaOnTheorem2(astModule: ast.Module, identifierModule: str, identifierCallable: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
|
|
183
|
+
def numbaOnTheorem2(astModule: ast.Module, identifierModule: str, identifierCallable: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
|
|
186
184
|
"""Generate Numba-accelerated Theorem 2 implementation with dataclass decomposition.
|
|
187
185
|
|
|
188
186
|
Parameters
|
|
@@ -204,7 +202,7 @@ def numbaOnTheorem2(astModule: ast.Module, identifierModule: str, identifierCall
|
|
|
204
202
|
Filesystem path where the accelerated module was written.
|
|
205
203
|
|
|
206
204
|
"""
|
|
207
|
-
sourceCallableIdentifier =
|
|
205
|
+
sourceCallableIdentifier = default['function']['counting']
|
|
208
206
|
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
209
207
|
ingredientsFunction.astFunctionDef.name = identifierCallable or sourceCallableIdentifier
|
|
210
208
|
|
|
@@ -244,7 +242,7 @@ def numbaOnTheorem2(astModule: ast.Module, identifierModule: str, identifierCall
|
|
|
244
242
|
|
|
245
243
|
return pathFilename
|
|
246
244
|
|
|
247
|
-
def trimTheorem2(astModule: ast.Module, identifierModule: str, identifierCallable: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
|
|
245
|
+
def trimTheorem2(astModule: ast.Module, identifierModule: str, identifierCallable: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
|
|
248
246
|
"""Generate constrained Theorem 2 implementation by removing unnecessary logic.
|
|
249
247
|
|
|
250
248
|
Parameters
|
|
@@ -266,7 +264,7 @@ def trimTheorem2(astModule: ast.Module, identifierModule: str, identifierCallabl
|
|
|
266
264
|
Filesystem path where the trimmed module was written.
|
|
267
265
|
|
|
268
266
|
"""
|
|
269
|
-
sourceCallableIdentifier: str =
|
|
267
|
+
sourceCallableIdentifier: str = default['function']['counting']
|
|
270
268
|
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
271
269
|
ingredientsFunction.astFunctionDef.name = identifierCallable or sourceCallableIdentifier
|
|
272
270
|
|
|
@@ -286,7 +284,7 @@ def trimTheorem2(astModule: ast.Module, identifierModule: str, identifierCallabl
|
|
|
286
284
|
|
|
287
285
|
# Update any calls to the original function name with the new target function name
|
|
288
286
|
NodeChanger(
|
|
289
|
-
findThis = Be.Call.funcIs(Be.Name.idIs(IfThis.isIdentifier(
|
|
287
|
+
findThis = Be.Call.funcIs(Be.Name.idIs(IfThis.isIdentifier(default['function']['counting'])))
|
|
290
288
|
, doThat = Grab.funcAttribute(Grab.idAttribute(Then.replaceWith(targetCallableIdentifier)))
|
|
291
289
|
).visit(ingredientsFunctionDispatcher.astFunctionDef)
|
|
292
290
|
|
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
"""Make functions that are complementary to the `count` function and are often called by `doTheNeedful`."""
|
|
2
2
|
from astToolkit import (
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Be, DOT, Grab, identifierDotAttribute, IngredientsFunction, IngredientsModule, LedgerOfImports, NodeChanger,
|
|
4
|
+
NodeTourist, Then)
|
|
5
5
|
from astToolkit.transformationTools import inlineFunctionDef, write_astModule
|
|
6
6
|
from hunterMakesPy import raiseIfNone
|
|
7
7
|
from mapFolding import packageSettings
|
|
8
|
-
from mapFolding.someAssemblyRequired import
|
|
9
|
-
|
|
10
|
-
identifierModuleDataPackingDEFAULT, identifierModuleSourceAlgorithmDEFAULT, IfThis, logicalPathInfixAlgorithmDEFAULT,
|
|
11
|
-
logicalPathInfixDEFAULT, ShatteredDataclass)
|
|
12
|
-
from mapFolding.someAssemblyRequired.toolkitMakeModules import findDataclass, getPathFilename
|
|
13
|
-
from mapFolding.someAssemblyRequired.transformationTools import (
|
|
14
|
-
shatter_dataclassesDOTdataclass, unpackDataclassCallFunctionRepackDataclass)
|
|
15
|
-
from os import PathLike
|
|
8
|
+
from mapFolding.someAssemblyRequired import default, IfThis
|
|
9
|
+
from mapFolding.someAssemblyRequired.toolkitMakeModules import getPathFilename
|
|
16
10
|
from pathlib import PurePath
|
|
17
|
-
from typing import cast
|
|
18
11
|
import ast
|
|
19
12
|
|
|
20
13
|
def makeInitializeState(astModule: ast.Module, moduleIdentifier: str, callableIdentifier: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath: # noqa: ARG001
|
|
@@ -49,12 +42,12 @@ def makeInitializeState(astModule: ast.Module, moduleIdentifier: str, callableId
|
|
|
49
42
|
Filesystem path where the initialization module was written.
|
|
50
43
|
|
|
51
44
|
"""
|
|
52
|
-
sourceCallableIdentifier: identifierDotAttribute =
|
|
45
|
+
sourceCallableIdentifier: identifierDotAttribute = default['function']['counting']
|
|
53
46
|
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
54
47
|
ingredientsFunction.astFunctionDef.name = callableIdentifier or sourceCallableIdentifier
|
|
55
48
|
|
|
56
49
|
dataclassInstanceIdentifier: identifierDotAttribute = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
57
|
-
theCountingIdentifier: identifierDotAttribute =
|
|
50
|
+
theCountingIdentifier: identifierDotAttribute = default['variable']['counting']
|
|
58
51
|
|
|
59
52
|
findThis = IfThis.isWhileAttributeNamespaceIdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
|
|
60
53
|
doThat = Grab.testAttribute(Grab.andDoAllOf([Grab.opsAttribute(Then.replaceWith([ast.Eq()])), Grab.leftAttribute(Grab.attrAttribute(Then.replaceWith(theCountingIdentifier)))]))
|
|
@@ -64,58 +57,3 @@ def makeInitializeState(astModule: ast.Module, moduleIdentifier: str, callableId
|
|
|
64
57
|
write_astModule(IngredientsModule(ingredientsFunction), pathFilename, packageSettings.identifierPackage)
|
|
65
58
|
|
|
66
59
|
return pathFilename
|
|
67
|
-
|
|
68
|
-
def makeUnRePackDataclass(astImportFrom: ast.ImportFrom, moduleIdentifier: str = identifierModuleDataPackingDEFAULT) -> PurePath:
|
|
69
|
-
"""Generate interface module for dataclass unpacking and repacking operations.
|
|
70
|
-
|
|
71
|
-
Parameters
|
|
72
|
-
----------
|
|
73
|
-
astImportFrom : ast.ImportFrom
|
|
74
|
-
Import statement specifying the target optimized function to call.
|
|
75
|
-
|
|
76
|
-
moduleIdentifier : str = identifierModuleDataPackingDEFAULT
|
|
77
|
-
Name for the generated interface module.
|
|
78
|
-
|
|
79
|
-
Returns
|
|
80
|
-
-------
|
|
81
|
-
pathFilename : PurePath
|
|
82
|
-
Filesystem path where the interface module was written.
|
|
83
|
-
"""
|
|
84
|
-
callableIdentifierHARDCODED: str = 'sequential'
|
|
85
|
-
|
|
86
|
-
algorithmSourceModule: identifierDotAttribute = identifierModuleSourceAlgorithmDEFAULT
|
|
87
|
-
callableIdentifier: str = callableIdentifierHARDCODED
|
|
88
|
-
logicalPathInfix: identifierDotAttribute = logicalPathInfixDEFAULT
|
|
89
|
-
logicalPathInfixAlgorithm: identifierDotAttribute = logicalPathInfixAlgorithmDEFAULT
|
|
90
|
-
sourceCallableIdentifier: str = identifierCallableSourceDispatcherDEFAULT
|
|
91
|
-
|
|
92
|
-
logicalPathSourceModule: identifierDotAttribute = '.'.join([packageSettings.identifierPackage, logicalPathInfixAlgorithm, algorithmSourceModule]) # noqa: FLY002
|
|
93
|
-
|
|
94
|
-
ingredientsFunction: IngredientsFunction = astModuleToIngredientsFunction(parseLogicalPath2astModule(logicalPathSourceModule), sourceCallableIdentifier)
|
|
95
|
-
ingredientsFunction.astFunctionDef.name = callableIdentifier
|
|
96
|
-
|
|
97
|
-
shatteredDataclass: ShatteredDataclass = shatter_dataclassesDOTdataclass(*findDataclass(ingredientsFunction))
|
|
98
|
-
|
|
99
|
-
ingredientsFunction.imports.update(shatteredDataclass.imports)
|
|
100
|
-
ingredientsFunction.imports.addAst(astImportFrom)
|
|
101
|
-
targetCallableIdentifier: str = astImportFrom.names[0].name
|
|
102
|
-
ingredientsFunction = raiseIfNone(unpackDataclassCallFunctionRepackDataclass(ingredientsFunction, targetCallableIdentifier, shatteredDataclass))
|
|
103
|
-
targetFunctionDef: ast.FunctionDef = raiseIfNone(extractFunctionDef(parseLogicalPath2astModule(raiseIfNone(astImportFrom.module)), targetCallableIdentifier))
|
|
104
|
-
astTuple: ast.Tuple = cast('ast.Tuple', raiseIfNone(NodeTourist(Be.Return.valueIs(Be.Tuple)
|
|
105
|
-
, doThat=Then.extractIt(DOT.value)).captureLastMatch(targetFunctionDef)))
|
|
106
|
-
astTuple.ctx = Make.Store()
|
|
107
|
-
|
|
108
|
-
changeAssignCallToTarget = NodeChanger(
|
|
109
|
-
findThis = Be.Assign.valueIs(IfThis.isCallIdentifier(targetCallableIdentifier))
|
|
110
|
-
, doThat = Then.replaceWith(Make.Assign([astTuple], value=Make.Call(Make.Name(targetCallableIdentifier), astTuple.elts))))
|
|
111
|
-
changeAssignCallToTarget.visit(ingredientsFunction.astFunctionDef)
|
|
112
|
-
|
|
113
|
-
ingredientsModule = IngredientsModule(ingredientsFunction)
|
|
114
|
-
ingredientsModule.removeImportFromModule('numpy')
|
|
115
|
-
|
|
116
|
-
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix, moduleIdentifier)
|
|
117
|
-
|
|
118
|
-
write_astModule(ingredientsModule, pathFilename, packageSettings.identifierPackage)
|
|
119
|
-
|
|
120
|
-
return pathFilename
|
|
121
|
-
|
|
@@ -6,17 +6,14 @@ from astToolkit import (
|
|
|
6
6
|
from astToolkit.transformationTools import inlineFunctionDef, removeUnusedParameters, write_astModule
|
|
7
7
|
from hunterMakesPy import importLogicalPath2Identifier, raiseIfNone
|
|
8
8
|
from mapFolding import packageSettings
|
|
9
|
-
from mapFolding.someAssemblyRequired import
|
|
10
|
-
DeReConstructField2ast, identifierCallableSourceDEFAULT, identifierCallableSourceDispatcherDEFAULT, IfThis,
|
|
11
|
-
logicalPathInfixDEFAULT, ShatteredDataclass)
|
|
9
|
+
from mapFolding.someAssemblyRequired import default, DeReConstructField2ast, IfThis, ShatteredDataclass
|
|
12
10
|
from mapFolding.someAssemblyRequired.makingModules_count import (
|
|
13
11
|
makeMapFoldingNumba, makeTheorem2, numbaOnTheorem2, trimTheorem2)
|
|
14
|
-
from mapFolding.someAssemblyRequired.makingModules_doTheNeedful import makeInitializeState
|
|
15
|
-
from mapFolding.someAssemblyRequired.toolkitMakeModules import
|
|
12
|
+
from mapFolding.someAssemblyRequired.makingModules_doTheNeedful import makeInitializeState
|
|
13
|
+
from mapFolding.someAssemblyRequired.toolkitMakeModules import getModule, getPathFilename
|
|
16
14
|
from mapFolding.someAssemblyRequired.toolkitNumba import decorateCallableWithNumba, parametersNumbaLight
|
|
17
15
|
from mapFolding.someAssemblyRequired.transformationTools import (
|
|
18
16
|
removeDataclassFromFunction, shatter_dataclassesDOTdataclass, unpackDataclassCallFunctionRepackDataclass)
|
|
19
|
-
from os import PathLike
|
|
20
17
|
from pathlib import PurePath
|
|
21
18
|
from typing import Any, TYPE_CHECKING
|
|
22
19
|
import ast
|
|
@@ -25,7 +22,7 @@ import dataclasses
|
|
|
25
22
|
if TYPE_CHECKING:
|
|
26
23
|
from collections.abc import Sequence
|
|
27
24
|
|
|
28
|
-
def makeDaoOfMapFoldingParallelNumba(astModule: ast.Module,
|
|
25
|
+
def makeDaoOfMapFoldingParallelNumba(astModule: ast.Module, identifierModule: str, identifierCallable: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath: # noqa: ARG001
|
|
29
26
|
"""Generate parallel implementation with concurrent execution and task division.
|
|
30
27
|
|
|
31
28
|
Parameters
|
|
@@ -47,11 +44,11 @@ def makeDaoOfMapFoldingParallelNumba(astModule: ast.Module, moduleIdentifier: st
|
|
|
47
44
|
Filesystem path where the parallel module was written.
|
|
48
45
|
|
|
49
46
|
"""
|
|
50
|
-
sourceCallableIdentifier =
|
|
51
|
-
if
|
|
52
|
-
|
|
47
|
+
sourceCallableIdentifier = default['function']['counting']
|
|
48
|
+
if identifierCallable is None:
|
|
49
|
+
identifierCallable = sourceCallableIdentifier
|
|
53
50
|
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
54
|
-
ingredientsFunction.astFunctionDef.name =
|
|
51
|
+
ingredientsFunction.astFunctionDef.name = identifierCallable
|
|
55
52
|
|
|
56
53
|
dataclassName: ast.expr = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.annotation)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
57
54
|
dataclassIdentifier: str = raiseIfNone(NodeTourist(Be.Name, Then.extractIt(DOT.id)).captureLastMatch(dataclassName))
|
|
@@ -69,10 +66,10 @@ def makeDaoOfMapFoldingParallelNumba(astModule: ast.Module, moduleIdentifier: st
|
|
|
69
66
|
dataclassInstanceIdentifier: identifierDotAttribute = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
70
67
|
shatteredDataclass: ShatteredDataclass = shatter_dataclassesDOTdataclass(dataclassLogicalPathModule, dataclassIdentifier, dataclassInstanceIdentifier)
|
|
71
68
|
|
|
72
|
-
|
|
73
|
-
dataclassBaseFields: tuple[dataclasses.Field[Any], ...] = dataclasses.fields(importLogicalPath2Identifier(dataclassLogicalPathModule, dataclassIdentifier))
|
|
69
|
+
# START add the parallel state fields to the count function ------------------------------------------------
|
|
70
|
+
dataclassBaseFields: tuple[dataclasses.Field[Any], ...] = dataclasses.fields(importLogicalPath2Identifier(dataclassLogicalPathModule, dataclassIdentifier))
|
|
74
71
|
dataclassIdentifierParallel: identifierDotAttribute = 'Parallel' + dataclassIdentifier
|
|
75
|
-
dataclassFieldsParallel: tuple[dataclasses.Field[Any], ...] = dataclasses.fields(importLogicalPath2Identifier(dataclassLogicalPathModule, dataclassIdentifierParallel))
|
|
72
|
+
dataclassFieldsParallel: tuple[dataclasses.Field[Any], ...] = dataclasses.fields(importLogicalPath2Identifier(dataclassLogicalPathModule, dataclassIdentifierParallel))
|
|
76
73
|
onlyParallelFields: list[dataclasses.Field[Any]] = [field for field in dataclassFieldsParallel if field.name not in [fieldBase.name for fieldBase in dataclassBaseFields]]
|
|
77
74
|
|
|
78
75
|
Official_fieldOrder: list[str] = []
|
|
@@ -108,12 +105,12 @@ def makeDaoOfMapFoldingParallelNumba(astModule: ast.Module, moduleIdentifier: st
|
|
|
108
105
|
shatteredDataclassParallel.imports.update(shatteredDataclass.imports)
|
|
109
106
|
shatteredDataclassParallel.imports.removeImportFrom(dataclassLogicalPathModule, dataclassIdentifier)
|
|
110
107
|
|
|
111
|
-
|
|
108
|
+
# END add the parallel state fields to the count function ------------------------------------------------
|
|
112
109
|
|
|
113
110
|
ingredientsFunction.imports.update(shatteredDataclassParallel.imports)
|
|
114
111
|
ingredientsFunction: IngredientsFunction = removeDataclassFromFunction(ingredientsFunction, shatteredDataclassParallel)
|
|
115
112
|
|
|
116
|
-
|
|
113
|
+
# START add the parallel logic to the count function ------------------------------------------------
|
|
117
114
|
|
|
118
115
|
findThis = Be.While.testIs(Be.Compare.leftIs(IfThis.isNameIdentifier('leafConnectee')))
|
|
119
116
|
captureCountGapsCodeBlock: NodeTourist[ast.While, Sequence[ast.stmt]] = NodeTourist(findThis, doThat = Then.extractIt(DOT.body))
|
|
@@ -127,20 +124,20 @@ def makeDaoOfMapFoldingParallelNumba(astModule: ast.Module, moduleIdentifier: st
|
|
|
127
124
|
countGapsCodeBlockNew: list[ast.stmt] = [thisIsMyTaskIndexCodeBlock, countGapsCodeBlock[-1]]
|
|
128
125
|
NodeChanger[ast.While, hasDOTbody](findThis, doThat = Grab.bodyAttribute(Then.replaceWith(countGapsCodeBlockNew))).visit(ingredientsFunction.astFunctionDef)
|
|
129
126
|
|
|
130
|
-
|
|
127
|
+
# END add the parallel logic to the count function ------------------------------------------------
|
|
131
128
|
|
|
132
129
|
ingredientsFunction = removeUnusedParameters(ingredientsFunction)
|
|
133
130
|
|
|
134
131
|
ingredientsFunction = decorateCallableWithNumba(ingredientsFunction, parametersNumbaLight)
|
|
135
132
|
|
|
136
|
-
|
|
137
|
-
sourceCallableIdentifier =
|
|
133
|
+
# START unpack/repack the dataclass function ------------------------------------------------
|
|
134
|
+
sourceCallableIdentifier = default['function']['dispatcher']
|
|
138
135
|
|
|
139
136
|
unRepackDataclass: IngredientsFunction = astModuleToIngredientsFunction(astModule, sourceCallableIdentifier)
|
|
140
137
|
unRepackDataclass.astFunctionDef.name = 'unRepack' + dataclassIdentifierParallel
|
|
141
138
|
unRepackDataclass.imports.update(shatteredDataclassParallel.imports)
|
|
142
139
|
NodeChanger(
|
|
143
|
-
findThis = Be.arg.annotationIs(Be.Name.idIs(lambda thisAttribute: thisAttribute == dataclassIdentifier))
|
|
140
|
+
findThis = Be.arg.annotationIs(Be.Name.idIs(lambda thisAttribute: thisAttribute == dataclassIdentifier))
|
|
144
141
|
, doThat = Grab.annotationAttribute(Grab.idAttribute(Then.replaceWith(dataclassIdentifierParallel)))
|
|
145
142
|
).visit(unRepackDataclass.astFunctionDef)
|
|
146
143
|
unRepackDataclass.astFunctionDef.returns = Make.Name(dataclassIdentifierParallel)
|
|
@@ -187,7 +184,7 @@ def makeDaoOfMapFoldingParallelNumba(astModule: ast.Module, moduleIdentifier: st
|
|
|
187
184
|
)
|
|
188
185
|
ingredientsModule.removeImportFromModule('numpy')
|
|
189
186
|
|
|
190
|
-
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix,
|
|
187
|
+
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix, identifierModule)
|
|
191
188
|
|
|
192
189
|
write_astModule(ingredientsModule, pathFilename, packageSettings.identifierPackage)
|
|
193
190
|
|
|
@@ -196,25 +193,22 @@ def makeDaoOfMapFoldingParallelNumba(astModule: ast.Module, moduleIdentifier: st
|
|
|
196
193
|
def makeMapFoldingModules() -> None:
|
|
197
194
|
"""Make multidimensional map folding modules."""
|
|
198
195
|
astModule = getModule(logicalPathInfix='algorithms')
|
|
199
|
-
pathFilename: PurePath = makeMapFoldingNumba(astModule, 'daoOfMapFoldingNumba', None,
|
|
196
|
+
pathFilename: PurePath = makeMapFoldingNumba(astModule, 'daoOfMapFoldingNumba', None, default['logicalPath']['synthetic'], default['function']['dispatcher'])
|
|
200
197
|
|
|
201
198
|
astModule = getModule(logicalPathInfix='algorithms')
|
|
202
|
-
pathFilename = makeDaoOfMapFoldingParallelNumba(astModule, 'countParallelNumba', None,
|
|
199
|
+
pathFilename = makeDaoOfMapFoldingParallelNumba(astModule, 'countParallelNumba', None, default['logicalPath']['synthetic'], default['function']['dispatcher'])
|
|
203
200
|
|
|
204
201
|
astModule: ast.Module = getModule(logicalPathInfix='algorithms')
|
|
205
|
-
makeInitializeState(astModule, 'initializeState', '
|
|
202
|
+
makeInitializeState(astModule, default['module']['initializeState'], default['function']['initializeState'], default['logicalPath']['synthetic'])
|
|
206
203
|
|
|
207
204
|
astModule = getModule(logicalPathInfix='algorithms')
|
|
208
|
-
pathFilename = makeTheorem2(astModule, 'theorem2', None,
|
|
205
|
+
pathFilename = makeTheorem2(astModule, 'theorem2', None, default['logicalPath']['synthetic'], default['function']['dispatcher'])
|
|
209
206
|
|
|
210
207
|
astModule = parsePathFilename2astModule(pathFilename)
|
|
211
|
-
pathFilename = trimTheorem2(astModule, 'theorem2Trimmed', None,
|
|
208
|
+
pathFilename = trimTheorem2(astModule, 'theorem2Trimmed', None, default['logicalPath']['synthetic'], default['function']['dispatcher'])
|
|
212
209
|
|
|
213
210
|
astModule = parsePathFilename2astModule(pathFilename)
|
|
214
|
-
pathFilename = numbaOnTheorem2(astModule, 'theorem2Numba', None,
|
|
215
|
-
|
|
216
|
-
astImportFrom: ast.ImportFrom = Make.ImportFrom(getLogicalPath(packageSettings.identifierPackage, logicalPathInfixDEFAULT, 'theorem2Numba'), list_alias=[Make.alias(identifierCallableSourceDEFAULT)])
|
|
217
|
-
makeUnRePackDataclass(astImportFrom)
|
|
211
|
+
pathFilename = numbaOnTheorem2(astModule, 'theorem2Numba', None, default['logicalPath']['synthetic'], default['function']['dispatcher'])
|
|
218
212
|
|
|
219
213
|
if __name__ == '__main__':
|
|
220
214
|
makeMapFoldingModules()
|
|
@@ -3,8 +3,7 @@ from astToolkit import (
|
|
|
3
3
|
astModuleToIngredientsFunction, Be, Grab, identifierDotAttribute, Make, NodeChanger, NodeTourist, Then)
|
|
4
4
|
from hunterMakesPy import raiseIfNone
|
|
5
5
|
from mapFolding import packageSettings
|
|
6
|
-
from mapFolding.someAssemblyRequired import
|
|
7
|
-
identifierCallableSourceDEFAULT, identifierCallableSourceDispatcherDEFAULT, IfThis, logicalPathInfixDEFAULT)
|
|
6
|
+
from mapFolding.someAssemblyRequired import default, IfThis
|
|
8
7
|
from mapFolding.someAssemblyRequired.toolkitMakeModules import (
|
|
9
8
|
findDataclass, getModule, getPathFilename, write_astModule)
|
|
10
9
|
from pathlib import PurePath
|
|
@@ -12,14 +11,14 @@ import ast
|
|
|
12
11
|
|
|
13
12
|
identifierDataclassNumPyHARDCODED = 'MatrixMeandersNumPyState'
|
|
14
13
|
|
|
15
|
-
logicalPathInfixMeanders: str =
|
|
14
|
+
logicalPathInfixMeanders: str = default['logicalPath']['synthetic'] + '.meanders'
|
|
16
15
|
|
|
17
16
|
def makeCountBigInt(astModule: ast.Module, identifierModule: str, callableIdentifier: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
|
|
18
17
|
"""Make `countBigInt` module for meanders using `MatrixMeandersNumPyState` dataclass."""
|
|
19
18
|
identifierDataclassNumPy: str = identifierDataclassNumPyHARDCODED
|
|
20
19
|
_logicalPathDataclass, identifierDataclassOld, identifierDataclassInstance = findDataclass(astModuleToIngredientsFunction(astModule, raiseIfNone(sourceCallableDispatcher)))
|
|
21
20
|
|
|
22
|
-
NodeChanger(findThis=Be.FunctionDef.nameIs(IfThis.isIdentifier(
|
|
21
|
+
NodeChanger(findThis=Be.FunctionDef.nameIs(IfThis.isIdentifier(default['function']['counting']))
|
|
23
22
|
, doThat=Grab.nameAttribute(Then.replaceWith(raiseIfNone(callableIdentifier)))
|
|
24
23
|
).visit(astModule)
|
|
25
24
|
|
|
@@ -56,8 +55,11 @@ def makeCountBigInt(astModule: ast.Module, identifierModule: str, callableIdenti
|
|
|
56
55
|
|
|
57
56
|
return pathFilename
|
|
58
57
|
|
|
59
|
-
|
|
58
|
+
def makeMeandersModules() -> None:
|
|
59
|
+
"""Make meanders modules."""
|
|
60
60
|
astModule: ast.Module = getModule(logicalPathInfix='algorithms', identifierModule='matrixMeanders')
|
|
61
|
-
pathFilename: PurePath = makeCountBigInt(astModule, 'bigInt', 'countBigInt', logicalPathInfixMeanders,
|
|
61
|
+
pathFilename: PurePath = makeCountBigInt(astModule, 'bigInt', 'countBigInt', logicalPathInfixMeanders, default['function']['dispatcher'])
|
|
62
62
|
|
|
63
|
+
if __name__ == '__main__':
|
|
64
|
+
makeMeandersModules()
|
|
63
65
|
|
|
@@ -36,7 +36,7 @@ from astToolkit import (
|
|
|
36
36
|
from autoflake import fix_code as autoflake_fix_code
|
|
37
37
|
from hunterMakesPy import raiseIfNone, writeStringToHere
|
|
38
38
|
from mapFolding import packageSettings
|
|
39
|
-
from mapFolding.someAssemblyRequired import
|
|
39
|
+
from mapFolding.someAssemblyRequired import default
|
|
40
40
|
from os import PathLike
|
|
41
41
|
from pathlib import PurePath
|
|
42
42
|
from typing import Any
|
|
@@ -96,7 +96,7 @@ def getLogicalPath(identifierPackage: str | None = None, logicalPathInfix: ident
|
|
|
96
96
|
listLogicalPathParts.extend([module for module in identifierModule if module is not None])
|
|
97
97
|
return '.'.join(listLogicalPathParts)
|
|
98
98
|
|
|
99
|
-
def getModule(identifierPackage: str | None = packageSettings.identifierPackage, logicalPathInfix: identifierDotAttribute | None =
|
|
99
|
+
def getModule(identifierPackage: str | None = packageSettings.identifierPackage, logicalPathInfix: identifierDotAttribute | None = default['logicalPath']['synthetic'], identifierModule: str | None = default['module']['algorithm']) -> ast.Module:
|
|
100
100
|
"""Get Module."""
|
|
101
101
|
logicalPathSourceModule: identifierDotAttribute = getLogicalPath(identifierPackage, logicalPathInfix, identifierModule)
|
|
102
102
|
astModule: ast.Module = parseLogicalPath2astModule(logicalPathSourceModule)
|