floq.client.schemas

This module provides types definitions.

class floq.client.schemas.APIError(code: int, message: str)

Bases: object

API error response.

code

HTTP error code.

Type

int

message

Error details.

Type

str

class floq.client.schemas.BatchJobContext(circuits: List[marshmallow_dataclass.NewType.<locals>.new_type], params: List[marshmallow_dataclass.NewType.<locals>.new_type])

Bases: object

Simulation batch job context.

circuits

List of circuits to be run as a batch.

Type

List[cirq.Circuit]

params

List of parameters to be used with circuits, same size as list of circuits.

Type

List[cirq.study.Sweepable]

class floq.client.schemas.ExpectationBatchJobContext(circuits: List[marshmallow_dataclass.NewType.<locals>.new_type], params: List[marshmallow_dataclass.NewType.<locals>.new_type], operators: List[marshmallow_dataclass.NewType.<locals>.new_type])

Bases: floq.client.schemas.BatchJobContext

Expectation values batch job context.

operators

List of list of cirq.ops.PauliSum operators, same size as list of circuits.

Type

List[List[cirq.ops.PauliSum]]

class floq.client.schemas.ExpectationBatchJobResult(id: uuid.UUID, status: floq.client.schemas.JobStatus, error_message: Optional[str] = None, progress: Optional[floq.client.schemas.JobProgress] = None, result: Optional[List[List[List[float]]]] = None)

Bases: floq.client.schemas.JobResult

Expectation values batch job result.

result

List of expectation values list, same size as number of circuits. Each element has the outer size of input sweep parameters and the inner size of input operators size.

Type

Optional[List[List[List[float]]]]

class floq.client.schemas.ExpectationJobContext(circuit: marshmallow_dataclass.NewType.<locals>.new_type, param_resolver: marshmallow_dataclass.NewType.<locals>.new_type, operators: marshmallow_dataclass.NewType.<locals>.new_type)

Bases: floq.client.schemas.JobContext

Expectation values job context.

operators

List of cirq.ops.PauliSum operators.

Type

cirq.ops.PauliSum

class floq.client.schemas.ExpectationJobResult(id: uuid.UUID, status: floq.client.schemas.JobStatus, error_message: Optional[str] = None, progress: Optional[floq.client.schemas.JobProgress] = None, result: Optional[List[float]] = None)

Bases: floq.client.schemas.JobResult

Expectation values job result.

result

List of floats, same size as input operators size.

Type

Optional[List[float]]

class floq.client.schemas.ExpectationJobStatusEvent(id: uuid.UUID, data: Union[floq.client.schemas.ExpectationJobResult, floq.client.schemas.ExpectationBatchJobResult, floq.client.schemas.ExpectationSweepJobResult], event: str = '', timestamp: int = 0)

Bases: floq.client.schemas.JobStatusEvent

Expectation job status changed event.

data

Expectation job result.

Type

Union[floq.client.schemas.ExpectationJobResult, floq.client.schemas.ExpectationBatchJobResult, floq.client.schemas.ExpectationSweepJobResult]

class floq.client.schemas.ExpectationSweepJobContext(circuit: marshmallow_dataclass.NewType.<locals>.new_type, params: marshmallow_dataclass.NewType.<locals>.new_type, operators: marshmallow_dataclass.NewType.<locals>.new_type)

Bases: floq.client.schemas.SweepJobContext

Expectation values sweep job context.

operators

List of cirq.ops.PauliSum operators, same size as list of circuits.

Type

List[cirq.ops.PauliSum]

class floq.client.schemas.ExpectationSweepJobResult(id: uuid.UUID, status: floq.client.schemas.JobStatus, error_message: Optional[str] = None, progress: Optional[floq.client.schemas.JobProgress] = None, result: Optional[List[List[float]]] = None)

Bases: floq.client.schemas.JobResult

Expectation values sweep job result.

result

List of expectation values list. The outer size is the same as input sweep size, the inner size is the same size as input operators size.

Type

Optional[List[List[float]]]

class floq.client.schemas.JobContext(circuit: marshmallow_dataclass.NewType.<locals>.new_type, param_resolver: marshmallow_dataclass.NewType.<locals>.new_type)

Bases: object

Simulation job context.

circuit

Circuit to be run.

Type

cirq.Circuit

param_resolver

ParamResolver to be used with the circuit.

Type

cirq.ParamResolver

class floq.client.schemas.JobProgress(completed: int = 0, total: int = 1)

Bases: object

Job computation progress.

current

Number of completed work units.

total

Total number of work units.

Type

int

class floq.client.schemas.JobResult(id: uuid.UUID, status: floq.client.schemas.JobStatus, error_message: Optional[str] = None, progress: Optional[floq.client.schemas.JobProgress] = None, result: Optional[Any] = None)

