Skip to main content

Strangeworks-Wolfram

The strangeworks-wolfram package allows Wolfram Mathematica users to communicate with the Strangeworks platform. This allows users to submit jobs to gate based quantum hardware as well to a wider range of alternative compute providers, see full catalog.

Installation

A user must go through the following steps to be able to run jobs

🥳 Success! You may view your job in the portal.

😅 Something went wrong? Find us in Slack!

Usage

IBM

Here's a simple example of creating a Bell state with IBM.

Before running follow the installation steps above:

IBM: Hello World

(* Install QuantumFramework *)
PacletInstall["Wolfram/QuantumFramework", ForceVersionInstall -> True]
<< Wolfram`QuantumFramework`;

(* Install Strangeworks Extension *)
PacletInstall["Strangeworks/Strangeworks", ForceVersionInstall -> True]
<< Strangeworks`Strangeworks`;

(* Define quantum circuit using the QuantumFrameworks *)
ops = {QuantumOperator["H", {1}],
QuantumOperator["CX", {1, 2}], {1}, {2}};
qc = QuantumCircuitOperator[ops]; qc["Diagram"]

(* User must input their own apikey and resourceslug, see installation instructions above *)
apikey = "";
resourceslug = "";
productslug = "ibm-qiskit-runtime";

authstatus = AuthenticateSW[apikey]
resourcestatus = GetResourceSW[resourceslug, productslug]

(* Display backends available to the user *)
backends = BackendsSW[]

(* Run on the simulator *)
backend = "ibmq_qasm_simulator";
shots = 100;
swjob = RunSW[qc, backend, shots]
jobslug = Part[swjob, 2]

(* Check on the status of the job *)
status = StatusSW[jobslug]

(* Get the results *)
result = ResultSW[jobslug];

(* Plot the results *)
histogramSW[Part[result, 2]]

🥳 Success! You may view your job in the portal.

😅 Something went wrong? Find us in Slack!

AWS Braket

Here's a simple example of creating a Bell state with AWS Braket.

Before running follow the installation steps above, but you will also need to add the AWS Braket resource on the platform. To do that complete the billing account details on the paltform page and also contact hello@strangeworks.com to begin the process.

AWS: Hello World

(* Install QuantumFramework *)
PacletInstall["Wolfram/QuantumFramework", ForceVersionInstall -> True]
<< Wolfram`QuantumFramework`;

(* Install Strangeworks Extension *)
PacletInstall["Strangeworks/Strangeworks", ForceVersionInstall -> True]
<< Strangeworks`Strangeworks`;

(* Define quantum circuit using the QuantumFrameworks *)
ops = {QuantumOperator["H", {1}],
QuantumOperator["CX", {1, 2}], {1}, {2}};
qc = QuantumCircuitOperator[ops]; qc["Diagram"]

(* User must input their own apikey and resourceslug, see installation instructions above *)
apikey = "";
resourceslug = "";
productslug = "amazon-braket";

authstatus = AuthenticateSW[apikey]
resourcestatus = GetResourceSW[resourceslug, productslug]

(* Display backends available to the user *)
backends = BackendsSW[]

(* Run on the simulator *)
backend = "arn:aws:braket:::device/quantum-simulator/amazon/sv1";
shots = 100;
swjob = RunSW[qc, backend, shots]
jobslug = Part[swjob, 2]

(* Check on the status of the job *)
status = StatusSW[jobslug]

(* Get the results *)
result = ResultSW[jobslug];

(* Plot the results *)
histogramSW[Part[result, 2]]

🥳 Success! You may view your job in the portal.

😅 Something went wrong? Find us in Slack!

Optimization Service

Here's a simple example of solving a QUBO matrix with our quantum and quantum inspired solvers.

Before running follow the installation steps above, but you will also need to add the Optimization resource on the platform. To do that complete the billing account details on the paltform page and also contact hello@strangeworks.com to begin the process.

Opt: Hello World

(* Install QuantumFramework *)
PacletInstall["Wolfram/QuantumFramework", ForceVersionInstall -> True]
<< Wolfram`QuantumFramework`;

(* Install Strangeworks Extension *)
PacletInstall["Strangeworks/Strangeworks", ForceVersionInstall -> True]
<< Strangeworks`Strangeworks`;

(* Define a qubo matrix to optimize *)
Q = {{-2, 2, 2, 0, 0}, {0, -2, 0, 2, 0}, {0, 0, -2, 2, 2}, {0, 0,
0, -2, 2}, {0, 0, 0, 0, -2}};
Q // MatrixForm

(* User must input their own apikey and resourceslug, see installation instructions above *)
apikey = "";
resourceslug = ""; (* slug for the optimization resource *)
productslug = "optimization";

authstatus = AuthenticateSW[apikey]
resourcestatus = GetResourceSW[resourceslug, productslug]

(* Display backends available to the user *)
backends = BackendsSW[]

(* Run on the Dwave *)
backend = "dwave.Advantage_system6.2";
childresourceslug = ""; (* slug for the child job resource, i.e. dwave, gurobi, jij etc. *)

jobslug = RunSWOpt[Q, childresourceslug, backend]

(* Get the results *)
result = ResultSW[jobslug];

🥳 Success! You may view your job in the portal.

😅 Something went wrong? Find us in Slack!

QAOA Service

Here's a simple example of solving a QUBO matrix with our QAOA Service.

Before running follow the installation steps above, but you will also need to add the QAOA resource on the platform. To do that complete the billing account details on the paltform page and also contact hello@strangeworks.com to begin the process.

QAOA: Hello World

(* Install QuantumFramework *)
PacletInstall["Wolfram/QuantumFramework", ForceVersionInstall -> True]
<< Wolfram`QuantumFramework`;

(* Install Strangeworks Extension *)
PacletInstall["Strangeworks/Strangeworks", ForceVersionInstall -> True]
<< Strangeworks`Strangeworks`;

(* Define a qubo matrix to optimize *)
Q = {{-2, 2, 2, 0, 0}, {0, -2, 0, 2, 0}, {0, 0, -2, 2, 2}, {0, 0,
0, -2, 2}, {0, 0, 0, 0, -2}};
Q // MatrixForm

(* User must input their own apikey and resourceslug, see installation instructions above *)
apikey = "";
resourceslug = "";
productslug = "qaoa";

authstatus = AuthenticateSW[apikey]
resourcestatus = GetResourceSW[resourceslug, productslug]

(* Display backends available to the user *)
backends = BackendsSW[]

(* Define Algorithm Parameters *)
params = <|
"maxiter" -> 50, (*Maximum number of iterations in algorithm*)
"shotsin" ->
100, (*Number of times quantum circuit is measured at each iteration*)
"theta0" -> {1.0, 1.0}, (*Optional Input: Starting point for variational parameters*)
"p" -> 1, (*Optional Input: Controls the depth of the Quantum Circuit ansatz*)
"alpha" -> 0.1 (*Optional Input: Cvar parameter, float between 0 and 1 - https://arxiv.org/pdf/1907.04769.pdf*)
|>

(* Run on the simulator *)
backend = "arn:aws:braket:::device/quantum-simulator/amazon/sv1";

swjob = RunSWQAOA[Q, params, backend]
jobslug = Part[swjob, 2]

(* Check on the status *)
status = StatusSW[jobslug]

(* Get the results *)
result = ResultSW[jobslug];

🥳 Success! You may view your job in the portal.

😅 Something went wrong? Find us in Slack!