Skip to content

Commit

Permalink
Merge branch 'pythonise-tcl-scripts' of github.com:highperformancecod…
Browse files Browse the repository at this point in the history
…er/minsky into pythonise-tcl-scripts
  • Loading branch information
highperformancecoder committed Apr 29, 2024
2 parents b841183 + 3c5c706 commit fceeacc
Show file tree
Hide file tree
Showing 181 changed files with 505 additions and 502 deletions.
22 changes: 22 additions & 0 deletions createIcons.py
@@ -0,0 +1,22 @@
import sys
from pathlib import Path
here=str(Path(sys.argv[0]).parent)
if here: sys.path.append(here)
else: sys.path.append('.')

from pyminsky import minsky

iconDir=here+'/gui-js/apps/minsky-web/src/assets/images/icons/'
minsky.histogramResource.setResource(iconDir+'histogram.svg')
# make the background transparent
minsky.canvas.backgroundColour({'a':0})
ops=minsky.availableOperations()
ops.append("switch")
for op in ops:
# ignore some operations
if op in ["numOps","constant","copy","ravel","integrate"]: continue

if op=="switch": minsky.canvas.addSwitch()
else: minsky.canvas.addOperation(op)
minsky.renderCanvasToPNG(iconDir+op+'.png')
minsky.clearAllMaps()
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/abs.gif
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/acos.gif
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/add.gif
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/all.gif
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/and_.gif
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/any.gif
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/asin.gif
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/atan.gif
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/cos.gif
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/cosh.gif
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/data.gif
Binary file not shown.
Binary file modified gui-js/apps/minsky-web/src/assets/images/icons/data.png
Diff not rendered.
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/eq.gif
Diff not rendered.
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/exp.gif
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/fact.gif
Diff not rendered.
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/frac.gif
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file modified gui-js/apps/minsky-web/src/assets/images/icons/index.gif
Binary file modified gui-js/apps/minsky-web/src/assets/images/icons/inf.gif
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/le.gif
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/ln.gif
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/log.gif
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/lt.gif
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/max.gif
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/mean.gif
Diff not rendered.
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/meld.gif
Diff not rendered.
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/min.gif
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/not_.gif
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/one.gif
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/or_.gif
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/pi.gif
Diff not rendered.
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/pow.gif
Diff not rendered.
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/rho.gif
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/sin.gif
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/sinh.gif
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/size.gif
Diff not rendered.
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/sqrt.gif
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/sum.gif
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/tan.gif
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/tanh.gif
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/time.gif
Diff not rendered.
Diff not rendered.
Binary file removed gui-js/apps/minsky-web/src/assets/images/icons/zero.gif
Diff not rendered.
@@ -1,7 +1,7 @@
<ng-container *ngIf="title && operations.length">
<button class="tab toolButton" [attr.classType]="'Operations'" [matMenuTriggerFor]="opMenu" [attr.aria-label]="title">
<img
src="assets/images/icons/{{ operations[0] }}.gif"
src="assets/images/icons/{{ operations[0] }}.png"
alt="{{ title }}"
title="{{ title }}"
/>
Expand All @@ -17,7 +17,7 @@
(dragstart)="onButtonDrag($event, operation)"
>
<img
src="assets/images/icons/{{ operation }}.gif"
src="assets/images/icons/{{ operation }}.png"
alt="{{ operation }}"
title="{{ operation }}"
/>
Expand Down
Expand Up @@ -33,7 +33,7 @@
<img src="assets/images/icons/note.gif" alt="Note" title="Note" />
</button>
<button class="tab toolButton" classType="Operation:time" (click)="electronService.minsky.canvas.addOperation('time')">
<img src="assets/images/icons/time.gif" alt="Time" title="Time" />
<img src="assets/images/icons/time.png" alt="Time" title="Time" />
</button>
<ng-container *ngFor="let operation of availableOperationsMapping | keyvalue">
<minsky-available-operations
Expand All @@ -42,12 +42,12 @@
></minsky-available-operations>
</ng-container>
<button class="tab toolButton" classType="SwitchIcon" (click)="electronService.minsky.canvas.addSwitch()">
<img src="assets/images/icons/switch.gif" alt="Switch" title="Switch" />
<img src="assets/images/icons/switch.png" alt="Switch" title="Switch" />
</button>
<button class="tab toolButton"
classType="Operation:userFunction" (click)="electronService.minsky.canvas.addOperation('userFunction')">
<img
src="assets/images/icons/userFunction.gif"
src="assets/images/icons/userFunction.png"
alt="User Defined Function"
title="User Defined Function"
/>
Expand All @@ -69,7 +69,7 @@
<button class="tab toolButton"
classType="Operation:differentiate" (click)="electronService.minsky.canvas.addOperation('differentiate')">
<img
src="assets/images/icons/differentiate.gif"
src="assets/images/icons/differentiate.png"
alt="Differentiate"
title="Differentiate"
/>
Expand Down
2 changes: 1 addition & 1 deletion test/00/compareSimulationWithLogged.sh
Expand Up @@ -11,7 +11,7 @@ for i in *.mky; do
if [ $i = "indexing.mky" ]; then continue; fi
if [ $i = "importedCSV.mky" ]; then continue; fi
if [ $i = "histogram.mky" ]; then continue; fi
$here/gui-tk/minsky ../test/compareFileLog.tcl $i ../test/exampleLogs/$i.log
python3 ../test/compareFileLog.py $i ../test/exampleLogs/$i.log
if test $? -ne 0; then
echo "for $i"
fail
Expand Down
74 changes: 74 additions & 0 deletions test/compareFileLog.py
@@ -0,0 +1,74 @@
#!/usr/bin/python3

