tq42 package
Subpackages
- tq42.exceptions package
- Submodules
- tq42.exceptions.authentication_error module
- tq42.exceptions.experiment_run_cancel_error module
- tq42.exceptions.invalid_argument_error module
- tq42.exceptions.no_default_error module
- tq42.exceptions.permission_denied_error module
- tq42.exceptions.retries_exceeded_error module
- tq42.exceptions.tq42_api_error module
- tq42.exceptions.unauthenticated_error module
- Module contents
- tq42.internal package
Submodules
tq42.channel module
- class tq42.channel.Channel(client: TQ42Client, id: str)[source]
Bases:
object
Reference an existing channel with its id. A channel can be created with
create()
.- Parameters:
client – a client instance
id – existing channel id
- async connect(callback: Callable[[Ask], Awaitable[Tell]], finish_callback: Callable, max_duration_in_sec: int | None = None, message_timeout_in_sec: int | None = None) None [source]
Connects to the stream and handles every message with the provided callback to create an answer. ASK gets into the callback and then we expect a TELL answer
- Parameters:
callback – Async callback that handles an ASK message and returns a TELL message
finish_callback – Callback that is called when channel is completed
max_duration_in_sec (int) – Timeout for whole connection in seconds. None -> no timeout for overall flow
message_timeout_in_sec (int) – Timeout between messages in seconds. None -> no timeout between messages
- static create(client: TQ42Client) Channel [source]
Create a new channel
- Parameters:
client – a client instance
- Returns:
a new channel
tq42.client module
tq42.dataset module
- class tq42.dataset.Dataset(client: TQ42Client, id: str, data: StorageProto | None = None)[source]
Bases:
object
Reference an existing dataset.
- Parameters:
client – a client instance
id – the id of the existing dataset
data – only used internally
- static create(client: ~tq42.client.TQ42Client, project_id: str, name: str, description: str, sensitivity: <google.protobuf.internal.enum_type_wrapper.EnumTypeWrapper object at 0x7168c8f7a710>, file: str = None, url: str = None) Dataset [source]
Create a dataset for a project.
- Params client:
a client instance
- Parameters:
project_id – the id of the project where the dataset should be created in
name – name for the dataset
description – description for the dataset
sensitivity – sensitivity of the dataset (e.g. DatasetSensitivityProto.SENSITIVE for a sensitive dataset)
file – path to local file that should be uploaded to the dataset
url – url to remote file that should be uploaded to the dataset
- Returns:
the created dataset
Only one of url or file can be specified.
- data: StorageProto
Object containing all attributes of the dataset
tq42.experiment module
- class tq42.experiment.Experiment(client: TQ42Client, id: str, data: ExperimentProto | None = None)[source]
Bases:
object
Reference an existing experiment.
- Parameters:
client – a client instance
id – the id of the existing experiment
data – only used internally
- data: ExperimentProto
Object containing all attributes of the experiment
- set_friendly_name(friendly_name: str) Experiment [source]
Set the friendly name of the experiment
- Parameters:
friendly_name – new friendly name for the experiment
- Returns:
the updated experiment
- update(name: str) Experiment [source]
Update the name of the experiment
- Parameters:
name – new name for the experiment
- Returns:
the updated experiment
- tq42.experiment.list_all(client: TQ42Client, project_id: str | None = None) List[Experiment] [source]
List all the experiments you have permission to view within a specific project. If no project_id is specified the currently set project id will be used for this.
- Parameters:
client – a client instance
project_id – the id of the project to list experiments for (defaults to the currently set project)
- Returns:
a list of all experiments
tq42.experiment_run module
- class tq42.experiment_run.ExperimentRun(client: TQ42Client, id: str, data: ExperimentRunProto | None = None)[source]
Bases:
object
Reference an existing experiment run.
- Parameters:
client – a client instance
id – the id of the existing experiment run
data – only used internally
- cancel() ExperimentRun [source]
Cancel a run that is QUEUED, PENDING, or RUNNING.
- Returns:
the cancelled experiment run
- Raises:
ExperimentRunCancelError if the experiment run is not queued, pending or running
- check() ExperimentRun [source]
Update the state of the experiment run
- Returns:
the updated experiment run
- property completed: bool
Check if the experiment run is completed
- Returns:
true if the experiment run is in the state COMPLETED
- static create(client: ~tq42.client.TQ42Client, algorithm: str, version: str, experiment_id: str, compute: <google.protobuf.internal.enum_type_wrapper.EnumTypeWrapper object at 0x7168c8ea6e90>, parameters: ~typing.Mapping[str, ~typing.Any]) ExperimentRun [source]
Start a new experiment run in an experiment
- Parameters:
client – a client instance
algorithm – name of the algorithm (e.g. ‘TOY’)
version – version of the algorithm in the format x.y.z
experiment_id – id of the experiment in which the run should be started
compute – the hardware specification on which the run should be started (e.g. HardwareProto.SMALL)
parameters – dict with parameters for the algorithm
- Returns:
the created experiment run
- data: ExperimentRunProto
Object containing all attributes of the experiment run
- property outputs: dict[str, Any] | None
Get the outputs of the experiment run if the run is completed.
- Returns:
a dict with the outputs of the experiment run. If the run is not completed yet, returns None.
- poll(tries=1000, initial_delay=1.0, delay=1.0, backoff=1.0) ExperimentRun [source]
Monitor an experiment run until it completes, then automatically display the results (if there are no errors).
- Parameters:
tries – how many retries until the poll loop is cancelled (default: 1000)
initial_delay – initial delay before starting poll loop (default: 1 second)
delay – initial delay between retries (default: 1 second)
backoff – backoff factor between retries (default: 1)
- Returns:
the finished experiment run
- Raises:
ExceedRetriesError if tries are exceeded
- property result: dict[str, Any] | None
Get the result of the experiment run if the run is completed.
If the result contains a results_string or if the result is a string, it will be parsed and returned.
- Returns:
a dict with the result of the experiment run. If the run is not completed yet, returns None.
- tq42.experiment_run.list_all(client: TQ42Client, experiment_id: str) List[ExperimentRun] [source]
List all the runs within an experiment you have permission to view.
- Parameters:
client – a client instance
experiment_id – id of the experiment
- Returns:
a list of experiment runs
tq42.model module
- class tq42.model.Model(client: TQ42Client, id: str, data: StorageProto | None = None)[source]
Bases:
object
Reference an existing model.
- Parameters:
client – a client instance
id – the id of the existing model
data – only used internally
- data: StorageProto
Object containing all attributes of the model
tq42.organization module
- class tq42.organization.Organization(client: TQ42Client, id: str, data: OrganizationProto | None = None)[source]
Bases:
object
Reference an existing organization.
- Parameters:
client – a client instance
id – the id of the existing organization
data – only used internally
- data: OrganizationProto
Object containing all attributes of the organization
- static get_default_org(client: TQ42Client) Organization | None [source]
Gets the default organization for this user based on the default_org field
- Returns:
the default organization if one is set as a default
- set() Organization [source]
Sets the current organization as the default organization.
- Returns:
organization instance
- tq42.organization.list_all(client: TQ42Client) List[Organization] [source]
List all the organizations you have permission to view.
- Parameters:
client – a client instance
- Returns:
a list of all organizations
tq42.project module
- class tq42.project.Project(client: TQ42Client, id: str, data: ProjectProto | None = None)[source]
Bases:
object
Reference an existing project.
- Parameters:
client – a client instance
id – the id of the existing project
data – only used internally
- data: ProjectProto
Object containing all attributes of the project
- static get_default(client: TQ42Client, organization_id: str) Project | None [source]
Gets the default project in an organization
- Parameters:
client – a client instance
organization_id – the id of the organization
- Returns:
the default project if there is at least one project in the organization
- set_friendly_name(friendly_name: str) Project [source]
Set a friendly name for a project.
- Parameters:
friendly_name – new friendly name for the project
- Returns:
the updated project
- static show(client: TQ42Client) Project [source]
Returns the current default project.
- Parameters:
client – a client instance
- Raises:
NoDefaultError if no default project is set
- Returns:
the current default project
- tq42.project.list_all(client: TQ42Client, organization_id: str | None = None) List[Project] [source]
List all the projects you have permission to view within the organization.
- Parameters:
client – a client instance
organization_id – optionally an id of an organization, defaults to the default organization
- Returns:
a list of projects