qxmt.configs module

qxmt.configs module#

class qxmt.configs.DatasetConfig(*, openml=None, file=None, generate=None, random_seed, split, features=None, raw_preprocess_logic=None, transform_logic=None)

Bases: BaseModel

Parameters:
  • openml (OpenMLConfig | None)

  • file (FileConfig | None)

  • generate (GenerateDataConfig | None)

  • random_seed (int)

  • split (SplitConfig)

  • features (list[str] | None)

  • raw_preprocess_logic (list[dict[str, Any]] | dict[str, Any] | None)

  • transform_logic (list[dict[str, Any]] | dict[str, Any] | None)

features: list[str] | None
file: FileConfig | None
generate: GenerateDataConfig | None
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'features': FieldInfo(annotation=Union[list[str], NoneType], required=False, default=None), 'file': FieldInfo(annotation=Union[FileConfig, NoneType], required=False, default=None), 'generate': FieldInfo(annotation=Union[GenerateDataConfig, NoneType], required=False, default=None), 'openml': FieldInfo(annotation=Union[OpenMLConfig, NoneType], required=False, default=None), 'random_seed': FieldInfo(annotation=int, required=True), 'raw_preprocess_logic': FieldInfo(annotation=Union[list[dict[str, Any]], dict[str, Any], NoneType], required=False, default=None), 'split': FieldInfo(annotation=SplitConfig, required=True), 'transform_logic': FieldInfo(annotation=Union[list[dict[str, Any]], dict[str, Any], NoneType], required=False, default=None)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

openml: OpenMLConfig | None
random_seed: int
raw_preprocess_logic: list[dict[str, Any]] | dict[str, Any] | None
split: SplitConfig
transform_logic: list[dict[str, Any]] | dict[str, Any] | None
class qxmt.configs.DeviceConfig(*, platform, name, n_qubits, shots=None, save_shots_results=False)

Bases: BaseModel

Parameters:
  • platform (str)

  • name (str)

  • n_qubits (int)

  • shots (int | None)

  • save_shots_results (bool)

check_save_shots()
Return type:

DeviceConfig

classmethod check_shots(value)
Parameters:

value (int)

Return type:

int

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'n_qubits': FieldInfo(annotation=int, required=True), 'name': FieldInfo(annotation=str, required=True), 'platform': FieldInfo(annotation=str, required=True), 'save_shots_results': FieldInfo(annotation=bool, required=False, default=False), 'shots': FieldInfo(annotation=Union[int, NoneType], required=False, default=None)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

n_qubits: int
name: str
platform: str
save_shots_results: bool
shots: int | None
class qxmt.configs.EvaluationConfig(*, default_metrics, custom_metrics=None)

Bases: BaseModel

Parameters:
  • default_metrics (list[str])

  • custom_metrics (list[dict[str, Any]] | None)