# usage python3 compareFileLog.py <system.mky> <logfile>

# compares the running of a minsky model <system.mky>, with a previously
# run data log file <logfile>, created by "createFileLog"

import sys
import csv
import re

from pathlib import Path
here=Path(sys.argv[0]).parent.parent
if here=="": here='.' #relative path
sys.path.append(str(here))

from pyminsky import minsky

def fclose(x,y):
if abs(x)>1e-30:
return abs(x-y)/(abs(x)+abs(y)) < 1e-2
return abs(x-y) <= 1e-30

minsky.load(sys.argv[1])

ret=0

minsky.running(True)
#provide seed to ensure repeatability
minsky.srand(10)
minsky.reset()

valueDict={}
def testValue(key, value):
# check that any local variable of the same name matches out value
if not any([fclose(value, x) for x in valueDict[key]]):
print(sys.argv[1], "t=",minsky.t(),name," logged ",value)
ret=1

with open(sys.argv[2]) as log:
reader=csv.reader(log)
# first line should specify no of steps to run
row=next(reader)
nsteps=int(row[1])

for step in range(nsteps):
row=next(reader)
minsky.step()

if not fclose(minsky.t(),float(row[0])):
print("t=",minsky.t()," logged ",row[0])
ret=1


for i in range(1,len(row),2):
# stash these in an array of values, to represent multiple same named local variables
if row[i] in valueDict:
valueDict[row[i]].append(float(row[i+1]))
else:
valueDict[row[i]]=[float(row[i+1])]


for name in minsky.variableValues._keys():
if re.search("^constant:",name) != None: continue
value=minsky.variableValues[name]
if value.temp(): continue

if value.size()>1:
for i in range(value.size()):
testValue(f"{value.name()}|{i}",value.value())
else:
testValue(value.name(),value.value())

exit(ret)
91 changes: 0 additions & 91 deletions test/compareFileLog.tcl

This file was deleted.

39 changes: 39 additions & 0 deletions test/createFileLog.py
@@ -0,0 +1,39 @@
#!/usr/bin/python3

# usage python3 createFileLog.py <system.mky>

# writes a log file on stdout for system <system.mky>

import sys
from pathlib import Path
here=Path(sys.argv[0]).parent.parent
if here=="": here='.' #relative path
sys.path.append(str(here))

