added cleanup of notebooks for www version
This commit is contained in:
@@ -155,7 +155,7 @@
|
|||||||
"id": "RY1F4kdWPLNG"
|
"id": "RY1F4kdWPLNG"
|
||||||
},
|
},
|
||||||
"source": [
|
"source": [
|
||||||
"Also let's get installing / importing all the necessary libraries out of the way. And while we're at it, we can set the random seed - obviously, 42 is the ultimate choice here 🙂"
|
"Also let's get installing / importing all the necessary libraries out of the way. And while we're at it, we can set the random seed - obviously, 42 is the ultimate choice here \ud83d\ude42"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -591,7 +591,6 @@
|
|||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"WARNING:tensorflow:From /usr/local/lib/python3.7/site-packages/tensorflow_core/python/ops/resource_variable_ops.py:1630: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.\n",
|
|
||||||
"Instructions for updating:\n",
|
"Instructions for updating:\n",
|
||||||
"If using Keras pass *_constraint arguments to layers.\n",
|
"If using Keras pass *_constraint arguments to layers.\n",
|
||||||
"Model: \"sequential\"\n",
|
"Model: \"sequential\"\n",
|
||||||
@@ -1261,4 +1260,4 @@
|
|||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 1
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,16 @@
|
|||||||
import json, re, os
|
import sys, json, re, os
|
||||||
|
# usage: json-cleanup-for-pdf.py <int>
|
||||||
|
# if int>0, disable PDF mode (only do WWW cleanup)
|
||||||
|
|
||||||
|
# disableWrites = True # debugging
|
||||||
|
|
||||||
|
pdfMode = True
|
||||||
|
|
||||||
|
print(format(sys.argv))
|
||||||
|
if len(sys.argv)>1:
|
||||||
|
if int(sys.argv[1])>0:
|
||||||
|
print("WWW mode on")
|
||||||
|
pdfMode = False
|
||||||
|
|
||||||
fileList = [
|
fileList = [
|
||||||
"diffphys-code-burgers.ipynb", "diffphys-code-sol.ipynb", "physicalloss-code.ipynb", # TF
|
"diffphys-code-burgers.ipynb", "diffphys-code-sol.ipynb", "physicalloss-code.ipynb", # TF
|
||||||
@@ -6,11 +18,21 @@ fileList = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
#fileList = [ "diffphys-code-burgers.ipynb"] # debug
|
#fileList = [ "diffphys-code-burgers.ipynb"] # debug
|
||||||
|
#fileList = [ "diffphys-code-sol.ipynb"] # debug
|
||||||
|
|
||||||
# shorten data line: "0.008612174447657694, 0.02584669669548606, 0.043136357266407785"
|
|
||||||
|
# main
|
||||||
|
|
||||||
for fnOut in fileList:
|
for fnOut in fileList:
|
||||||
fn = fnOut[:-5] + "bak"
|
# create backups
|
||||||
|
fn0 = fnOut[:-5] + "bak"
|
||||||
|
fn = fn0 + "0"; cnt = 0
|
||||||
|
while os.path.isfile(fn):
|
||||||
|
#print("Error: "+fn+" already exists!")
|
||||||
|
#exit(1)
|
||||||
|
print("Warning: "+fn+" already exists!")
|
||||||
|
fn = fn0 + format(cnt); cnt=cnt+1
|
||||||
|
|
||||||
print("renaming "+fnOut+ " to "+fn )
|
print("renaming "+fnOut+ " to "+fn )
|
||||||
if os.path.isfile(fnOut):
|
if os.path.isfile(fnOut):
|
||||||
os.rename(fnOut, fn)
|
os.rename(fnOut, fn)
|
||||||
@@ -18,18 +40,16 @@ for fnOut in fileList:
|
|||||||
print("Error: "+fn+" missing!")
|
print("Error: "+fn+" missing!")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
#continue # exit(1)
|
|
||||||
|
|
||||||
#fn="diffphys-code-burgers.ipynb"
|
|
||||||
#fnOut="diffphys-code-burgers-r.ipynb"
|
|
||||||
|
|
||||||
with open(fn) as file:
|
with open(fn) as file:
|
||||||
d = json.load(file)
|
d = json.load(file)
|
||||||
|
|
||||||
#print(d.keys()) #print(d["cells"][0].keys())
|
#print(d.keys()) #print(d["cells"][0].keys())
|
||||||
|
|
||||||
|
# remove TF / pytorch warnings
|
||||||
re1 = re.compile(r"WARNING:tensorflow:")
|
re1 = re.compile(r"WARNING:tensorflow:")
|
||||||
re2 = re.compile(r"UserWarning:")
|
re2 = re.compile(r"UserWarning:")
|
||||||
|
|
||||||
|
# shorten data line: "0.008612174447657694, 0.02584669669548606, 0.043136357266407785"
|
||||||
re3 = re.compile(r"\[0.008612174447657694, 0.02584669669548606, 0.043136357266407785.+\]" )
|
re3 = re.compile(r"\[0.008612174447657694, 0.02584669669548606, 0.043136357266407785.+\]" )
|
||||||
re3t = "[0.008612174447657694, 0.02584669669548606, 0.043136357266407785 ... ]"
|
re3t = "[0.008612174447657694, 0.02584669669548606, 0.043136357266407785 ... ]"
|
||||||
|
|
||||||
@@ -48,13 +68,14 @@ for fnOut in fileList:
|
|||||||
#d[t][i]["outputs"] = ""
|
#d[t][i]["outputs"] = ""
|
||||||
#print(d[t][i]["outputs"])
|
#print(d[t][i]["outputs"])
|
||||||
|
|
||||||
for j in range(len( d[t][i]["source"] )):
|
if pdfMode:
|
||||||
#print( d[t][i]["source"][j] )
|
for j in range(len( d[t][i]["source"] )):
|
||||||
#print( type(d[t][i]["source"][j] ))
|
#print( d[t][i]["source"][j] )
|
||||||
dsOut = re3.sub( re3t, d[t][i]["source"][j] ) # replace long number string (only for burgers)
|
#print( type(d[t][i]["source"][j] ))
|
||||||
d[t][i]["source"][j] = dsOut
|
dsOut = re3.sub( re3t, d[t][i]["source"][j] ) # replace long number string (only for burgers)
|
||||||
deletes = deletes+1
|
d[t][i]["source"][j] = dsOut
|
||||||
#print( d[t][i]["source"][j] +"\n >>> \n" +d2 )
|
deletes = deletes+1
|
||||||
|
#print( d[t][i]["source"][j] +"\n >>> \n" +d2 )
|
||||||
|
|
||||||
#print(len( d[t][i]["outputs"] ))
|
#print(len( d[t][i]["outputs"] ))
|
||||||
for j in range(len( d[t][i]["outputs"] )):
|
for j in range(len( d[t][i]["outputs"] )):
|
||||||
@@ -82,8 +103,6 @@ for fnOut in fileList:
|
|||||||
|
|
||||||
print( format( len( d[t][i]["outputs"][j]["text"] )) + " A")
|
print( format( len( d[t][i]["outputs"][j]["text"] )) + " A")
|
||||||
|
|
||||||
#print(d["cells"])
|
|
||||||
|
|
||||||
if deletes==0:
|
if deletes==0:
|
||||||
print("Warning: Nothing found in "+fn+"!")
|
print("Warning: Nothing found in "+fn+"!")
|
||||||
if not os.path.isfile(fnOut):
|
if not os.path.isfile(fnOut):
|
||||||
|
|||||||
Reference in New Issue
Block a user