Bases: object

Simulation job result.

id

Unique job id.

Type

uuid.UUID

status

Current job status.

Type

floq.client.schemas.JobStatus

error_message

Optional error message explaining why the computation failed, only set if the status is floq.client.schemas.JobStatus.ERROR.

Type

Optional[str]

progress

Optional computation progress, only set if the status is floq.client.schemas.JobStatus.IN_PROGRESS.

Type

Optional[floq.client.schemas.JobProgress]

result

Optional simulation job result, only set if the status is floq.client.schemas.JobStatus.COMPLETE.

Type

Optional[Any]

class floq.client.schemas.JobStatus(value)

Bases: enum.IntEnum

Current job status.

NOT_STARTED

The job was added to the queue.

IN_PROGRESS

The job is being processed.

COMPLETE

Simulation has been completed successfully.

ERROR

Simulation has failed.

class floq.client.schemas.JobStatusEvent(id: uuid.UUID, data: floq.client.schemas.JobResult, event: str = '', timestamp: int = 0)

Bases: floq.client.schemas.ServerSideEvent

Job status changed event.

data

Simulation job result.

Type

floq.client.schemas.JobResult

class floq.client.schemas.JobSubmitted(id: uuid.UUID)

Bases: object

Submitted job.

id

Unique job id.

Type

uuid.UUID

class floq.client.schemas.JobType(value)

Bases: enum.IntEnum

Simulation job type.

SAMPLE

Sampling.

EXPECTATION

Expectation values.

NOISY_EXPECTATION

Noisy expectation values.

class floq.client.schemas.JobsQueue(ids: List[uuid.UUID] = <factory>)

Bases: object

Current status of jobs queue.

ids

List of pending jobs ids.

Type

List[uuid.UUID]

class floq.client.schemas.PendingJob(id: uuid.UUID, status: floq.client.schemas.JobStatus, type: floq.client.schemas.JobType)

Bases: object

Queued job details.

id

Unique job id.

Type

uuid.UUID

status

Current job status.

Type

floq.client.schemas.JobStatus

type

Job type.

Type

floq.client.schemas.JobType

class floq.client.schemas.SampleBatchJobContext(circuits: List[marshmallow_dataclass.NewType.<locals>.new_type], params: List[marshmallow_dataclass.NewType.<locals>.new_type], repetitions: Union[int, List[int]])

Bases: floq.client.schemas.BatchJobContext

Sample batch job context.

repetitions

Number of times the circuits will run. Can be specified as a single value or list of same size as input circuits.

Type

Union[int, List[int]]

class RepetitionsValidator

Bases: marshmallow.validate.Validator

A Helper class for validating repetitions field value.

class floq.client.schemas.SampleBatchJobResult(id: uuid.UUID, status: floq.client.schemas.JobStatus, error_message: Optional[str] = None, progress: Optional[floq.client.schemas.JobProgress] = None, result: Optional[List[List[marshmallow_dataclass.NewType.<locals>.new_type]]] = None)

Bases: floq.client.schemas.JobResult

Sample batch job result.

result

Output from running the circuit.

Type

Optional[List[List[cirq.Result]]]

class floq.client.schemas.SampleJobContext(circuit: marshmallow_dataclass.NewType.<locals>.new_type, param_resolver: marshmallow_dataclass.NewType.<locals>.new_type, repetitions: int = 1)

Bases: floq.client.schemas.JobContext

Sample job context.

repetitions

Number of times the circuit will run.

Type

int

class floq.client.schemas.SampleJobResult(id: uuid.UUID, status: floq.client.schemas.JobStatus, error_message: Optional[str] = None, progress: Optional[floq.client.schemas.JobProgress] = None, result: Optional[marshmallow_dataclass.NewType.<locals>.new_type] = None)

Bases: floq.client.schemas.JobResult

Sample job result.

result

Output from running the circuit.

Type

Optional[marshmallow_dataclass.NewType.<locals>.new_type]

class floq.client.schemas.SampleJobStatusEvent(id: uuid.UUID, data: Union[floq.client.schemas.SampleJobResult, floq.client.schemas.SampleBatchJobResult, floq.client.schemas.SampleSweepJobResult], event: str = '', timestamp: int = 0)

Bases: floq.client.schemas.JobStatusEvent

Sample job status changed event.

data

Sample job result.

Type

Union[floq.client.schemas.SampleJobResult, floq.client.schemas.SampleBatchJobResult, floq.client.schemas.SampleSweepJobResult]

class floq.client.schemas.SampleSweepJobContext(circuit: marshmallow_dataclass.NewType.<locals>.new_type, params: marshmallow_dataclass.NewType.<locals>.new_type, repetitions: int = 1)