from pyminsky import minsky
import re
minsky.load(sys.argv[1])


nSteps=10
print("nsteps,",nSteps)
minsky.running(True)
#provide seed to ensure repeatability
minsky.srand(10)
minsky.reset()

for step in range(nSteps):
minsky.step()
print(minsky.t(),end='')

for name in minsky.variableValues._keys():
if re.search("^constant:",name) != None: continue
value=minsky.variableValues[name]
if value.temp(): continue
if value.size()>1:
for i in range(value.size()):
print(f',"{value.name()}|{i}"',value.value(i),sep=',',end='')
else:
print(f',"{value.name()}"',value.value(),sep=',',end="")
print()

41 changes: 0 additions & 41 deletions test/createFileLog.tcl

This file was deleted.

22 changes: 11 additions & 11 deletions test/exampleLogs/1Free.mky.log
@@ -1,11 +1,11 @@
nsteps 10
3 {:FirmInt} 0.858866 {:Firms} 85.8866 {:IntLoan} 4.70502 {:Loan} 2.44978 {:Loans} 94.1004 {:Safe} 8.21384 {:Vault} 4.89956 {:rD} 0.01 {:rL} 0.05 {:τ<sub>vault</sub>} 0.5
6.02049 {:FirmInt} 0.783437 {:Firms} 78.3437 {:IntLoan} 4.93813 {:Loan} 0.118746 {:Loans} 98.7625 {:Safe} 20.4188 {:Vault} 0.237492 {:rD} 0.01 {:rL} 0.05 {:τ<sub>vault</sub>} 0.5
9.0989 {:FirmInt} 0.655612 {:Firms} 65.5612 {:IntLoan} 4.94946 {:Loan} 0.00542632 {:Loans} 98.9891 {:Safe} 33.4279 {:Vault} 0.0108526 {:rD} 0.01 {:rL} 0.05 {:τ<sub>vault</sub>} 0.5
12.597 {:FirmInt} 0.502844 {:Firms} 50.2844 {:IntLoan} 4.94998 {:Loan} 0.000158069 {:Loans} 98.9997 {:Safe} 48.7153 {:Vault} 0.000316138 {:rD} 0.01 {:rL} 0.05 {:τ<sub>vault</sub>} 0.5
17.2533 {:FirmInt} 0.290882 {:Firms} 29.0882 {:IntLoan} 4.95 {:Loan} -2.36134e-06 {:Loans} 99 {:Safe} 69.9118 {:Vault} -4.72268e-06 {:rD} 0.01 {:rL} 0.05 {:τ<sub>vault</sub>} 0.5
24.2533 {:FirmInt} -0.0469424 {:Firms} -4.69424 {:IntLoan} 4.95 {:Loan} 1.53463e-06 {:Loans} 99 {:Safe} 103.694 {:Vault} 3.06927e-06 {:rD} 0.01 {:rL} 0.05 {:τ<sub>vault</sub>} 0.5
31.2533 {:FirmInt} -0.409262 {:Firms} -40.9262 {:IntLoan} 4.95 {:Loan} -9.97358e-07 {:Loans} 99 {:Safe} 139.926 {:Vault} -1.99472e-06 {:rD} 0.01 {:rL} 0.05 {:τ<sub>vault</sub>} 0.5
38.2533 {:FirmInt} -0.797852 {:Firms} -79.7852 {:IntLoan} 4.95 {:Loan} 6.48183e-07 {:Loans} 99 {:Safe} 178.785 {:Vault} 1.29637e-06 {:rD} 0.01 {:rL} 0.05 {:τ<sub>vault</sub>} 0.5
45.2533 {:FirmInt} -1.21462 {:Firms} -121.462 {:IntLoan} 4.95 {:Loan} -4.21254e-07 {:Loans} 99 {:Safe} 220.462 {:Vault} -8.42508e-07 {:rD} 0.01 {:rL} 0.05 {:τ<sub>vault</sub>} 0.5
52.2533 {:FirmInt} -1.6616 {:Firms} -166.16 {:IntLoan} 4.95 {:Loan} 2.73773e-07 {:Loans} 99 {:Safe} 265.16 {:Vault} 5.47546e-07 {:rD} 0.01 {:rL} 0.05 {:τ<sub>vault</sub>} 0.5
nsteps, 10
3.0,":FirmInt",0.8588660509119618,":Firms",85.88660509119617,":IntLoan",4.705022218461891,":Loan",2.44977781538109,":Loans",94.10044436923782,":Safe",8.213839278041643,":Vault",4.89955563076218,":rD",0.01,":rL",0.05,":\tau_\mathrm{vault}",0.5
6.020493780300365,":FirmInt",0.7834374049051636,":Firms",78.34374049051635,":IntLoan",4.938125375996015,":Loan",0.11874624003985976,":Loans",98.76250751992029,":Safe",20.418767029403934,":Vault",0.23749248007971951,":rD",0.01,":rL",0.05,":\tau_\mathrm{vault}",0.5
9.098903060211793,":FirmInt",0.6556122409453465,":Firms",65.56122409453465,":IntLoan",4.949457367861261,":Loan",0.005426321387397959,":Loans",98.98914735722522,":Safe",33.427923262690555,":Vault",0.010852642774795918,":rD",0.01,":rL",0.05,":\tau_\mathrm{vault}",0.5
12.597033634549913,":FirmInt",0.5028440931774055,":Firms",50.284409317740554,":IntLoan",4.949984193080265,":Loan",0.00015806919735001588,":Loans",98.9996838616053,":Safe",48.71527454386475,":Vault",0.00031613839470003176,":rD",0.01,":rL",0.05,":\tau_\mathrm{vault}",0.5
17.253250340525874,":FirmInt",0.2908818721402956,":Firms",29.08818721402956,":IntLoan",4.9500002361337945,":Loan",-2.361337937732855e-06,":Loans",99.00000472267588,":Safe",69.91181750864634,":Vault",-4.72267587546571e-06,":rD",0.01,":rL",0.05,":\tau_\mathrm{vault}",0.5
24.253250340525874,":FirmInt",-0.046942394056448004,":Firms",-4.6942394056448,":IntLoan",4.949999846536688,":Loan",1.5346331306456168e-06,":Loans",98.99999693073374,":Safe",103.69423633637857,":Vault",3.0692662612912335e-06,":rD",0.01,":rL",0.05,":\tau_\mathrm{vault}",0.5
31.253250340525874,":FirmInt",-0.40926154384946795,":Firms",-40.92615438494679,":IntLoan",4.950000099735782,":Loan",-9.97357814839633e-07,":Loans",99.00000199471563,":Safe",139.92615637966247,":Vault",-1.994715629679266e-06,":rD",0.01,":rL",0.05,":\tau_\mathrm{vault}",0.5
38.253250340525874,":FirmInt",-0.7978518868990342,":Firms",-79.78518868990342,":IntLoan",4.949999935181733,":Loan",6.481826769914769e-07,":Loans",98.99999870363465,":Safe",178.78518739353808,":Vault",1.2963653539829538e-06,":rD",0.01,":rL",0.05,":\tau_\mathrm{vault}",0.5
45.253250340525874,":FirmInt",-1.214618150039562,":Firms",-121.4618150039562,":IntLoan",4.950000042125382,":Loan",-4.212538133261557e-07,":Loans",99.00000084250763,":Safe",220.46181584646382,":Vault",-8.425076266523114e-07,":rD",0.01,":rL",0.05,":\tau_\mathrm{vault}",0.5
52.253250340525874,":FirmInt",-1.66160341522156,":Firms",-166.160341522156,":IntLoan",4.949999972622723,":Loan",2.7377278279863865e-07,":Loans",98.99999945245445,":Safe",265.1603409746104,":Vault",5.475455655972773e-07,":rD",0.01,":rL",0.05,":\tau_\mathrm{vault}",0.5

0 comments on commit fceeacc

Please sign in to comment.