mirror of
https://github.com/LCPQ/quantum_package
synced 2025-05-06 15:14:50 +02:00
Add pickle to ezfio_interface.py
This commit is contained in:
parent
69490976fd
commit
91ac5cc2a8
@ -51,6 +51,10 @@ Type = namedtuple('Type', 'ocaml fortran')
|
|||||||
|
|
||||||
|
|
||||||
def is_bool(str_):
|
def is_bool(str_):
|
||||||
|
"""
|
||||||
|
Take a string, if is a bool return the convert into
|
||||||
|
fortran and ocaml one.
|
||||||
|
"""
|
||||||
if str_.lower() in ['true', '.true.']:
|
if str_.lower() in ['true', '.true.']:
|
||||||
return Type("true", ".True.")
|
return Type("true", ".True.")
|
||||||
elif str_.lower() in ['false', '.False.']:
|
elif str_.lower() in ['false', '.False.']:
|
||||||
@ -67,6 +71,21 @@ def get_type_dict():
|
|||||||
For example fancy_type['Ndet'].fortran = interger
|
For example fancy_type['Ndet'].fortran = interger
|
||||||
.ocaml = int
|
.ocaml = int
|
||||||
"""
|
"""
|
||||||
|
# ~#~#~#~#~ #
|
||||||
|
# P i c l e #
|
||||||
|
# ~#~#~#~#~ #
|
||||||
|
|
||||||
|
import cPickle as pickle
|
||||||
|
|
||||||
|
from os import listdir
|
||||||
|
|
||||||
|
qpackage_root = os.environ['QPACKAGE_ROOT']
|
||||||
|
|
||||||
|
fancy_type_pickle = qpackage_root + "/scripts/fancy_type.p"
|
||||||
|
|
||||||
|
if fancy_type_pickle in listdir(os.getcwd()):
|
||||||
|
fancy_type = pickle.load(open(fancy_type_pickle, "rb"))
|
||||||
|
return fancy_type
|
||||||
|
|
||||||
# ~#~#~#~ #
|
# ~#~#~#~ #
|
||||||
# I n i t #
|
# I n i t #
|
||||||
@ -102,7 +121,7 @@ def get_type_dict():
|
|||||||
"string": "character*32"}
|
"string": "character*32"}
|
||||||
|
|
||||||
# Read and parse qptype
|
# Read and parse qptype
|
||||||
src = os.environ['QPACKAGE_ROOT'] + "/ocaml/qptypes_generator.ml"
|
src = qpackage_root + "/ocaml/qptypes_generator.ml"
|
||||||
with open(src, "r") as f:
|
with open(src, "r") as f:
|
||||||
l = [i for i in f.read().splitlines() if i.strip().startswith("*")]
|
l = [i for i in f.read().splitlines() if i.strip().startswith("*")]
|
||||||
|
|
||||||
@ -114,6 +133,12 @@ def get_type_dict():
|
|||||||
|
|
||||||
fancy_type[str_fancy_type] = Type(str_ocaml_type, str_fortran_type)
|
fancy_type[str_fancy_type] = Type(str_ocaml_type, str_fortran_type)
|
||||||
|
|
||||||
|
# ~#~#~#~#~#~#~#~ #
|
||||||
|
# F i n a l i z e #
|
||||||
|
# ~#~#~#~#~#~#~#~ #
|
||||||
|
|
||||||
|
pickle.dump(dict(fancy_type), open(fancy_type_pickle, "wb"))
|
||||||
|
|
||||||
return dict(fancy_type)
|
return dict(fancy_type)
|
||||||
|
|
||||||
|
|
||||||
@ -217,7 +242,7 @@ def get_dict_config_file(config_file_path, module_lower):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
d[pvd]["default"] = is_bool(default_raw)
|
d[pvd]["default"] = is_bool(default_raw)
|
||||||
except:
|
except TypeError:
|
||||||
d[pvd]["default"] = Type(default_raw, default_raw)
|
d[pvd]["default"] = Type(default_raw, default_raw)
|
||||||
|
|
||||||
return dict(d)
|
return dict(d)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user