-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Physics class + Lassen compatibility (#2)
* physics class * generalized physics solution shape in latent space. * minor * updated README * activation for autoencoder * lassen compatible.
- Loading branch information
1 parent
4ebad94
commit 9b4cb93
Showing
11 changed files
with
538 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ examples/data | |
examples/results | ||
examples/checkpoint | ||
*.npy | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from warnings import warn | ||
|
||
verbose = False | ||
|
||
class InputParser: | ||
dict_ = None | ||
name = "" | ||
|
||
def __init__(self, dict, name = ""): | ||
from copy import deepcopy | ||
self.dict_ = deepcopy(dict) | ||
self.name = name | ||
return | ||
|
||
def getInput(self, keys, fallback=None, datatype=None): | ||
''' | ||
Find the value corresponding to the list of keys. | ||
If the specified keys do not exist, use the fallback value. | ||
If the fallback value does not exist, returns an error. | ||
If the datatype is specified, enforce the output value has the right datatype. | ||
''' | ||
keyString = "" | ||
for key_ in keys: | ||
keyString += key_ + "/" | ||
|
||
val = self.dict_ | ||
for key in keys: | ||
if key in val: | ||
val = val[key] | ||
elif (fallback != None): | ||
return fallback | ||
else: | ||
raise RuntimeError("%s does not exist in the input dictionary %s!" % (keyString, self.name)) | ||
|
||
if (fallback != None): | ||
if (type(val) != type(fallback)): | ||
raise RuntimeError("%s does not match the type with the fallback value %s!" % (str(type(val)), str(type(fallback)))) | ||
elif (datatype != None): | ||
if (type(val) != datatype): | ||
raise RuntimeError("%s does not match the specified datatype %s!" % (str(type(val)), str(datatype))) | ||
else: | ||
if verbose: warn("InputParser Warning: datatype is not checked.\n key: %s\n value type: %s" % (keys, type(val))) | ||
return val | ||
|
||
def getDictFromList(list_, inputDict): | ||
''' | ||
get a dict with {key: val} from a list of dicts | ||
NOTE: it returns only the first item in the list, | ||
even if the list has more than one dict with {key: val}. | ||
''' | ||
dict_ = None | ||
for item in list_: | ||
isDict = True | ||
for key, val in inputDict.items(): | ||
if key not in item: | ||
isDict = False | ||
break | ||
if (item[key] != val): | ||
isDict = False | ||
break | ||
if (isDict): | ||
dict_ = item | ||
break | ||
if (dict_ == None): | ||
raise RuntimeError('Given list does not have a dict with {%s: %s}!' % (key, val)) | ||
return dict_ |
Oops, something went wrong.