Json
ConfigSpace.read_and_write.json
#
read
#
read(
jason_string: str,
decoders: (
Mapping[
Literal[
"hyperparameters",
"conditions",
"forbiddens",
],
Mapping[str, _Decoder],
]
| None
) = None,
) -> ConfigurationSpace
Create a configuration space definition from a json string.
from ConfigSpace import ConfigurationSpace
from ConfigSpace.read_and_write import json as cs_json
cs = ConfigurationSpace({"a": [1, 2, 3]})
cs_string = cs_json.write(cs)
with open('configspace.json', 'w') as f:
f.write(cs_string)
with open('configspace.json', 'r') as f:
json_string = f.read()
config = cs_json.read(json_string)
PARAMETER | DESCRIPTION |
---|---|
jason_string |
A json string representing a configuration space definition
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ConfigurationSpace
|
The deserialized ConfigurationSpace object |
Source code in src/ConfigSpace/read_and_write/json.py
write
#
write(
space: ConfigurationSpace,
indent: int = 2,
encoders: (
Mapping[type, tuple[str, _Encoder]] | None
) = None,
) -> str
Create a string representation of a ConfigurationSpace in json format. This string can be written to file.
from ConfigSpace import ConfigurationSpace
from ConfigSpace.read_and_write import json as cs_json
cs = ConfigurationSpace({"a": [1, 2, 3]})
with open('configspace.json', 'w') as f:
f.write(cs_json.write(cs))
PARAMETER | DESCRIPTION |
---|---|
space |
A configuration space, which should be written to file.
TYPE:
|
indent |
number of whitespaces to use as indent
TYPE:
|
encoders |
Additional encoders to include where they key is a type to which the encoder applies to and the value is a tuple, where the first element is the type name to include in the dictionary and the second element is the encoder function which gives back a serializable dictionary.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
String representation of the configuration space, which can be written to file |