strangeworks-matlab
The strangeworks-matlab
package allows MATLAB users to communicate with the Strangeworks platform.
This allows users to submit jobs to gate based quantum hardware as well as a wide range of alternative compute providers, see full catalog.
Installation
A user must go through the following steps to be able to run jobs
- Download and authenticate Matlab, free trials available. Skip this if you already have a license.
- Download and install the quantum computing package
- Download Strangeworks.mltbx from File Exchange. Double click to install with Matlab package manager
- Sign up for free to our platform
- Add the free IBM runtime resource. For other resources, please visit the Strangeworks catalog
- Put in your apiKey from the homepage and resource id from the resource page and run the example script
example_ibm.m
🥳 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:
apiKey = '';
resource_slug = "";
sw = strangeworks().authenticate(apiKey);
sw = sw.get_resource(resource_slug);
fprintf("Product %s \n", sw.product_slug)
backends = sw.backends();
for i = 1:length(backends)
fprintf("name=%s: remoteStatus=%s: id=%s \n",backends(i).name,backends(i).remoteStatus,backends(i).remoteBackendId)
end
gates = [hGate(1); cxGate(1,2)];
qc = quantumCircuit(gates);
shots = 100;
backend = "ibmq_qasm_simulator";
sw_job = sw.run(backend,qc,shots)
job_slug = sw_job.slug;
status = sw.status(job_slug);
fprintf("Job %s status %s \n", job_slug,status)
results = sw.result(job_slug);
sw.plot_histogram(results.hist)
🥳 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:
apiKey = '';
resource_slug = "";
sw = strangeworks().authenticate(apiKey);
sw = sw.get_resource(resource_slug);
fprintf("Product %s \n", sw.product_slug)
backends = sw.backends();
for i = 1:length(backends)
fprintf("name=%s: remoteStatus=%s: id=%s \n",backends(i).name,backends(i).remoteStatus,backends(i).remoteBackendId)
end
gates = [hGate(1); cxGate(1,2)];
qc = quantumCircuit(gates);
shots = 100;
backend = "arn:aws:braket:::device/quantum-simulator/amazon/sv1";
sw_job = sw.run(backend,qc,shots)
job_slug = sw_job.slug;
status = sw.status(job_slug);
fprintf("Job %s status %s \n", job_slug,status)
results = sw.result(job_slug);
sw.plot_histogram(results.hist)
🥳 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 StrangeworksQAOA service.
Before running follow the installation steps above:
apiKey = '';
resource_slug = "";
sw = strangeworks().authenticate(apiKey);
sw = sw.get_resource(resource_slug);
fprintf("Product %s \n", sw.product_slug)
backends = sw.backends();
for i = 1:length(backends)
fprintf("name=%s: remoteStatus=%s: id=%s \n",backends(i).name,backends(i).remoteStatus,backends(i).remoteBackendId)
end
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];
% backend = "arn:aws:braket:::device/quantum-simulator/amazon/sv1";
backend = "ibmq_qasm_simulator";
% See https://docs.strangeworks.com/apps/qaoa for more info
problem_params = struct( ...
maxiter= 50, ... % Maximum number of iterations in algorithm
shotsin= 1000, ... % Number of times quantum circuit is measured at each iteration
p=1, ... % Optional Input: Controls the depth of the Quantum Circuit ansatz. Default p=1
theta0= [1.0,1.0], ... % Optional Input: Starting point for variational parameters. If specified must be equal to 2p
alpha= 0.1, ... % Optional Input: Cvar parameter, float between 0 and 1 - https://arxiv.org/pdf/1907.04769.pdf. Default alpha=1.0
optimizer= "COBYLA" ... % Optional Input: Classical optimizer to use.
);
sw_job = sw.run(backend, Q, problem_params);
job_slug = sw_job.slug;
status = sw.status(job_slug);
fprintf("Job %s status %s \n", job_slug,status)
results = sw.result(job_slug)
🥳 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 Optimization service.
Before running follow the installation steps above:
apiKey = '';
resource_slug = "";
sw = strangeworks().authenticate(apiKey);
sw = sw.get_resource(resource_slug);
fprintf("Product %s \n", sw.product_slug)
backends = sw.backends();
for i = 1:length(backends)
fprintf("name=%s: remoteStatus=%s: id=%s \n",backends(i).name,backends(i).remoteStatus,backends(i).remoteBackendId)
end
Q = [0 -1 2;...
-1 0 4;...
2 4 0];
c = [-5 6 -4];
qprob = qubo(Q,c)
solver = "dwave.Advantage_system6.4";
solver_options = struct();
sw_job = sw.run(solver, qprob, solver_options);
job_slug = sw_job.job_slug;
% job_slug = '';
status = sw.status(job_slug);
fprintf("Job %s status %s \n", job_slug,status)
samples_struct = sw.result(job_slug)
🥳 Success! You may view your job in the portal.
😅 Something went wrong? Find us in Slack!