mapFolding 0.16.2__py3-none-any.whl → 0.17.0__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/A000682.py +2 -2
- easyRun/NOTcountingFolds.py +16 -8
- easyRun/countFolds.py +9 -2
- easyRun/generateAllModules.py +14 -0
- easyRun/meanders.py +4 -4
- mapFolding/__init__.py +1 -0
- mapFolding/_theSSOT.py +3 -2
- mapFolding/_theTypes.py +3 -0
- mapFolding/algorithms/A000136constraintPropagation.py +95 -0
- mapFolding/algorithms/A000136elimination.py +163 -0
- mapFolding/algorithms/A000136eliminationParallel.py +77 -0
- mapFolding/algorithms/A086345.py +75 -0
- mapFolding/algorithms/matrixMeanders.py +59 -18
- mapFolding/algorithms/matrixMeandersNumPyndas.py +841 -0
- mapFolding/algorithms/oeisIDbyFormula.py +2 -2
- mapFolding/algorithms/symmetricFolds.py +35 -0
- mapFolding/basecamp.py +100 -153
- mapFolding/dataBaskets.py +142 -65
- mapFolding/filesystemToolkit.py +4 -32
- mapFolding/oeis.py +5 -12
- mapFolding/reference/A086345Wu.py +25 -0
- mapFolding/reference/irvineJavaPort.py +3 -3
- mapFolding/reference/matrixMeandersAnalysis/signatures.py +3 -0
- mapFolding/reference/meandersDumpingGround/matrixMeandersNumPyV1finalForm.py +1 -1
- mapFolding/someAssemblyRequired/A007822/A007822rawMaterials.py +10 -45
- mapFolding/someAssemblyRequired/A007822/_asynchronousAnnex.py +51 -0
- mapFolding/someAssemblyRequired/A007822/makeA007822AsynchronousModules.py +39 -196
- mapFolding/someAssemblyRequired/A007822/makeA007822Modules.py +57 -43
- mapFolding/someAssemblyRequired/RecipeJob.py +84 -34
- mapFolding/someAssemblyRequired/__init__.py +4 -8
- mapFolding/someAssemblyRequired/_toolkitContainers.py +38 -7
- mapFolding/someAssemblyRequired/infoBooth.py +41 -23
- mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +140 -164
- mapFolding/someAssemblyRequired/makeJobTheorem2codon.py +63 -96
- mapFolding/someAssemblyRequired/makingModules_count.py +26 -30
- mapFolding/someAssemblyRequired/makingModules_doTheNeedful.py +10 -72
- mapFolding/someAssemblyRequired/{mapFolding → mapFoldingModules}/makeMapFoldingModules.py +30 -35
- mapFolding/someAssemblyRequired/meanders/makeMeandersModules.py +13 -11
- mapFolding/someAssemblyRequired/toolkitMakeModules.py +5 -31
- mapFolding/someAssemblyRequired/toolkitNumba.py +3 -2
- mapFolding/someAssemblyRequired/transformationTools.py +12 -15
- mapFolding/syntheticModules/A007822/algorithm.py +45 -50
- mapFolding/syntheticModules/A007822/asynchronous.py +92 -36
- mapFolding/syntheticModules/A007822/initializeState.py +19 -23
- mapFolding/syntheticModules/A007822/theorem2.py +20 -24
- mapFolding/syntheticModules/A007822/theorem2Numba.py +23 -25
- mapFolding/syntheticModules/A007822/theorem2Trimmed.py +19 -23
- mapFolding/syntheticModules/countParallelNumba.py +1 -2
- mapFolding/syntheticModules/daoOfMapFoldingNumba.py +5 -4
- mapFolding/syntheticModules/initializeState.py +1 -1
- mapFolding/syntheticModules/meanders/bigInt.py +59 -22
- mapFolding/syntheticModules/theorem2.py +1 -1
- mapFolding/syntheticModules/theorem2Numba.py +30 -9
- mapFolding/syntheticModules/theorem2Trimmed.py +2 -2
- mapFolding/tests/test_computations.py +29 -3
- {mapfolding-0.16.2.dist-info → mapfolding-0.17.0.dist-info}/METADATA +11 -8
- mapfolding-0.17.0.dist-info/RECORD +107 -0
- mapFolding/_dataPacking.py +0 -68
- mapFolding/algorithms/matrixMeandersBeDry.py +0 -182
- mapFolding/algorithms/matrixMeandersNumPy.py +0 -333
- mapFolding/algorithms/matrixMeandersPandas.py +0 -334
- 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-0.16.2.dist-info/RECORD +0 -115
- /mapFolding/someAssemblyRequired/{mapFolding → mapFoldingModules}/__init__.py +0 -0
- {mapfolding-0.16.2.dist-info → mapfolding-0.17.0.dist-info}/WHEEL +0 -0
- {mapfolding-0.16.2.dist-info → mapfolding-0.17.0.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.16.2.dist-info → mapfolding-0.17.0.dist-info}/licenses/LICENSE +0 -0
- {mapfolding-0.16.2.dist-info → mapfolding-0.17.0.dist-info}/top_level.txt +0 -0
|
@@ -1,36 +1,25 @@
|
|
|
1
1
|
"""addSymmetryCheckAsynchronous."""
|
|
2
|
-
from astToolkit import
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
from astToolkit import Be, Grab, identifierDotAttribute, Make, NodeChanger, NodeTourist, Then
|
|
3
|
+
from astToolkit.containers import LedgerOfImports
|
|
4
|
+
from astToolkit.transformationTools import write_astModule
|
|
5
5
|
from hunterMakesPy import raiseIfNone
|
|
6
6
|
from mapFolding import packageSettings
|
|
7
|
-
from mapFolding.someAssemblyRequired import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
from mapFolding.someAssemblyRequired.A007822.A007822rawMaterials import (
|
|
11
|
-
A007822adjustFoldsTotal, astExprCall_filterAsymmetricFoldsDataclass, identifier_filterAsymmetricFolds,
|
|
12
|
-
identifierCounting, identifierDataclass, logicalPathInfixA007822, sourceCallableDispatcherA007822,
|
|
13
|
-
sourceCallableIdentifierA007822)
|
|
14
|
-
from mapFolding.someAssemblyRequired.infoBooth import identifierCallableSourceDEFAULT
|
|
15
|
-
from mapFolding.someAssemblyRequired.makingModules_count import makeTheorem2, numbaOnTheorem2, trimTheorem2
|
|
16
|
-
from mapFolding.someAssemblyRequired.toolkitMakeModules import (
|
|
17
|
-
getLogicalPath, getModule, getPathFilename, write_astModule)
|
|
7
|
+
from mapFolding.someAssemblyRequired import defaultA007822, IfThis
|
|
8
|
+
from mapFolding.someAssemblyRequired.A007822.A007822rawMaterials import ExprCallFilterAsymmetricFoldsState
|
|
9
|
+
from mapFolding.someAssemblyRequired.toolkitMakeModules import getModule, getPathFilename
|
|
18
10
|
from pathlib import PurePath
|
|
19
11
|
import ast
|
|
20
12
|
|
|
21
|
-
|
|
22
|
-
identifier_getSymmetricFoldsTotal = 'getSymmetricFoldsTotal'
|
|
23
|
-
identifier_initializeConcurrencyManager = 'initializeConcurrencyManager'
|
|
24
|
-
identifier_processCompletedFutures = '_processCompletedFutures'
|
|
13
|
+
# TODO figure out asynchronous + numba.
|
|
25
14
|
|
|
26
|
-
astExprCall_initializeConcurrencyManager: ast.Expr = Make.Expr(Make.Call(Make.Name(
|
|
15
|
+
astExprCall_initializeConcurrencyManager: ast.Expr = Make.Expr(Make.Call(Make.Name(defaultA007822['function']['initializeConcurrencyManager']), listParameters=[Make.Name('maxWorkers')]))
|
|
27
16
|
AssignTotal2CountingIdentifier: ast.Assign = Make.Assign(
|
|
28
|
-
[Make.Attribute(Make.Name(
|
|
29
|
-
, value=Make.Call(Make.Name(
|
|
17
|
+
[Make.Attribute(Make.Name(defaultA007822['variable']['stateInstance']), defaultA007822['variable']['counting'], context=Make.Store())]
|
|
18
|
+
, value=Make.Call(Make.Name(defaultA007822['function']['getSymmetricFoldsTotal']))
|
|
30
19
|
)
|
|
31
20
|
|
|
32
21
|
def addSymmetryCheckAsynchronous(astModule: ast.Module, identifierModule: str, identifierCallable: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath: # noqa: ARG001
|
|
33
|
-
"""
|
|
22
|
+
"""Make the check for symmetry in each folding pattern in a group of folds asynchronous to the rest of the symmetric map folding algorithm.
|
|
34
23
|
|
|
35
24
|
To do asynchronous filtering, a few things must happen.
|
|
36
25
|
1. When the algorithm finds a `groupOfFolds`, the call to `filterAsymmetricFolds` must be non-blocking.
|
|
@@ -45,16 +34,13 @@ def addSymmetryCheckAsynchronous(astModule: ast.Module, identifierModule: str, i
|
|
|
45
34
|
Each `leafBelow` array will be 28 * 8-bits, so if the queue has only 0.3% of the total calls in it, that is 28 GiB of data.
|
|
46
35
|
"""
|
|
47
36
|
astFunctionDef_count: ast.FunctionDef = raiseIfNone(NodeTourist(
|
|
48
|
-
findThis = Be.FunctionDef.nameIs(IfThis.isIdentifier(
|
|
37
|
+
findThis = Be.FunctionDef.nameIs(IfThis.isIdentifier(defaultA007822['function']['counting']))
|
|
49
38
|
, doThat = Then.extractIt
|
|
50
39
|
).captureLastMatch(astModule))
|
|
51
40
|
|
|
52
|
-
NodeChanger(Be.Return, Then.insertThisAbove([A007822adjustFoldsTotal])).visit(astFunctionDef_count)
|
|
53
|
-
|
|
54
41
|
NodeChanger(
|
|
55
|
-
|
|
56
|
-
,
|
|
57
|
-
).visit(astFunctionDef_count)
|
|
42
|
+
Be.Assign.valueIs(IfThis.isCallIdentifier(defaultA007822['function']['filterAsymmetricFolds']))
|
|
43
|
+
, Then.replaceWith(ExprCallFilterAsymmetricFoldsState)).visit(astFunctionDef_count)
|
|
58
44
|
|
|
59
45
|
NodeChanger(
|
|
60
46
|
findThis=Be.While.testIs(IfThis.isCallIdentifier('activeLeafGreaterThan0'))
|
|
@@ -62,9 +48,10 @@ def addSymmetryCheckAsynchronous(astModule: ast.Module, identifierModule: str, i
|
|
|
62
48
|
).visit(astFunctionDef_count)
|
|
63
49
|
|
|
64
50
|
NodeChanger(
|
|
65
|
-
findThis=Be.FunctionDef.nameIs(IfThis.isIdentifier(
|
|
51
|
+
findThis=Be.FunctionDef.nameIs(IfThis.isIdentifier(defaultA007822['function']['counting']))
|
|
66
52
|
, doThat=Then.replaceWith(astFunctionDef_count)
|
|
67
53
|
).visit(astModule)
|
|
54
|
+
del astFunctionDef_count
|
|
68
55
|
|
|
69
56
|
astFunctionDef_doTheNeedful: ast.FunctionDef = raiseIfNone(NodeTourist(
|
|
70
57
|
findThis = Be.FunctionDef.nameIs(IfThis.isIdentifier(sourceCallableDispatcher))
|
|
@@ -72,188 +59,44 @@ def addSymmetryCheckAsynchronous(astModule: ast.Module, identifierModule: str, i
|
|
|
72
59
|
).captureLastMatch(astModule))
|
|
73
60
|
|
|
74
61
|
astFunctionDef_doTheNeedful.body.insert(0, astExprCall_initializeConcurrencyManager)
|
|
75
|
-
astFunctionDef_doTheNeedful.args.args.append(Make.arg('maxWorkers', Make.
|
|
76
|
-
astFunctionDef_doTheNeedful.args.defaults.append(Make.Constant(None))
|
|
62
|
+
astFunctionDef_doTheNeedful.args.args.append(Make.arg('maxWorkers', Make.Name('int')))
|
|
77
63
|
|
|
78
64
|
NodeChanger(
|
|
79
65
|
findThis=Be.FunctionDef.nameIs(IfThis.isIdentifier(sourceCallableDispatcher))
|
|
80
66
|
, doThat=Then.replaceWith(astFunctionDef_doTheNeedful)
|
|
81
67
|
).visit(astModule)
|
|
68
|
+
del astFunctionDef_doTheNeedful
|
|
82
69
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
astModule.body.insert(0, astImportFrom)
|
|
87
|
-
|
|
88
|
-
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix, identifierModule)
|
|
89
|
-
pathFilenameAnnex: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix, identifierModule + 'Annex')
|
|
90
|
-
|
|
91
|
-
write_astModule(astModule, pathFilename, packageSettings.identifierPackage)
|
|
92
|
-
del astModule
|
|
93
|
-
# ----------------- Ingredients Module Annex ------------------------------------------------------------------------------
|
|
94
|
-
ImaString = """from concurrent.futures import Future as ConcurrentFuture, ThreadPoolExecutor
|
|
95
|
-
from hunterMakesPy import raiseIfNone
|
|
96
|
-
from mapFolding import Array1DLeavesTotal
|
|
97
|
-
from queue import Empty, Queue
|
|
98
|
-
from threading import Thread
|
|
99
|
-
import numpy"""
|
|
100
|
-
|
|
101
|
-
astModule = ast.parse(ImaString)
|
|
102
|
-
del ImaString
|
|
103
|
-
|
|
104
|
-
ImaString = f"""concurrencyManager = None
|
|
105
|
-
{identifierCounting}Total: int = 0
|
|
106
|
-
processingThread = None
|
|
107
|
-
queueFutures: Queue[ConcurrentFuture[int]] = Queue()
|
|
108
|
-
"""
|
|
109
|
-
astModule.body.extend(ast.parse(ImaString).body)
|
|
110
|
-
del ImaString
|
|
111
|
-
|
|
112
|
-
ImaString = f"""def {identifier_initializeConcurrencyManager}(maxWorkers: int | None = None, {identifierCounting}: int = 0) -> None:
|
|
113
|
-
global concurrencyManager, queueFutures, {identifierCounting}Total, processingThread
|
|
114
|
-
concurrencyManager = ThreadPoolExecutor(max_workers=maxWorkers)
|
|
115
|
-
queueFutures = Queue()
|
|
116
|
-
{identifierCounting}Total = {identifierCounting}
|
|
117
|
-
processingThread = Thread(target={identifier_processCompletedFutures})
|
|
118
|
-
processingThread.start()
|
|
119
|
-
"""
|
|
120
|
-
astModule.body.append(raiseIfNone(extractFunctionDef(ast.parse(ImaString), identifier_initializeConcurrencyManager)))
|
|
121
|
-
del ImaString
|
|
122
|
-
|
|
123
|
-
ImaString = f"""def {identifier_processCompletedFutures}() -> None:
|
|
124
|
-
global queueFutures, {identifierCounting}Total
|
|
125
|
-
while True:
|
|
126
|
-
try:
|
|
127
|
-
claimTicket: ConcurrentFuture[int] = queueFutures.get(timeout=1)
|
|
128
|
-
if claimTicket is None:
|
|
129
|
-
break
|
|
130
|
-
{identifierCounting}Total += claimTicket.result()
|
|
131
|
-
except Empty:
|
|
132
|
-
continue
|
|
133
|
-
"""
|
|
134
|
-
astModule.body.append(raiseIfNone(extractFunctionDef(ast.parse(ImaString), identifier_processCompletedFutures)))
|
|
135
|
-
del ImaString
|
|
136
|
-
|
|
137
|
-
ImaString = f"""def _{identifier_filterAsymmetricFolds}(leafBelow: Array1DLeavesTotal) -> int:
|
|
138
|
-
{identifierCounting} = 0
|
|
139
|
-
leafComparison: Array1DLeavesTotal = numpy.zeros_like(leafBelow)
|
|
140
|
-
leavesTotal = leafBelow.size - 1
|
|
141
|
-
|
|
142
|
-
indexLeaf = 0
|
|
143
|
-
leafConnectee = 0
|
|
144
|
-
while leafConnectee < leavesTotal + 1:
|
|
145
|
-
leafNumber = int(leafBelow[indexLeaf])
|
|
146
|
-
leafComparison[leafConnectee] = (leafNumber - indexLeaf + leavesTotal) % leavesTotal
|
|
147
|
-
indexLeaf = leafNumber
|
|
148
|
-
leafConnectee += 1
|
|
149
|
-
|
|
150
|
-
indexInMiddle = leavesTotal // 2
|
|
151
|
-
indexDistance = 0
|
|
152
|
-
while indexDistance < leavesTotal + 1:
|
|
153
|
-
ImaSymmetricFold = True
|
|
154
|
-
leafConnectee = 0
|
|
155
|
-
while leafConnectee < indexInMiddle:
|
|
156
|
-
if leafComparison[(indexDistance + leafConnectee) % (leavesTotal + 1)] != leafComparison[(indexDistance + leavesTotal - 1 - leafConnectee) % (leavesTotal + 1)]:
|
|
157
|
-
ImaSymmetricFold = False
|
|
158
|
-
break
|
|
159
|
-
leafConnectee += 1
|
|
160
|
-
{identifierCounting} += ImaSymmetricFold
|
|
161
|
-
indexDistance += 1
|
|
162
|
-
return {identifierCounting}
|
|
163
|
-
"""
|
|
164
|
-
astModule.body.append(raiseIfNone(extractFunctionDef(ast.parse(ImaString), f'_{identifier_filterAsymmetricFolds}')))
|
|
165
|
-
del ImaString
|
|
70
|
+
imports = LedgerOfImports(astModule)
|
|
71
|
+
removeImports = NodeChanger(IfThis.isAnyOf(Be.ImportFrom, Be.Import), Then.removeIt)
|
|
72
|
+
removeImports.visit(astModule)
|
|
166
73
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
queueFutures.put_nowait(raiseIfNone(concurrencyManager).submit(_{identifier_filterAsymmetricFolds}, leafBelow.copy()))
|
|
171
|
-
"""
|
|
172
|
-
astModule.body.append(raiseIfNone(extractFunctionDef(ast.parse(ImaString), identifier_filterAsymmetricFolds)))
|
|
173
|
-
del ImaString
|
|
174
|
-
|
|
175
|
-
ImaString = f"""
|
|
176
|
-
def {identifier_getSymmetricFoldsTotal}() -> int:
|
|
177
|
-
global concurrencyManager, queueFutures, processingThread
|
|
178
|
-
raiseIfNone(concurrencyManager).shutdown(wait=True)
|
|
179
|
-
queueFutures.put(None)
|
|
180
|
-
raiseIfNone(processingThread).join()
|
|
181
|
-
return {identifierCounting}Total
|
|
182
|
-
"""
|
|
183
|
-
astModule.body.append(raiseIfNone(extractFunctionDef(ast.parse(ImaString), identifier_getSymmetricFoldsTotal)))
|
|
184
|
-
del ImaString
|
|
185
|
-
write_astModule(astModule, pathFilenameAnnex, packageSettings.identifierPackage)
|
|
186
|
-
|
|
187
|
-
return pathFilename
|
|
74
|
+
astModuleAsynchronousAnnex: ast.Module = getModule(logicalPathInfix=defaultA007822['logicalPath']['assembly'], identifierModule='_asynchronousAnnex')
|
|
75
|
+
imports.walkThis(astModuleAsynchronousAnnex)
|
|
76
|
+
removeImports.visit(astModuleAsynchronousAnnex)
|
|
188
77
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
astModule = parsePathFilename2astModule(pathFilename)
|
|
194
|
-
|
|
195
|
-
listAssignToMove: list[ast.Assign] = []
|
|
196
|
-
|
|
197
|
-
findThis = IfThis.isAnyOf(IfThis.isAssignAndTargets0Is(IfThis.isNameIdentifier(identifierCountingDEFAULT))
|
|
198
|
-
, Be.AugAssign.targetIs(IfThis.isNameIdentifier(identifierCountingDEFAULT)))
|
|
199
|
-
NodeTourist(findThis, Then.appendTo(listAssignToMove)).visit(astModule)
|
|
200
|
-
|
|
201
|
-
NodeChanger(findThis, Then.removeIt).visit(astModule)
|
|
202
|
-
|
|
203
|
-
NodeChanger(
|
|
204
|
-
findThis=Be.Assign.valueIs(IfThis.isCallIdentifier(identifierCallableSourceDEFAULT))
|
|
205
|
-
, doThat=Then.insertThisBelow(listAssignToMove)
|
|
206
|
-
).visit(astModule)
|
|
207
|
-
|
|
208
|
-
write_astModule(astModule, pathFilename, packageSettings.identifierPackage)
|
|
209
|
-
|
|
210
|
-
return pathFilename
|
|
211
|
-
|
|
212
|
-
def makeAsynchronousTheorem2(astModule: ast.Module, identifierModule: str, identifierCallable: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
|
|
213
|
-
"""Make the asynchronous theorem2 module."""
|
|
214
|
-
pathFilename: PurePath = makeTheorem2(astModule, identifierModule, identifierCallable, logicalPathInfix, sourceCallableDispatcher)
|
|
215
|
-
|
|
216
|
-
astModule = parsePathFilename2astModule(pathFilename)
|
|
217
|
-
|
|
218
|
-
astAttribute = Make.Attribute(Make.Name(identifierDataclassInstanceDEFAULT), identifierCountingDEFAULT)
|
|
219
|
-
astAssign = Make.Assign([astAttribute], value=Make.Constant(0))
|
|
78
|
+
NodeChanger(Be.FunctionDef.nameIs(IfThis.isIdentifier(defaultA007822['function']['filterAsymmetricFolds']))
|
|
79
|
+
, Grab.nameAttribute(Then.replaceWith(f"_{defaultA007822['function']['filterAsymmetricFolds']}"))
|
|
80
|
+
).visit(astModule)
|
|
220
81
|
|
|
221
|
-
NodeChanger
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
).visit(astModule)
|
|
82
|
+
NodeChanger(Be.FunctionDef.nameIs(IfThis.isIdentifier(f"_{defaultA007822['function']['filterAsymmetricFolds']}"))
|
|
83
|
+
, Then.removeIt
|
|
84
|
+
).visit(astModuleAsynchronousAnnex)
|
|
225
85
|
|
|
226
|
-
|
|
227
|
-
findThis = Be.Expr.valueIs(IfThis.isCallIdentifier(identifier_initializeConcurrencyManager))
|
|
228
|
-
, doThat = Then.insertThisBelow([astAssign])
|
|
229
|
-
).visit(astModule)
|
|
86
|
+
astModule.body = [*imports.makeList_ast(), *astModuleAsynchronousAnnex.body, *astModule.body]
|
|
230
87
|
|
|
231
|
-
|
|
232
|
-
identifierAnnexNumba: identifierDotAttribute = identifierAnnex + 'Numba'
|
|
233
|
-
|
|
234
|
-
NodeChanger(
|
|
235
|
-
findThis=Be.ImportFrom.moduleIs(IfThis.isIdentifier(identifierAnnex))
|
|
236
|
-
, doThat=Grab.moduleAttribute(Then.replaceWith(identifierAnnexNumba))
|
|
237
|
-
).visit(astModule)
|
|
88
|
+
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix, identifierModule)
|
|
238
89
|
|
|
239
|
-
write_astModule(astModule, pathFilename, packageSettings.identifierPackage)
|
|
90
|
+
write_astModule(astModule, pathFilename, identifierPackage=packageSettings.identifierPackage)
|
|
240
91
|
|
|
241
92
|
return pathFilename
|
|
242
93
|
|
|
243
|
-
def
|
|
244
|
-
|
|
245
|
-
astModule: ast.Module = getModule(logicalPathInfix=
|
|
246
|
-
pathFilename: PurePath = addSymmetryCheckAsynchronous(astModule, 'asynchronous',
|
|
247
|
-
|
|
248
|
-
astModule = getModule(logicalPathInfix=logicalPathInfixA007822, identifierModule='asynchronous')
|
|
249
|
-
pathFilename = makeAsynchronousTheorem2(astModule, 'asynchronousTheorem2', None, logicalPathInfixA007822, identifierCallableSourceDispatcherDEFAULT)
|
|
250
|
-
|
|
251
|
-
astModule = parsePathFilename2astModule(pathFilename)
|
|
252
|
-
pathFilename = trimTheorem2(astModule, 'asynchronousTrimmed', None, logicalPathInfixA007822, identifierCallableSourceDispatcherDEFAULT)
|
|
253
|
-
|
|
254
|
-
astModule = parsePathFilename2astModule(pathFilename)
|
|
255
|
-
pathFilename = makeAsynchronousNumbaOnTheorem2(astModule, 'asynchronousNumba', None, logicalPathInfixA007822, identifierCallableSourceDispatcherDEFAULT)
|
|
94
|
+
def makeA007822AsynchronousModules() -> None:
|
|
95
|
+
"""Make asynchronous modules for A007822."""
|
|
96
|
+
astModule: ast.Module = getModule(logicalPathInfix=defaultA007822['logicalPath']['synthetic'], identifierModule=defaultA007822['module']['algorithm'])
|
|
97
|
+
pathFilename: PurePath = addSymmetryCheckAsynchronous(astModule, defaultA007822['module']['asynchronous'], defaultA007822['function']['counting'] # noqa: F841 # pyright: ignore[reportUnusedVariable]
|
|
98
|
+
, defaultA007822['logicalPath']['synthetic'], defaultA007822['function']['dispatcher'])
|
|
256
99
|
|
|
257
100
|
if __name__ == '__main__':
|
|
258
|
-
|
|
101
|
+
makeA007822AsynchronousModules()
|
|
259
102
|
|
|
@@ -1,75 +1,89 @@
|
|
|
1
1
|
"""addSymmetryCheck."""
|
|
2
|
-
from astToolkit import
|
|
2
|
+
from astToolkit import (
|
|
3
|
+
Be, Grab, identifierDotAttribute, Make, NodeChanger, NodeTourist, parsePathFilename2astModule, Then)
|
|
4
|
+
from astToolkit.containers import LedgerOfImports
|
|
5
|
+
from astToolkit.transformationTools import write_astModule
|
|
3
6
|
from hunterMakesPy import raiseIfNone
|
|
4
7
|
from mapFolding import packageSettings
|
|
5
|
-
from mapFolding.someAssemblyRequired import
|
|
6
|
-
identifierCallableSourceDEFAULT, identifierCallableSourceDispatcherDEFAULT, identifierCountingDEFAULT,
|
|
7
|
-
identifierDataclassInstanceDEFAULT, IfThis)
|
|
8
|
+
from mapFolding.someAssemblyRequired import default, defaultA007822, IfThis
|
|
8
9
|
from mapFolding.someAssemblyRequired.A007822.A007822rawMaterials import (
|
|
9
|
-
A007822adjustFoldsTotal, A007822incrementCount, FunctionDef_filterAsymmetricFolds
|
|
10
|
-
|
|
11
|
-
from mapFolding.someAssemblyRequired.
|
|
12
|
-
|
|
13
|
-
from mapFolding.someAssemblyRequired.makingModules_doTheNeedful import makeInitializeState, makeUnRePackDataclass
|
|
14
|
-
from mapFolding.someAssemblyRequired.toolkitMakeModules import (
|
|
15
|
-
getLogicalPath, getModule, getPathFilename, write_astModule)
|
|
16
|
-
from os import PathLike
|
|
10
|
+
A007822adjustFoldsTotal, A007822incrementCount, FunctionDef_filterAsymmetricFolds)
|
|
11
|
+
from mapFolding.someAssemblyRequired.makingModules_count import makeTheorem2, numbaOnTheorem2, trimTheorem2
|
|
12
|
+
from mapFolding.someAssemblyRequired.makingModules_doTheNeedful import makeInitializeState
|
|
13
|
+
from mapFolding.someAssemblyRequired.toolkitMakeModules import getModule, getPathFilename
|
|
17
14
|
from pathlib import PurePath
|
|
18
15
|
import ast
|
|
19
16
|
|
|
20
17
|
def addSymmetryCheck(astModule: ast.Module, identifierModule: str, identifierCallable: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath: # noqa: ARG001
|
|
21
|
-
"""
|
|
22
|
-
|
|
18
|
+
"""Modify the multidimensional map folding algorithm by checking for symmetry in each folding pattern in a group of folds."""
|
|
19
|
+
NodeChanger(Be.Name.idIs(IfThis.isIdentifier(default['variable']['stateDataclass']))
|
|
20
|
+
, Grab.idAttribute(Then.replaceWith(defaultA007822['variable']['stateDataclass']))
|
|
21
|
+
).visit(astModule)
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
NodeChanger(Be.alias.nameIs(IfThis.isIdentifier(default['variable']['stateDataclass']))
|
|
24
|
+
, Grab.nameAttribute(Then.replaceWith(defaultA007822['variable']['stateDataclass']))
|
|
25
|
+
).visit(astModule)
|
|
26
|
+
|
|
27
|
+
FunctionDef_count: ast.FunctionDef = raiseIfNone(NodeTourist(
|
|
28
|
+
findThis = Be.FunctionDef.nameIs(IfThis.isIdentifier(default['function']['counting']))
|
|
26
29
|
, doThat = Then.extractIt
|
|
27
30
|
).captureLastMatch(astModule))
|
|
28
|
-
|
|
31
|
+
FunctionDef_count.name = identifierCallable or defaultA007822['function']['counting']
|
|
29
32
|
|
|
30
|
-
NodeChanger(Be.Return, Then.insertThisAbove([A007822adjustFoldsTotal])).visit(
|
|
33
|
+
NodeChanger(Be.Return, Then.insertThisAbove([A007822adjustFoldsTotal])).visit(FunctionDef_count)
|
|
31
34
|
|
|
32
35
|
NodeChanger(
|
|
33
|
-
findThis=Be.AugAssign.targetIs(IfThis.isAttributeNamespaceIdentifier(
|
|
36
|
+
findThis=Be.AugAssign.targetIs(IfThis.isAttributeNamespaceIdentifier(default['variable']['stateInstance'], default['variable']['counting']))
|
|
34
37
|
, doThat=Then.replaceWith(A007822incrementCount)
|
|
35
|
-
).visit(
|
|
38
|
+
).visit(FunctionDef_count)
|
|
39
|
+
|
|
40
|
+
imports = LedgerOfImports(astModule)
|
|
41
|
+
NodeChanger(IfThis.isAnyOf(Be.ImportFrom, Be.Import), Then.removeIt).visit(astModule)
|
|
42
|
+
imports.addImport_asStr('numpy')
|
|
36
43
|
|
|
37
|
-
|
|
38
|
-
# system to replace the `Ingredients` paradigm.
|
|
39
|
-
NodeChanger(Be.ImportFrom, Then.insertThisBelow([FunctionDef_filterAsymmetricFolds])).visit(astModule)
|
|
44
|
+
astModule.body = [*imports.makeList_ast(), FunctionDef_filterAsymmetricFolds, *astModule.body]
|
|
40
45
|
|
|
41
46
|
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix, identifierModule)
|
|
42
47
|
|
|
43
|
-
write_astModule(astModule, pathFilename, packageSettings.identifierPackage)
|
|
48
|
+
write_astModule(astModule, pathFilename, identifierPackage=packageSettings.identifierPackage)
|
|
44
49
|
|
|
45
50
|
return pathFilename
|
|
46
51
|
|
|
47
|
-
def
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
def _numbaOnTheorem2(astModule: ast.Module, identifierModule: str, identifierCallable: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
|
|
53
|
+
pathFilename: PurePath = numbaOnTheorem2(astModule, identifierModule, identifierCallable, logicalPathInfix, sourceCallableDispatcher)
|
|
54
|
+
astModule = parsePathFilename2astModule(pathFilename)
|
|
55
|
+
|
|
56
|
+
NodeChanger(Be.AnnAssign.valueIs(IfThis.isAttributeNamespaceIdentifier(defaultA007822['variable']['stateInstance'], 'indices'))
|
|
57
|
+
, lambda node: Grab.valueAttribute(Then.replaceWith(Make.Call(Make.Name('List'), [raiseIfNone(node.value)])))(node)
|
|
58
|
+
).visit(astModule)
|
|
50
59
|
|
|
51
|
-
astModule
|
|
52
|
-
pathFilename: PurePath = makeMapFoldingNumba(astModule, 'algorithmNumba', None, logicalPathInfixA007822, sourceCallableDispatcherA007822)
|
|
60
|
+
astModule.body.insert(0, Make.ImportFrom('numba.typed', [Make.alias('List')]))
|
|
53
61
|
|
|
54
|
-
|
|
62
|
+
write_astModule(astModule, pathFilename, identifierPackage=packageSettings.identifierPackage)
|
|
55
63
|
|
|
56
|
-
|
|
57
|
-
makeInitializeState(astModule, 'initializeState', 'transitionOnGroupsOfFolds', logicalPathInfixA007822)
|
|
64
|
+
return pathFilename
|
|
58
65
|
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
def makeA007822Modules() -> None:
|
|
67
|
+
"""Make."""
|
|
68
|
+
astModule: ast.Module = getModule(logicalPathInfix='algorithms')
|
|
69
|
+
pathFilename: PurePath = addSymmetryCheck(astModule, defaultA007822['module']['algorithm'], defaultA007822['function']['counting']
|
|
70
|
+
, defaultA007822['logicalPath']['synthetic'], None)
|
|
61
71
|
|
|
62
|
-
astModule =
|
|
63
|
-
|
|
72
|
+
astModule = getModule(logicalPathInfix=defaultA007822['logicalPath']['synthetic'], identifierModule=defaultA007822['module']['algorithm'])
|
|
73
|
+
makeInitializeState(astModule, defaultA007822['module']['initializeState']
|
|
74
|
+
, defaultA007822['function']['initializeState'], defaultA007822['logicalPath']['synthetic'], None, identifiers=defaultA007822)
|
|
75
|
+
|
|
76
|
+
astModule = getModule(logicalPathInfix=defaultA007822['logicalPath']['synthetic'], identifierModule=defaultA007822['module']['algorithm'])
|
|
77
|
+
pathFilename = makeTheorem2(astModule, 'theorem2', defaultA007822['function']['counting']
|
|
78
|
+
, defaultA007822['logicalPath']['synthetic'], defaultA007822['function']['dispatcher'], identifiers=defaultA007822)
|
|
64
79
|
|
|
65
80
|
astModule = parsePathFilename2astModule(pathFilename)
|
|
66
|
-
pathFilename =
|
|
67
|
-
|
|
68
|
-
# @unRePackDataclass
|
|
81
|
+
pathFilename = trimTheorem2(astModule, 'theorem2Trimmed', defaultA007822['function']['counting']
|
|
82
|
+
, defaultA007822['logicalPath']['synthetic'], defaultA007822['function']['dispatcher'])
|
|
69
83
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
84
|
+
astModule = parsePathFilename2astModule(pathFilename)
|
|
85
|
+
pathFilename = _numbaOnTheorem2(astModule, 'theorem2Numba', defaultA007822['function']['counting']
|
|
86
|
+
, defaultA007822['logicalPath']['synthetic'], defaultA007822['function']['dispatcher'])
|
|
73
87
|
|
|
74
88
|
if __name__ == '__main__':
|
|
75
|
-
|
|
89
|
+
makeA007822Modules()
|
|
@@ -1,33 +1,29 @@
|
|
|
1
1
|
"""Configuration by dataclass."""
|
|
2
2
|
|
|
3
|
-
from ast import Module
|
|
4
3
|
from astToolkit import identifierDotAttribute, parseLogicalPath2astModule
|
|
4
|
+
from astToolkit.containers import IngredientsFunction, IngredientsModule, LedgerOfImports
|
|
5
|
+
from astToolkit.transformationTools import pythonCode2ast_expr
|
|
6
|
+
from hunterMakesPy import autoDecodingRLE
|
|
7
|
+
# TODO 'The____' identifiers are a vestigial semiotic system. Do I still need to import `asname`? If so, would different
|
|
8
|
+
# identifiers better integrate into the current semiotics?
|
|
5
9
|
from mapFolding import (
|
|
6
10
|
DatatypeElephino as TheDatatypeElephino, DatatypeFoldsTotal as TheDatatypeFoldsTotal,
|
|
7
11
|
DatatypeLeavesTotal as TheDatatypeLeavesTotal, getPathFilenameFoldsTotal, getPathRootJobDEFAULT, packageSettings)
|
|
8
|
-
from mapFolding.dataBaskets import MapFoldingState
|
|
9
|
-
from mapFolding.someAssemblyRequired import
|
|
12
|
+
from mapFolding.dataBaskets import MapFoldingState, SymmetricFoldsState
|
|
13
|
+
from mapFolding.someAssemblyRequired import DatatypeConfiguration, default, ShatteredDataclass
|
|
10
14
|
from mapFolding.someAssemblyRequired.transformationTools import shatter_dataclassesDOTdataclass
|
|
11
15
|
from pathlib import Path, PurePosixPath
|
|
16
|
+
from typing import cast
|
|
17
|
+
import ast
|
|
12
18
|
import dataclasses
|
|
13
19
|
|
|
14
|
-
@dataclasses.dataclass
|
|
20
|
+
@dataclasses.dataclass(slots=True)
|
|
15
21
|
class RecipeJobTheorem2:
|
|
16
22
|
"""Configuration recipe for generating map folding computation jobs.
|
|
17
23
|
|
|
18
24
|
This dataclass serves as the central configuration hub for the code transformation
|
|
19
|
-
assembly line that converts generic map folding algorithms into
|
|
20
|
-
specialized
|
|
21
|
-
for source code analysis, target file generation, datatype mapping, and compilation
|
|
22
|
-
optimization settings.
|
|
23
|
-
|
|
24
|
-
The transformation process operates by extracting functions from source modules,
|
|
25
|
-
embedding concrete parameter values, eliminating dead code paths, and generating
|
|
26
|
-
standalone Python modules optimized for specific map dimensions.
|
|
27
|
-
|
|
28
|
-
The recipe maintains both source configuration (where to find the generic algorithm)
|
|
29
|
-
and target configuration (where to write the optimized module), along with the
|
|
30
|
-
computational state that provides concrete values for the transformation process.
|
|
25
|
+
assembly line that converts generic map folding algorithms into optimized,
|
|
26
|
+
specialized modules.
|
|
31
27
|
|
|
32
28
|
Attributes
|
|
33
29
|
----------
|
|
@@ -81,24 +77,24 @@ class RecipeJobTheorem2:
|
|
|
81
77
|
Type alias for leaf count datatype.
|
|
82
78
|
"""
|
|
83
79
|
|
|
84
|
-
state: MapFoldingState
|
|
80
|
+
state: MapFoldingState | SymmetricFoldsState
|
|
85
81
|
"""The map folding computation state containing dimensions and initial values."""
|
|
86
82
|
foldsTotalEstimated: int = 0
|
|
87
83
|
"""Estimated total number of folds for progress tracking."""
|
|
88
84
|
shatteredDataclass: ShatteredDataclass = dataclasses.field(default=None, init=True) # pyright: ignore[reportAssignmentType]
|
|
89
85
|
"""Deconstructed dataclass metadata for code transformation."""
|
|
90
86
|
|
|
91
|
-
|
|
92
|
-
source_astModule: Module = parseLogicalPath2astModule('
|
|
87
|
+
# ------- Source -----------------------------------------
|
|
88
|
+
source_astModule: ast.Module = parseLogicalPath2astModule(f'{packageSettings.identifierPackage}.{default['logicalPath']['synthetic']}.theorem2Numba') # noqa: RUF009
|
|
93
89
|
"""Parsed AST of the source module containing the generic algorithm."""
|
|
94
|
-
|
|
90
|
+
identifierCallableSource: str = default['function']['counting']
|
|
95
91
|
"""Name of the counting function to extract."""
|
|
96
92
|
|
|
97
|
-
sourceLogicalPathModuleDataclass: identifierDotAttribute = '
|
|
93
|
+
sourceLogicalPathModuleDataclass: identifierDotAttribute = f'{packageSettings.identifierPackage}.dataBaskets'
|
|
98
94
|
"""Logical path to the dataclass module."""
|
|
99
|
-
sourceDataclassIdentifier: str = '
|
|
95
|
+
sourceDataclassIdentifier: str = default['variable']['stateDataclass']
|
|
100
96
|
"""Name of the source dataclass."""
|
|
101
|
-
sourceDataclassInstance: str =
|
|
97
|
+
sourceDataclassInstance: str = default['variable']['stateInstance']
|
|
102
98
|
"""Instance identifier for the dataclass."""
|
|
103
99
|
|
|
104
100
|
sourcePathPackage: PurePosixPath | None = PurePosixPath(packageSettings.pathPackage) # noqa: RUF009
|
|
@@ -106,7 +102,7 @@ class RecipeJobTheorem2:
|
|
|
106
102
|
sourcePackageIdentifier: str | None = packageSettings.identifierPackage
|
|
107
103
|
"""Name of the source package."""
|
|
108
104
|
|
|
109
|
-
|
|
105
|
+
# ------- Filesystem, names of physical objects ------------------------------------------
|
|
110
106
|
pathPackage: PurePosixPath | None = None
|
|
111
107
|
"""Override path for the target package."""
|
|
112
108
|
pathModule: PurePosixPath | None = PurePosixPath(getPathRootJobDEFAULT()) # noqa: RUF009
|
|
@@ -116,23 +112,23 @@ class RecipeJobTheorem2:
|
|
|
116
112
|
pathFilenameFoldsTotal: PurePosixPath = dataclasses.field(default=None, init=True) # pyright: ignore[reportAssignmentType]
|
|
117
113
|
"""Path for writing fold count results."""
|
|
118
114
|
|
|
119
|
-
|
|
115
|
+
# ------- Logical identifiers, as opposed to physical identifiers ------------------------
|
|
120
116
|
packageIdentifier: str | None = None
|
|
121
117
|
"""Target package identifier."""
|
|
122
118
|
logicalPathRoot: identifierDotAttribute | None = None
|
|
123
119
|
"""Logical path root; probably corresponds to physical filesystem directory."""
|
|
124
120
|
moduleIdentifier: str = dataclasses.field(default=None, init=True) # pyright: ignore[reportAssignmentType]
|
|
125
121
|
"""Target module identifier."""
|
|
126
|
-
|
|
122
|
+
identifierCallable: str = identifierCallableSource
|
|
127
123
|
"""Name of the counting function in generated module."""
|
|
128
|
-
|
|
124
|
+
identifierDataclass: str | None = sourceDataclassIdentifier
|
|
129
125
|
"""Target dataclass identifier."""
|
|
130
|
-
|
|
126
|
+
identifierDataclassInstance: str | None = sourceDataclassInstance
|
|
131
127
|
"""Target dataclass instance identifier."""
|
|
132
128
|
logicalPathModuleDataclass: identifierDotAttribute | None = sourceLogicalPathModuleDataclass
|
|
133
129
|
"""Logical path to target dataclass module."""
|
|
134
130
|
|
|
135
|
-
|
|
131
|
+
# ------- Datatypes ------------------------------------------
|
|
136
132
|
type DatatypeFoldsTotal = TheDatatypeFoldsTotal
|
|
137
133
|
"""Type alias for datatype linked to the magnitude of `foldsTotal`."""
|
|
138
134
|
type DatatypeElephino = TheDatatypeElephino
|
|
@@ -205,11 +201,65 @@ class RecipeJobTheorem2:
|
|
|
205
201
|
"""
|
|
206
202
|
pathFilenameFoldsTotal = PurePosixPath(getPathFilenameFoldsTotal(self.state.mapShape))
|
|
207
203
|
|
|
208
|
-
if self.moduleIdentifier is None: # pyright: ignore[reportUnnecessaryComparison]
|
|
209
|
-
self.moduleIdentifier = pathFilenameFoldsTotal.stem
|
|
210
|
-
|
|
211
204
|
if self.pathFilenameFoldsTotal is None: # pyright: ignore[reportUnnecessaryComparison]
|
|
212
205
|
self.pathFilenameFoldsTotal = pathFilenameFoldsTotal
|
|
213
206
|
|
|
214
|
-
if self.
|
|
215
|
-
self.
|
|
207
|
+
if self.moduleIdentifier is None: # pyright: ignore[reportUnnecessaryComparison]
|
|
208
|
+
self.moduleIdentifier = self.pathFilenameFoldsTotal.stem
|
|
209
|
+
|
|
210
|
+
if self.shatteredDataclass is None and self.logicalPathModuleDataclass and self.identifierDataclass and self.identifierDataclassInstance: # pyright: ignore[reportUnnecessaryComparison]
|
|
211
|
+
self.shatteredDataclass = shatter_dataclassesDOTdataclass(self.logicalPathModuleDataclass, self.identifierDataclass, self.identifierDataclassInstance)
|
|
212
|
+
|
|
213
|
+
def moveShatteredDataclass_arg2body(identifier: str, job: RecipeJobTheorem2) -> ast.AnnAssign | ast.Assign:
|
|
214
|
+
"""Embed a shattered dataclass field assignment into the function body.
|
|
215
|
+
|
|
216
|
+
(AI generated docstring)
|
|
217
|
+
|
|
218
|
+
This helper retrieves the pre-fabricated assignment for `identifier` from `job.shatteredDataclass`, hydrates the literal
|
|
219
|
+
payload from `job.state`, and returns the node ready for insertion into a generated function body. Scalar entries receive the
|
|
220
|
+
concrete integer value, array entries are encoded using the auto-decoding run-length encoded method from `hunterMakesPy`, and
|
|
221
|
+
other constructors are left untouched so downstream tooling can decide how to finalize them.
|
|
222
|
+
|
|
223
|
+
Parameters
|
|
224
|
+
----------
|
|
225
|
+
identifier : str
|
|
226
|
+
Field name keyed in `job.shatteredDataclass.Z0Z_field2AnnAssign`.
|
|
227
|
+
job : RecipeJobTheorem2
|
|
228
|
+
Job descriptor that supplies the current computation state and shattered metadata.
|
|
229
|
+
|
|
230
|
+
Returns
|
|
231
|
+
-------
|
|
232
|
+
Ima___Assign : ast.AnnAssign | ast.Assign
|
|
233
|
+
Assignment node mutated with state-backed values for the requested field.
|
|
234
|
+
"""
|
|
235
|
+
Ima___Assign, elementConstructor = job.shatteredDataclass.Z0Z_field2AnnAssign[identifier]
|
|
236
|
+
match elementConstructor:
|
|
237
|
+
case 'scalar':
|
|
238
|
+
cast(ast.Constant, cast(ast.Call, Ima___Assign.value).args[0]).value = int(eval(f"job.state.{identifier}")) # noqa: S307
|
|
239
|
+
case 'array':
|
|
240
|
+
dataAsStrRLE: str = autoDecodingRLE(eval(f"job.state.{identifier}"), assumeAddSpaces=True) # noqa: S307
|
|
241
|
+
dataAs_ast_expr: ast.expr = pythonCode2ast_expr(dataAsStrRLE)
|
|
242
|
+
cast(ast.Call, Ima___Assign.value).args = [dataAs_ast_expr]
|
|
243
|
+
case _:
|
|
244
|
+
pass
|
|
245
|
+
return Ima___Assign
|
|
246
|
+
|
|
247
|
+
# TODO Use this concept in general modules, not just custom jobs.
|
|
248
|
+
def customizeDatatypeViaImport(ingredientsFunction: IngredientsFunction, ingredientsModule: IngredientsModule, listDatatypeConfigurations: list[DatatypeConfiguration]) -> tuple[IngredientsFunction, IngredientsModule]:
|
|
249
|
+
"""Customize data types in the given ingredients by adjusting imports.
|
|
250
|
+
|
|
251
|
+
In the ecosystem of "Ingredients", "Recipes", "DataBaskets," and "shattered dataclasses," a ton of code is dedicated to
|
|
252
|
+
preserving _abstract_ names for datatypes, such as `Array1DLeavesTotal` and `DatatypeFoldsTotal`. This function well
|
|
253
|
+
illustrates why I put so much effort into preserving the abstract names. (Normally, Python will _immediately_ replace an alias
|
|
254
|
+
name with the type for which it is a proxy.) Because transformed code, even if it has been through 10 transformations (see,
|
|
255
|
+
for example, `mapFolding.syntheticModules.A007822.asynchronousNumba` or its equivalent), ought to still have the abstract
|
|
256
|
+
names, this function gives you the power to change the datatype from numpy to numba and/or from 8-bits to 16-bits merely by
|
|
257
|
+
changing the import statements. You shouldn't need to change any "business" logic.
|
|
258
|
+
|
|
259
|
+
NOTE This will not remove potentially conflicting existing imports from other modules.
|
|
260
|
+
"""
|
|
261
|
+
for datatypeConfig in listDatatypeConfigurations:
|
|
262
|
+
ingredientsFunction.imports.removeImportFrom(datatypeConfig.typeModule, None, datatypeConfig.datatypeIdentifier)
|
|
263
|
+
ingredientsFunction.imports.addImportFrom_asStr(datatypeConfig.typeModule, datatypeConfig.typeIdentifier, datatypeConfig.type_asname)
|
|
264
|
+
|
|
265
|
+
return ingredientsFunction, ingredientsModule
|
|
@@ -73,20 +73,16 @@ calculations through the strategic application of compiler optimization techniqu
|
|
|
73
73
|
"""
|
|
74
74
|
|
|
75
75
|
from mapFolding.someAssemblyRequired.infoBooth import (
|
|
76
|
+
default as default,
|
|
77
|
+
Default as Default,
|
|
78
|
+
defaultA007822 as defaultA007822,
|
|
76
79
|
dictionaryEstimatesMapFolding as dictionaryEstimatesMapFolding,
|
|
77
|
-
identifierCallableSourceDEFAULT as identifierCallableSourceDEFAULT,
|
|
78
|
-
identifierCallableSourceDispatcherDEFAULT as identifierCallableSourceDispatcherDEFAULT,
|
|
79
|
-
identifierCountingDEFAULT as identifierCountingDEFAULT,
|
|
80
|
-
identifierDataclassInstanceDEFAULT as identifierDataclassInstanceDEFAULT,
|
|
81
|
-
identifierModuleDataPackingDEFAULT as identifierModuleDataPackingDEFAULT,
|
|
82
|
-
identifierModuleSourceAlgorithmDEFAULT as identifierModuleSourceAlgorithmDEFAULT,
|
|
83
|
-
logicalPathInfixAlgorithmDEFAULT as logicalPathInfixAlgorithmDEFAULT,
|
|
84
|
-
logicalPathInfixDEFAULT as logicalPathInfixDEFAULT,
|
|
85
80
|
)
|
|
86
81
|
|
|
87
82
|
from mapFolding.someAssemblyRequired._toolIfThis import IfThis as IfThis
|
|
88
83
|
|
|
89
84
|
from mapFolding.someAssemblyRequired._toolkitContainers import (
|
|
85
|
+
DatatypeConfiguration as DatatypeConfiguration,
|
|
90
86
|
DeReConstructField2ast as DeReConstructField2ast,
|
|
91
87
|
ShatteredDataclass as ShatteredDataclass,
|
|
92
88
|
)
|