mapFolding 0.16.4__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 -9
- easyRun/countFolds.py +10 -3
- easyRun/meanders.py +3 -3
- mapFolding/algorithms/A000136constraintPropagation.py +95 -0
- mapFolding/algorithms/A000136elimination.py +163 -0
- mapFolding/algorithms/A000136eliminationParallel.py +77 -0
- mapFolding/algorithms/matrixMeanders.py +59 -18
- mapFolding/algorithms/matrixMeandersNumPyndas.py +841 -0
- mapFolding/algorithms/symmetricFolds.py +24 -25
- mapFolding/basecamp.py +30 -14
- mapFolding/dataBaskets.py +30 -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/test_computations.py +28 -2
- {mapfolding-0.16.4.dist-info → mapfolding-0.17.0.dist-info}/METADATA +9 -9
- {mapfolding-0.16.4.dist-info → mapfolding-0.17.0.dist-info}/RECORD +50 -49
- mapFolding/algorithms/matrixMeandersBeDry.py +0 -182
- mapFolding/algorithms/matrixMeandersNumPy.py +0 -333
- mapFolding/algorithms/matrixMeandersPandas.py +0 -334
- {mapfolding-0.16.4.dist-info → mapfolding-0.17.0.dist-info}/WHEEL +0 -0
- {mapfolding-0.16.4.dist-info → mapfolding-0.17.0.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.16.4.dist-info → mapfolding-0.17.0.dist-info}/licenses/LICENSE +0 -0
- {mapfolding-0.16.4.dist-info → mapfolding-0.17.0.dist-info}/top_level.txt +0 -0
|
@@ -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()
|
|
@@ -31,18 +31,14 @@ improvements through just-in-time compilation, parallel execution, and optimized
|
|
|
31
31
|
tailored for specific computational requirements essential to large-scale map folding research.
|
|
32
32
|
"""
|
|
33
33
|
|
|
34
|
-
from astToolkit import
|
|
35
|
-
|
|
36
|
-
from
|
|
37
|
-
from hunterMakesPy import raiseIfNone, writeStringToHere
|
|
34
|
+
from astToolkit import Be, DOT, identifierDotAttribute, NodeTourist, parseLogicalPath2astModule, Then
|
|
35
|
+
from astToolkit.containers import IngredientsFunction
|
|
36
|
+
from hunterMakesPy import raiseIfNone
|
|
38
37
|
from mapFolding import packageSettings
|
|
39
38
|
from mapFolding.someAssemblyRequired import default
|
|
40
39
|
from os import PathLike
|
|
41
40
|
from pathlib import PurePath
|
|
42
|
-
from typing import Any
|
|
43
41
|
import ast
|
|
44
|
-
import io
|
|
45
|
-
import isort
|
|
46
42
|
|
|
47
43
|
def findDataclass(ingredientsFunction: IngredientsFunction) -> tuple[identifierDotAttribute, str, str]:
|
|
48
44
|
"""Dynamically extract information about a `dataclass`: the instance identifier, the identifier, and the logical path module.
|
|
@@ -128,25 +124,3 @@ def getPathFilename(pathRoot: PathLike[str] | PurePath | None = packageSettings.
|
|
|
128
124
|
if pathRoot:
|
|
129
125
|
pathFilename = PurePath(pathRoot, pathFilename)
|
|
130
126
|
return pathFilename
|
|
131
|
-
|
|
132
|
-
def write_astModule(astModule: ast.Module, pathFilename: PathLike[Any] | PurePath | io.TextIOBase, packageName: str | None = None) -> None:
|
|
133
|
-
"""Prototype that will likely be moved to astToolkit.
|
|
134
|
-
|
|
135
|
-
Parameters
|
|
136
|
-
----------
|
|
137
|
-
astModule : ast.Module
|
|
138
|
-
The AST module to be written to a file.
|
|
139
|
-
pathFilename : PathLike[Any] | PurePath
|
|
140
|
-
The file path where the module should be written.
|
|
141
|
-
packageName : str | None = None
|
|
142
|
-
Optional package name to preserve in import optimization.
|
|
143
|
-
"""
|
|
144
|
-
ast.fix_missing_locations(astModule)
|
|
145
|
-
pythonSource: str = ast.unparse(astModule)
|
|
146
|
-
autoflake_additional_imports: list[str] = []
|
|
147
|
-
if packageName:
|
|
148
|
-
autoflake_additional_imports.append(packageName)
|
|
149
|
-
pythonSource = autoflake_fix_code(pythonSource, autoflake_additional_imports, expand_star_imports=False, remove_all_unused_imports=True, remove_duplicate_keys = False, remove_unused_variables = False)
|
|
150
|
-
pythonSource = isort.code(pythonSource)
|
|
151
|
-
writeStringToHere(pythonSource + '\n', pathFilename)
|
|
152
|
-
|
|
@@ -25,7 +25,8 @@ computational modules. The compilation layer integrates seamlessly with the broa
|
|
|
25
25
|
system to produce standalone modules optimized for specific map dimensions and computational contexts.
|
|
26
26
|
"""
|
|
27
27
|
|
|
28
|
-
from astToolkit import identifierDotAttribute,
|
|
28
|
+
from astToolkit import identifierDotAttribute, Make
|
|
29
|
+
from astToolkit.containers import IngredientsFunction
|
|
29
30
|
from collections.abc import Callable
|
|
30
31
|
from numba.core.compiler import CompilerBase as numbaCompilerBase
|
|
31
32
|
from typing import Any, Final, NotRequired, TYPE_CHECKING, TypedDict
|
|
@@ -25,9 +25,8 @@ This approach enables seamless integration between high-level dataclass-based in
|
|
|
25
25
|
low-level optimized implementations, maintaining code clarity while achieving performance gains
|
|
26
26
|
through specialized compilation paths essential for computationally intensive map folding research.
|
|
27
27
|
"""
|
|
28
|
-
|
|
29
|
-
from astToolkit import
|
|
30
|
-
Be, extractClassDef, identifierDotAttribute, IngredientsFunction, Make, NodeChanger, parseLogicalPath2astModule, Then)
|
|
28
|
+
from astToolkit import Be, extractClassDef, identifierDotAttribute, Make, NodeChanger, parseLogicalPath2astModule, Then
|
|
29
|
+
from astToolkit.containers import IngredientsFunction, LedgerOfImports
|
|
31
30
|
from astToolkit.transformationTools import unparseFindReplace
|
|
32
31
|
from hunterMakesPy import importLogicalPath2Identifier
|
|
33
32
|
from mapFolding.someAssemblyRequired import DeReConstructField2ast, IfThis, ShatteredDataclass
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import numpy
|
|
2
|
-
|
|
3
1
|
from mapFolding.dataBaskets import SymmetricFoldsState
|
|
4
2
|
|
|
5
|
-
|
|
6
3
|
def filterAsymmetricFolds(state: SymmetricFoldsState) -> SymmetricFoldsState:
|
|
7
4
|
state.indexLeaf = 1
|
|
8
5
|
state.leafComparison[0] = 1
|
|
@@ -12,10 +9,13 @@ def filterAsymmetricFolds(state: SymmetricFoldsState) -> SymmetricFoldsState:
|
|
|
12
9
|
state.leafComparison[state.leafConnectee] = (state.indexMiniGap - state.indexLeaf + state.leavesTotal) % state.leavesTotal
|
|
13
10
|
state.indexLeaf = state.indexMiniGap
|
|
14
11
|
state.leafConnectee += 1
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
for listTuples in state.indices:
|
|
13
|
+
state.leafConnectee = 1
|
|
14
|
+
for indexLeft, indexRight in listTuples:
|
|
15
|
+
if state.leafComparison[indexLeft] != state.leafComparison[indexRight]:
|
|
16
|
+
state.leafConnectee = 0
|
|
17
|
+
break
|
|
18
|
+
state.symmetricFolds += state.leafConnectee
|
|
19
19
|
return state
|
|
20
20
|
|
|
21
21
|
def activeLeafGreaterThan0(state: SymmetricFoldsState) -> bool:
|
|
@@ -153,7 +153,7 @@ def count(state: SymmetricFoldsState) -> SymmetricFoldsState:
|
|
|
153
153
|
state = undoLastLeafPlacement(state)
|
|
154
154
|
if gapAvailable(state):
|
|
155
155
|
state = insertActiveLeafAtGap(state)
|
|
156
|
-
state.
|
|
156
|
+
state.symmetricFolds = (state.symmetricFolds + 1) // 2
|
|
157
157
|
return state
|
|
158
158
|
|
|
159
159
|
def doTheNeedful(state: SymmetricFoldsState) -> SymmetricFoldsState:
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
from copy import deepcopy
|
|
2
|
-
from queue import Queue
|
|
3
|
-
from threading import Lock, Thread
|
|
4
|
-
|
|
5
|
-
import numpy
|
|
6
|
-
|
|
7
2
|
from mapFolding import DatatypeFoldsTotal
|
|
8
3
|
from mapFolding.dataBaskets import SymmetricFoldsState
|
|
4
|
+
from queue import Queue
|
|
5
|
+
from threading import Lock, Thread
|
|
9
6
|
|
|
10
7
|
listThreads: list[Thread] = []
|
|
11
8
|
queueFutures: Queue[SymmetricFoldsState] = Queue()
|
|
@@ -33,7 +30,7 @@ def _threadDoesSomething() -> None:
|
|
|
33
30
|
break
|
|
34
31
|
state = _filterAsymmetricFolds(state)
|
|
35
32
|
with LOCKsymmetricFoldsTotal:
|
|
36
|
-
symmetricFoldsTotal += state.
|
|
33
|
+
symmetricFoldsTotal += state.symmetricFolds
|
|
37
34
|
|
|
38
35
|
def filterAsymmetricFolds(state: SymmetricFoldsState) -> None:
|
|
39
36
|
queueFutures.put_nowait(deepcopy(state))
|
|
@@ -54,11 +51,13 @@ def _filterAsymmetricFolds(state: SymmetricFoldsState) -> SymmetricFoldsState:
|
|
|
54
51
|
state.leafComparison[state.leafConnectee] = (state.indexMiniGap - state.indexLeaf + state.leavesTotal) % state.leavesTotal
|
|
55
52
|
state.indexLeaf = state.indexMiniGap
|
|
56
53
|
state.leafConnectee += 1
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
for listTuples in state.indices:
|
|
55
|
+
state.leafConnectee = 1
|
|
56
|
+
for indexLeft, indexRight in listTuples:
|
|
57
|
+
if state.leafComparison[indexLeft] != state.leafComparison[indexRight]:
|
|
58
|
+
state.leafConnectee = 0
|
|
59
|
+
break
|
|
60
|
+
state.symmetricFolds += state.leafConnectee
|
|
62
61
|
return state
|
|
63
62
|
|
|
64
63
|
def activeLeafGreaterThan0(state: SymmetricFoldsState) -> bool:
|
|
@@ -197,8 +196,8 @@ def count(state: SymmetricFoldsState) -> SymmetricFoldsState:
|
|
|
197
196
|
if gapAvailable(state):
|
|
198
197
|
state = insertActiveLeafAtGap(state)
|
|
199
198
|
else:
|
|
200
|
-
state.
|
|
201
|
-
state.
|
|
199
|
+
state.symmetricFolds = getSymmetricFoldsTotal()
|
|
200
|
+
state.symmetricFolds = (state.symmetricFolds + 1) // 2
|
|
202
201
|
return state
|
|
203
202
|
|
|
204
203
|
def doTheNeedful(state: SymmetricFoldsState, maxWorkers: int) -> SymmetricFoldsState:
|