sk_builder.fileref

Providing Ref and FileRef models.

FIXME: This is a copy-paste "import" from hqs_core_models 0.8.1, to address issue when installing the device_builder using hqstage.

Copyright © 2024-2025 HQS Quantum Simulations GmbH. All Rights Reserved.

class SingleFieldBaseModel(pydantic.main.BaseModel):

A restricted base model for models with a single field.

SingleFieldBaseModel(*args, **kwargs)

Initializes a SingleFieldBaseModel instance.

Implements the following checks:

  • ensure that the subclass has only a single field.
  • ensure that the subclass has be instantiated with a single value.

NOTE: This implies that the default value for the single field of a subclass is ignored, since the user is forced to overwrite.

Raises:
  • ValueError: If subclass does not have a single field.
  • ValueError: If supplied kwargs key does not correspond to name (or alias) of the single field.
  • ValueError: If model is not in initialized with a single value.
model_config: ClassVar[pydantic.config.ConfigDict] = {}

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

class Ref(SingleFieldBaseModel):

Reference to a JSON document.

This follows the specification of https://json-schema.org/understanding-json-schema/structuring#dollarref, but we use the concept for documents themselves, and not just for JSON schemas.

We use this to properly model documents which contain references to sub-documents, such as TaskExecutionRequest optionally having the file_upload property in the form of a reference to the actual file upload document.

Ref(*args, **kwargs)

Construct a new Ref instance based on a given URL.

The constructor accepts the URL of the referenced document

  • either as a positional argument (for simple construction)
  • or as a keyword argument called "url" (for supporting explicitly naming the field),
  • or as a keyword argument called "$ref" (for pydantic validation).
Arguments:
  • *args (str): The URL of the referenced document.
  • **kwargs: Keyword arguments containing either url or $ref.
model_config: ClassVar[pydantic.config.ConfigDict] = {}

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

class FileRef(SingleFieldBaseModel):

Reference to a local or remote (binary) file.

Used to properly model a file name or URL as part of the input or output of a task, where the file is meant to be made available beyond the scope of the (local) task execution.

FileRef(*args, **kwargs)

Construct a new FileRef instance based on a local file path or a remote file URL.

The constructor accepts the path or URL of the referenced file

  • either as a positional argument (for simple construction)
  • or as a keyword argument called "filename" (for explicitly pointing to a local file),
  • or as a keyword argument called "url" (for explicitly pointing to a URL),
  • or as a keyword argument called "$file" (for pydantic validation).

In the current implementation, there is no difference between the above mentioned alternatives. This might change in the future for a smarter implementation of FileRef.

Arguments:
  • *args (str): The file path to a local file or a URL to a remote file.
  • **kwargs: Keyword arguments containing either filename, url, or $file.
model_config: ClassVar[pydantic.config.ConfigDict] = {}

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