strangeworks_braket package

Subpackages

Submodules

strangeworks_braket.device module

class AwsDeviceType(value)

Bases: str, Enum

Possible AWS device types

QPU = 'QPU'
SIMULATOR = 'SIMULATOR'
class StrangeworksDevice(arn: str, name: str | None = None, status: str | None = None, slug: str | None = None, noise_model: NoiseModel | None = None, **kwargs)

Bases: Device

property arn: str

Return the ARN of the device

Type:

str

property frames: dict[str, Frame]

Returns a dict mapping frame ids to the frame objects for predefined frames for this device.

property gate_calibrations: GateCalibrations | None

Calibration data for a QPU. Calibration data is shown for gates on particular gubits. # noqa If a QPU does not expose these calibrations, None is returned.

Returns:

The calibration object. Returns None if the data # noqa is not present.

Return type:

Optional[GateCalibrations]

static get_devices(arns: list[str] | None = None, names: list[str] | None = None, statuses: list[str] | None = None) list[StrangeworksDevice]

Get a list of devices. :param arns: Filter by list of device ARNs. Defaults to None. :type arns: Optional[list[str] :param names: Filter by list of device names. Defaults to None. :type names: Optional[list[str]] :param statuses: Filter by list of device statuses. Defaults to None. :type statuses: Optional[list[str]]

Returns:

devices – List of devices that match the provided filters.

Return type:

list[SwDevice]

property ports: dict[str, Port]

Returns a dict mapping port ids to the port objects for predefined ports for this device.

property properties: DeviceCapabilities

Return the device properties

Please see braket.device_schema in amazon-braket-schemas-python

Type:

DeviceCapabilities

property provider_name: str

Return the provider name

Type:

str

refresh_gate_calibrations() GateCalibrations | None

Refreshes the gate calibration data upon request.

If the device does not have calibration data, None is returned.

Raises:

URLError – If the URL provided returns a non 2xx response.

Returns:

the calibration data for the device. None is returned if the device does not have a gate calibrations URL associated.

Return type:

Optional[GateCalibrations]

refresh_metadata() None

Refresh the AwsDevice object with the most recent Device metadata.

run(task_specification: Circuit | Problem | Program | Program | PulseSequence | AnalogHamiltonianSimulation, shots: int | None = None, poll_timeout_seconds: float = 432000, poll_interval_seconds: float | None = None, inputs: dict[str, float] | None = None, gate_definitions: dict[tuple[Gate, QubitSet], PulseSequence] | None = None, reservation_arn: str | None = None, tags: list[str] | None = None, *aws_quantum_task_args: Any, **aws_quantum_task_kwargs: Any) QuantumTask

Run a task on the device. :param task_specification: The task specification. :type task_specification: Union[Circuit, Problem, OpenQasmProgram] :param shots: The number of shots to run the task for. Defaults to 1000. :type shots: Optional[int]

Returns:

task – The task that was run.

Return type:

QuantumTask (StrangeworksQuantumTask)

run_batch(task_specifications: Circuit | Problem | list[Circuit | Problem], shots: int | None, max_parallel: int | None, inputs: Dict[str, float] | list[Dict[str, float]] | None, *args, **kwargs) QuantumTaskBatch

Executes a batch of quantum tasks in parallel

Parameters:
  • task_specifications (Union[Union[Circuit, Problem], list[Union[Circuit, Problem]]]) – Single instance or list of circuits or problems to run on device.

  • shots (Optional[int]) – The number of times to run the circuit or annealing problem.

  • max_parallel (Optional[int]) – The maximum number of quantum tasks to run in parallel. Batch creation will fail if this value is greater than the maximum allowed concurrent quantum tasks on the device.

  • inputs (Optional[Union[dict[str, float], list[dict[str, float]]]]) – Inputs to be passed along with the IR. If the IR supports inputs, the inputs will be updated with this value.

  • *args (Any) – Arbitrary arguments.

  • **kwargs (Any) – Arbitrary keyword arguments.

Returns:

A batch containing all of the qauntum tasks run

Return type:

QuantumTaskBatch

run_hybrid(filepath: str, hyperparameters: Dict[str, Any], *args, **kwargs) QuantumTask

Run a task on the device. :param filepath: Path to the python file that will be run. :type filepath: str :param hyperparameters: Dictionary of hyperparameters to pass to the task.

Must be json serializable.

Returns:

Job – The job that was run.

Return type:

QuantumJob (StrangeworksQuantumJob)

property status: str

Return the status of this Device.

Returns:

The status of this Device

Return type:

str

property topology_graph: DiGraph

topology of device as a networkx DiGraph object.

Examples

>>> import networkx as nx
>>> device = AwsDevice("arn1")
>>> nx.draw_kamada_kawai(device.topology_graph, with_labels=True, font_weight="bold")  # noqa
>>> topology_subgraph = device.topology_graph.subgraph(range(8))
>>> nx.draw_kamada_kawai(topology_subgraph, with_labels=True, font_weight="bold")  # noqa
>>> print(device.topology_graph.edges)
Returns:

topology of QPU as a networkx DiGraph object. None if the topology # noqa is not available for the device.

Return type:

DiGraph

Type:

DiGraph

strangeworks_braket.job module

class StrangeworksQuantumJob(job: Job, *args, **kwargs)

Bases: QuantumTask

async_result() Task

Get the quantum task result asynchronously.

Returns:

Get the quantum task result asynchronously.

Return type:

asyncio.Task

cancel() None

Cancel the job.

Raises:
StrangeworksError

If the job has not been submitted yet.

static create(source_module: str, hyperparameters: Dict[str, Any], device: str, job_name: str) StrangeworksQuantumJob

Create a job.

Parameters:
source_module: str

The directory or single file containing the code to run.

entry_point: str

The main script or function the job will run.

hyperparameters: Dict[str, Any]

Dictionary of hyperparameters to pass to the job. Must be json serializable.

device: str

The ARN of the device to run the job on.

job_name: str

The name of the job, which will be added as a tag.

input_data: str

The input data for the job.

wait_until_complete: bool, optional

Whether to wait until the job is complete. Defaults to False.

Returns:
job: StrangeworksQuantumJob

The job.

Raises:
StrangeworksError

If the job specification is not a circuit, or openqasm program.

static create_hybrid(device_arn: str, filepath: str, hyperparameters: Dict[str, Any], device_parameters: Dict[str, Any] | None = None, tags: Dict[str, str] | None = None, *args, **kwargs) StrangeworksQuantumJob

Create a job.

Parameters:
device_arn: str

The name of the device to run the job on.

filepath: str

Path to the python file that will be run.

hyperparameters: Dict[str, Any]

Dictionary of hyperparameters to pass to the job. Must be json serializable.

device_parameters: Optional[Dict[str, Any]]

The device parameters.

tags: Optional[Dict[str, str]]

The tags to add to the strangeworks job.

Returns:
job: StrangeworksQuantumJob

The job.

Raises:
StrangeworksError

If the job specification is not a circuit, or openqasm program.

static from_strangeworks_slug(id: str) StrangeworksQuantumJob

Get a job from a strangeworks id.

Parameters:
id: str

The strangeworks id of the job.

Returns:
job: StrangeworksQuantumJob

The job.

Raises:
StrangeworksError

If no job is found for the id. Or if multiple job are found for the id.

property id: str

The id of the job.

Returns:
id: str

The id of the job. This is the id of the job in Strangeworks.

metadata(use_cached_value: bool = False) Dict[str, Any]

Get task metadata.

Parameters:

use_cached_value (bool) – If True, uses the value retrieved from the previous request. Default is False.

Returns:

The metadata regarding the quantum task. If use_cached_value is True, then the value retrieved from the most recent request is used.

Return type:

dict[str, Any]

result() Dict[str, Any]

Get the result of the job.

Returns:
result: BraketSchemaBase

The result of the job.

Raises:
StrangeworksError

If the job has not been submitted yet. Or if the job did not complete successfully. Or unable to fetch the results for the job.

state() str

Get the state of the job.

Returns:
state: str

The state of the job.

Raises:
StrangeworksError

If the job has not been submitted yet. Or if we find are not able to find the status.

strangeworks_braket.task module

class StrangeworksQuantumTask(job: Job, *args, **kwargs)

Bases: QuantumTask

async_result() Task

Get the quantum task result asynchronously.

Returns:

Get the quantum task result asynchronously.

Return type:

asyncio.Task

cancel() None

Cancel the task.

Raises:
StrangeworksError

If the task has not been submitted yet.

static create(device_arn: str, task_specification: Circuit | Problem | Program | Program | PulseSequence | AnalogHamiltonianSimulation, shots: int, device_parameters: dict[str, Any] | None = None, disable_qubit_rewiring: bool = False, tags: dict[str, str] | None = None, inputs: dict[str, float] | None = None, gate_definitions: dict[tuple[Gate, QubitSet], PulseSequence] | None = None, quiet: bool = False, reservation_arn: str | None = None, *args, **kwargs) StrangeworksQuantumTask

AwsQuantumTask factory method that serializes a quantum task specification (either a quantum circuit or annealing problem), submits it to Amazon Braket, and returns back an AwsQuantumTask tracking the execution.

Parameters:
  • aws_session (AwsSession) – AwsSession to connect to AWS with.

  • device_arn (str) – The ARN of the quantum device.

  • task_specification (Union[Circuit, Problem, OpenQASMProgram, BlackbirdProgram, PulseSequence, AnalogHamiltonianSimulation]) – # noqa The specification of the quantum task to run on device.

  • s3_destination_folder (AwsSession.S3DestinationFolder) – NamedTuple, with bucket for index 0 and key for index 1, that specifies the Amazon S3 bucket and folder to store quantum task results in.

  • shots (int) – The number of times to run the quantum task on the device. If the device is a simulator, this implies the state is sampled N times, where N = shots. shots=0 is only available on simulators and means that the simulator will compute the exact results based on the quantum task specification.

  • device_parameters (dict[str, Any] | None) – Additional parameters to send to the device.

  • disable_qubit_rewiring (bool) – Whether to run the circuit with the exact qubits chosen, without any rewiring downstream, if this is supported by the device. Only applies to digital, gate-based circuits (as opposed to annealing problems). If True, no qubit rewiring is allowed; if False, qubit rewiring is allowed. Default: False

  • tags (dict[str, str] | None) – Tags, which are Key-Value pairs to add to this quantum task. An example would be: {“state”: “washington”}

  • inputs (dict[str, float] | None) – Inputs to be passed along with the IR. If the IR supports inputs, the inputs will be updated with this value. Default: {}.

  • gate_definitions (dict[tuple[Gate, QubitSet], PulseSequence] | None) – A dict of user defined gate calibrations. Each calibration is defined for a particular Gate on a particular QubitSet and is represented by a PulseSequence. Default: None.

  • quiet (bool) – Sets the verbosity of the logger to low and does not report queue position. Default is False.

  • reservation_arn (str | None) – The reservation ARN provided by Braket Direct to reserve exclusive usage for the device to run the quantum task on. Note: If you are creating tasks in a job that itself was created reservation ARN, those tasks do not need to be created with the reservation ARN. Default: None.

Returns:

AwsQuantumTask tracking the quantum task execution on the device.

Return type:

AwsQuantumTask

Note

The following arguments are typically defined via clients of Device.
  • task_specification

  • s3_destination_folder

  • shots

See also

braket.aws.aws_quantum_simulator.AwsQuantumSimulator.run() braket.aws.aws_qpu.AwsQpu.run()

static from_strangeworks_slug(id: str) StrangeworksQuantumTask

Get a task from a strangeworks id.

Parameters:
id: str

The strangeworks id of the task.

Returns:
task: StrangeworksQuantumTask

The task.

Raises:
StrangeworksError

If no task is found for the id. Or if multiple tasks are found for the id.

property id: str

The id of the task.

Returns:
id: str

The id of the task. This is the id of the job in Strangeworks.

metadata(use_cached_value: bool = False) Dict[str, Any]

Get task metadata.

Parameters:

use_cached_value (bool) – If True, uses the value retrieved from the previous request. Default is False.

Returns:

The metadata regarding the quantum task. If use_cached_value is True, then the value retrieved from the most recent request is used.

Return type:

dict[str, Any]

result() GateModelQuantumTaskResult | AnnealingQuantumTaskResult

Get the result of the task.

Returns:
result: Union[GateModelQuantumTaskResult, AnnealingQuantumTaskResult]

The result of the task.

Raises:
StrangeworksError

If the task has not been submitted yet. Or if the task did not complete successfully. Or unable to fetch the results for the task.

state() str

Get the state of the task.

Returns:
state: str

The state of the task.

Raises:
StrangeworksError

If the task has not been submitted yet. Or if we find are not able to find the status.

Module contents

Strangeworks Braket SDK