custom_metrics: list[dict[str, Any]] | None
default_metrics: list[str]
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'custom_metrics': FieldInfo(annotation=Union[list[dict[str, Any]], NoneType], required=False, default=None), 'default_metrics': FieldInfo(annotation=list[str], required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

class qxmt.configs.ExperimentConfig(*, path='', description='', global_settings, dataset, device, feature_map=None, kernel=None, model, evaluation)

Bases: BaseModel

Parameters:
__init__(**data)

Initialize the experiment configuration.

Case 1:

Load the configuration from a file path. This case the data is a dictionary with a single key “path”.

Case 2:

Load the configuration from a dictionary. This case the data is a dictionary with the configuration data.

Parameters:

data (Any)

Return type:

None

dataset: DatasetConfig
description: str
device: DeviceConfig
evaluation: EvaluationConfig
feature_map: FeatureMapConfig | None
global_settings: GlobalSettingsConfig
kernel: KernelConfig | None
load_from_path(path)
Parameters:

path (str)

Return type:

dict[str, Any]

model: ModelConfig
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'dataset': FieldInfo(annotation=DatasetConfig, required=True), 'description': FieldInfo(annotation=str, required=False, default=''), 'device': FieldInfo(annotation=DeviceConfig, required=True), 'evaluation': FieldInfo(annotation=EvaluationConfig, required=True), 'feature_map': FieldInfo(annotation=Union[FeatureMapConfig, NoneType], required=False, default=None), 'global_settings': FieldInfo(annotation=GlobalSettingsConfig, required=True), 'kernel': FieldInfo(annotation=Union[KernelConfig, NoneType], required=False, default=None), 'model': FieldInfo(annotation=ModelConfig, required=True), 'path': FieldInfo(annotation=Union[Path, str], required=False, default='')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

path: Path | str
class qxmt.configs.FeatureMapConfig(*, module_name, implement_name, params=None)

Bases: BaseModel

Parameters:
  • module_name (str)

  • implement_name (str)

  • params (dict[str, Any] | None)

implement_name: str
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'implement_name': FieldInfo(annotation=str, required=True), 'module_name': FieldInfo(annotation=str, required=True), 'params': FieldInfo(annotation=Union[dict[str, Any], NoneType], required=False, default=None)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

module_name: str
params: dict[str, Any] | None
class qxmt.configs.FileConfig(*, data_path, label_path, label_name)

Bases: BaseModel

Parameters:
  • data_path (Path | str)

  • label_path (Path | str | None)

  • label_name (str | None)

data_path: Path | str
label_name: str | None
label_path: Path | str | None
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'data_path': FieldInfo(annotation=Union[Path, str], required=True), 'label_name': FieldInfo(annotation=Union[str, NoneType], required=True), 'label_path': FieldInfo(annotation=Union[Path, str, NoneType], required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

model_post_init(_FileConfig__context)

Override this method to perform additional initialization after __init__ and model_construct. This is useful if you want to do some validation that requires the entire model to be initialized.

Parameters:

_FileConfig__context (dict[str, Any])

Return type:

None

class qxmt.configs.GenerateDataConfig(*, generate_method, params={})

Bases: BaseModel

Parameters:
  • generate_method (Literal['linear'])

  • params (dict[str, Any] | None)

generate_method: Literal['linear']
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'generate_method': FieldInfo(annotation=Literal['linear'], required=True), 'params': FieldInfo(annotation=Union[dict[str, Any], NoneType], required=False, default={})}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

params: dict[str, Any] | None
class qxmt.configs.GlobalSettingsConfig(*, random_seed, task_type)

Bases: BaseModel

Parameters:
  • random_seed (int)

  • task_type (Literal['classification', 'regression'])

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'random_seed': FieldInfo(annotation=int, required=True), 'task_type': FieldInfo(annotation=Literal['classification', 'regression'], required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

random_seed: int
task_type: Literal['classification', 'regression']
class qxmt.configs.KernelConfig(*, module_name, implement_name, params=None)

Bases: BaseModel

Parameters:
  • module_name (str)

  • implement_name (str)

  • params (dict[str, Any] | None)

implement_name: str
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'implement_name': FieldInfo(annotation=str, required=True), 'module_name': FieldInfo(annotation=str, required=True), 'params': FieldInfo(annotation=Union[dict[str, Any], NoneType], required=False, default=None)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

module_name: str
params: dict[str, Any] | None
class qxmt.configs.ModelConfig(*, name, params, feature_map=None, kernel=None)

Bases: BaseModel

Parameters:
feature_map: FeatureMapConfig | None
kernel: KernelConfig | None
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'feature_map': FieldInfo(annotation=Union[FeatureMapConfig, NoneType], required=False, default=None), 'kernel': FieldInfo(annotation=Union[KernelConfig, NoneType], required=False, default=None), 'name': FieldInfo(annotation=str, required=True), 'params': FieldInfo(annotation=dict[str, Any], required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

name: str
params: dict[str, Any]
class qxmt.configs.OpenMLConfig(*, name=None, id=None, return_format='numpy', save_path=None)

Bases: BaseModel

Parameters:
  • name (str | None)

  • id (int | None)

  • return_format (str)

  • save_path (Path | str | None)

id: int | None
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'id': FieldInfo(annotation=Union[int, NoneType], required=False, default=None), 'name': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'return_format': FieldInfo(annotation=str, required=False, default='numpy'), 'save_path': FieldInfo(annotation=Union[Path, str, NoneType], required=False, default=None)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

model_post_init(_OpenMLConfig__context)

Override this method to perform additional initialization after __init__ and model_construct. This is useful if you want to do some validation that requires the entire model to be initialized.

Parameters:

_OpenMLConfig__context (dict[str, Any])

Return type:

None

name: str | None
return_format: str
save_path: Path | str | None
class qxmt.configs.SplitConfig(*, train_ratio, validation_ratio=0.0, test_ratio, shuffle=True)

Bases: BaseModel

Parameters:
  • train_ratio (Annotated[float, Ge(ge=0.0), Le(le=1.0)])

  • validation_ratio (Annotated[float, Ge(ge=0.0), Le(le=1.0)])

  • test_ratio (Annotated[float, Ge(ge=0.0), Le(le=1.0)])

  • shuffle (bool)

check_ratio()
Return type:

SplitConfig

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'shuffle': FieldInfo(annotation=bool, required=False, default=True), 'test_ratio': FieldInfo(annotation=float, required=True, metadata=[Ge(ge=0.0), Le(le=1.0)]), 'train_ratio': FieldInfo(annotation=float, required=True, metadata=[Ge(ge=0.0), Le(le=1.0)]), 'validation_ratio': FieldInfo(annotation=float, required=False, default=0.0, metadata=[Ge(ge=0.0), Le(le=1.0)])}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

shuffle: bool
test_ratio: float
train_ratio: float
validation_ratio: float