mirror of
https://github.com/vale981/two_qubit_model
synced 2025-03-04 17:21:43 -05:00
fix json decoding when loading from db
This commit is contained in:
parent
7eb02405d7
commit
3c5d373e0f
2 changed files with 6 additions and 5 deletions
|
@ -42,9 +42,11 @@ def model_db(data_path: str = "./.data"):
|
|||
db_path.touch(exist_ok=True)
|
||||
with db_path.open("r+") as f:
|
||||
data = f.read()
|
||||
db = (
|
||||
JSONEncoder.loads(data, object_hook=model_hook) if len(data) > 0 else {}
|
||||
)
|
||||
db = JSONEncoder.loads(data) if len(data) > 0 else {}
|
||||
db = {
|
||||
key: model_hook(value) if isinstance(value, dict) else value
|
||||
for key, value in db.items()
|
||||
}
|
||||
|
||||
yield db
|
||||
|
||||
|
@ -76,7 +78,7 @@ def model_hook(dct: dict[str, Any]):
|
|||
if model == "OttoEngine":
|
||||
return OttoEngine.from_dict(treated_vals)
|
||||
|
||||
return object_hook(dct)
|
||||
return dct
|
||||
|
||||
|
||||
def integrate_multi(models: Sequence[Model], *args, **kwargs):
|
||||
|
|
|
@ -63,7 +63,6 @@ class JSONEncoder(json.JSONEncoder):
|
|||
|
||||
@default.register(tuple)
|
||||
def _(self, obj: tuple):
|
||||
print("ho")
|
||||
return {
|
||||
"type": "tuple",
|
||||
"value": list(*obj),
|
||||
|
|
Loading…
Add table
Reference in a new issue