Bases: floq.client.schemas.SweepJobContext

Sample sweep job context.

repetitions

Number of times the circuit will run.

Type

int

class floq.client.schemas.SampleSweepJobResult(id: uuid.UUID, status: floq.client.schemas.JobStatus, error_message: Optional[str] = None, progress: Optional[floq.client.schemas.JobProgress] = None, result: Optional[List[marshmallow_dataclass.NewType.<locals>.new_type]] = None)

Bases: floq.client.schemas.JobResult

Sample sweep job result.

result

Output from running the circuit.

Type

Optional[List[marshmallow_dataclass.NewType.<locals>.new_type]]

class floq.client.schemas.ServerSideEvent(id: uuid.UUID, data: Any, event: str = '', timestamp: int = 0)

Bases: object

Base class for server side event.

Both event and timestamp fields are auto-populated if using default values:

  • event is set to the class name

  • timestamp is set to the current time

id

Event unique id.

Type

uuid.UUID

data

Event payload.

Type

Any

event

Event name.

Type

str

timestamp

Event timestamp (in UNIX seconds).

Type

int

class floq.client.schemas.StreamTimeoutEvent(id: uuid.UUID, data: Optional[Any] = None, event: str = '', timestamp: int = 0)

Bases: floq.client.schemas.ServerSideEvent

Server side event that indicates the stream connection reached the maximum timeout (10 minutes).

class floq.client.schemas.SweepJobContext(circuit: marshmallow_dataclass.NewType.<locals>.new_type, params: marshmallow_dataclass.NewType.<locals>.new_type)

Bases: object

Simulation sweep job context.

circuit

Circuit to be run.

Type

cirq.Circuit

params

Parameters to be used with the circuit.

Type

cirq.study.Sweepable

class floq.client.schemas.TaskState(value)

Bases: enum.IntEnum

Current task state.

PENDING

Task is scheduled for execution.

RUNNING

Task is running.

DONE

Task is finished.

class floq.client.schemas.TaskStatus(state: floq.client.schemas.TaskState, error: Optional[str] = None, success: Optional[bool] = None)

Bases: object

Current task status.

state

Current task state.

Type

floq.client.schemas.TaskState

error

Optional error message explaining why the task failed, only set if the state is floq.client.schemas.TaskState.DONE and the success flag is False.

Type

Optional[str]

success

Optional flag indicating whether task finished successfully, only set if the task state is floq.client.schemas.TaskState.DONE.

Type

Optional[bool]

class floq.client.schemas.TaskStatusEvent(id: uuid.UUID, data: floq.client.schemas.TaskStatus, event: str = '', timestamp: int = 0)

Bases: floq.client.schemas.ServerSideEvent

Task status changed event.

data

Task status.

Type

floq.client.schemas.TaskStatus

class floq.client.schemas.TaskSubmitted(id: uuid.UUID)

Bases: object

Submitted task.

id

Unique task id.

Type

uuid.UUID

class floq.client.schemas.Worker(state: floq.client.schemas.WorkerState, error: Optional[str] = None, job_id: Optional[uuid.UUID] = None)

Bases: object

Current status of the TPU worker.

state

Current worker state.

Type

floq.client.schemas.WorkerState

error

Optional error message explaining problem with the worker, only set when the state is floq.client.schemas.WorkerState.ERROR.

Type

Optional[str]

job_id

Currently processed job id, only set when the state is floq.client.schemas.WorkerState.PROCESSING_JOB.

Type

Optional[uuid.UUID]

class floq.client.schemas.WorkerState(value)

Bases: enum.IntEnum

TPU worker state.

BOOTING

Worker is booting.

ERROR

Worker encountered an error.

IDLE

Worker is idling.

OFFLINE

Worker is offline.

PROCESSING_JOB

Worker is processing a job.

SHUTTING_DOWN

Worker is shutting down.

floq.client.schemas.decode(schema: marshmallow.schema.Schema, data: str, **kwargs) dataclasses.dataclass

Decodes input string using provided schema.

Parameters
  • schema – Schema to be used for deserialization.

  • data – JSON-encoded data to be deserialized.

  • **kwargs – Extra keyworded arguments to be passed to marshmallow.Schemas.loads method.

Returns

Deserialized dataclasses.dataclass object.

floq.client.schemas.encode(schema: marshmallow.schema.Schema, data: dataclasses.dataclass, **kwargs) str

Encodes input data using provided schema.

Parameters
  • schema – Schema to be used for serialization.

  • data – Dataclass object to be serialized.

  • **kwargs – Extra keyworded arguments to be passed to marshmallow.Schemas.dumps method.

Returns

JSON-encoded serialized data.