Skip to content

Commit 5a7ce6b

Browse files
authored
replace .json() with .model_dump_json() (#543)
* replace .json() with .model_dump_json() * notebook cleanup
1 parent 4d4c136 commit 5a7ce6b

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

bofire/runners/run.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def autosafe_results(benchmark):
4646
filename = (
4747
"bofire_autosaves/" + benchmark_name + "/run" + str(run_idx) + ".json"
4848
)
49-
parsed_domain = benchmark.domain.json()
49+
parsed_domain = benchmark.domain.model_dump_json()
5050
with open(filename, "w") as file:
5151
json.dump(parsed_domain, file)
5252

docs/data_models_functionals.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Data models in BoFire hold static data of an optimization problem. These are input and output features as well as constraints making up the domain. They further include possible optimization objectives, acquisition functions, and kernels.
44

5-
All data models in ```bofire.data_models```, are specified as pydantic models and inherit from ```bofire.data_models.base.BaseModel```. These data models can be (de)serialized via ```.dict()``` and ```.json()``` (provided by pydantic). A json schema of each data model can be obtained using ```.schema()```.
5+
All data models in ```bofire.data_models```, are specified as pydantic models and inherit from ```bofire.data_models.base.BaseModel```. These data models can be (de)serialized via ```.dict()``` and ```.model_dump_json()``` (provided by pydantic). A json schema of each data model can be obtained using ```.schema()```.
66

77
For surrogates and strategies, all functional parts are located in ```bofire.surrogates``` and ```bofire.strategies```. These functionalities include the ```ask``` and ```tell``` as well as ```fit``` and ```predict``` methods. All class attributes (used by these method) are also removed from the data models. Each functional entity is initialized using the corresponding data model. As an example, consider the following data model of a ```RandomStrategy```:
88

@@ -37,7 +37,7 @@ import json
3737
from pydantic import parse_obj_as
3838
from bofire.data_models.strategies.api import AnyStrategy
3939

40-
serialized = data_model.json()
40+
serialized = data_model.model_dump_json()
4141
data = json.loads(serialized)
4242
# alternative: data = data_model.dict()
4343
data_model_ = parse_obj_as(AnyStrategy, data)

tutorials/serialization/models_serial.ipynb

+6-6
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@
230230
"surrogate_data = SingleTaskGPSurrogate(inputs=input_features, outputs=output_features)\n",
231231
"\n",
232232
"# we generate the json spec\n",
233-
"jspec = surrogate_data.json()\n",
233+
"jspec = surrogate_data.model_dump_json()\n",
234234
"\n",
235235
"jspec"
236236
]
@@ -515,7 +515,7 @@
515515
")\n",
516516
"\n",
517517
"# we generate the json spec\n",
518-
"jspec = surrogate_data.json()\n",
518+
"jspec = surrogate_data.model_dump_json()\n",
519519
"\n",
520520
"jspec"
521521
]
@@ -623,7 +623,7 @@
623623
")\n",
624624
"\n",
625625
"# we generate the json spec\n",
626-
"jspec = surrogate_data.json()\n",
626+
"jspec = surrogate_data.model_dump_json()\n",
627627
"\n",
628628
"jspec"
629629
]
@@ -893,7 +893,7 @@
893893
")\n",
894894
"\n",
895895
"# we generate the json spec\n",
896-
"jspec = surrogate_data.json()\n",
896+
"jspec = surrogate_data.model_dump_json()\n",
897897
"\n",
898898
"jspec"
899899
]
@@ -960,7 +960,7 @@
960960
],
961961
"metadata": {
962962
"kernelspec": {
963-
"display_name": "base",
963+
"display_name": "Python 3",
964964
"language": "python",
965965
"name": "python3"
966966
},
@@ -974,7 +974,7 @@
974974
"name": "python",
975975
"nbconvert_exporter": "python",
976976
"pygments_lexer": "ipython3",
977-
"version": "3.12.7"
977+
"version": "3.10.12"
978978
},
979979
"papermill": {
980980
"default_parameters": {},

tutorials/serialization/strategies_serial.ipynb

+4-4
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@
343343
},
344344
"outputs": [],
345345
"source": [
346-
"jsurrogate_spec = strategy_data.surrogate_specs.surrogates[0].json()\n",
346+
"jsurrogate_spec = strategy_data.surrogate_specs.surrogates[0].model_dump_json()\n",
347347
"dump = strategy.surrogates.surrogates[0].dumps()"
348348
]
349349
},
@@ -551,7 +551,7 @@
551551
" surrogate_data = strategy.surrogate_specs.surrogates[i]\n",
552552
" surrogate = strategy.surrogates.surrogates[i]\n",
553553
" # get the spec\n",
554-
" jsurrogate_spec = surrogate_data.json()\n",
554+
" jsurrogate_spec = surrogate_data.model_dump_json()\n",
555555
" # get the dump\n",
556556
" dump = surrogate.dumps()\n",
557557
" # do the cross validation, only if we have a trainable model under the hood\n",
@@ -586,7 +586,7 @@
586586
],
587587
"metadata": {
588588
"kernelspec": {
589-
"display_name": "base",
589+
"display_name": "Python 3",
590590
"language": "python",
591591
"name": "python3"
592592
},
@@ -600,7 +600,7 @@
600600
"name": "python",
601601
"nbconvert_exporter": "python",
602602
"pygments_lexer": "ipython3",
603-
"version": "3.12.7"
603+
"version": "3.10.12"
604604
},
605605
"papermill": {
606606
"default_parameters": {},

0 commit comments

Comments
 (0)