Skip to main content

Rigetti

The strangeworks-rigetti package allows users to run construct and solve problems with the QAOA algorithm on multiple hardware providers.

📑 Package Documentation

Overview​

​ This page will be describing the strangeworks rigetti sdk that allows a user to perform various Rigetti computing computations through the strangeworks platform. Rigetti documentation lives at https://docs.rigetti.com/qcs/ ​

Prerequisites​

​ The user needs a strangeworks account and billing setup prior to any computations. ​

Installation​

​ To get started, make sure you have Python 3.10 or above (installation) and are familiar with setting up and using virtual environments.

Install packages using pip: ​

pip install -U pip && pip install strangeworks-rigetti

​ Import package into python: ​

import strangeworks
from strangeworks_rigetti import get_qc

​

Authentication​

Any issues authenticating, you may need to add a rigetti resource to your account through the Platform

When running various computations one will need their api key and a resource id that you can get once you add a resource as stated above ​

Usage​

​ Before running:

  1. Set up your environment and install strangeworks-rigetti and strangeworks
  2. In the portal, Activate Strangeworks Rigetti Service to create a Resource and get the resource id and replace it with resource-id below
  3. Replace your-api-key below with your key from the Portal homepage
  4. Use examples below to utilize the various functionality. See Examples section below for an example script.

Authenticate with strangeworks python sdk using users API token:

strangeworks.authenticate(api_key="your-api-key")

​ Get a quantum computing resource using the rigetti sdk extension by supplying a quantum computing backend name, the resource slug and a qvm setting

qc = get_qc(
"Ankaa-2", resource_slug=resource_id, as_qvm=True
) # as_qvm=False will produce a billable transaction for using hardware

​

Examples​

​ Here is an example on how to run a simple circuit on a rigetti quantum computing resource

import pyquil
from pyquil.gates import CNOT, MEASURE, H

import strangeworks
from strangeworks_rigetti import get_qc

strangeworks.authenticate(api_key="your-api-key")

# get rigetti resource
res = strangeworks.get_resource_for_product("rigetti")

# as_qvm=True uses the quantum virtual machine
# as_qvm=False uses an actual Rigetti machine
# as_qvm=False will produce a billable transaction for using hardware
qc = get_qc(
"Ankaa-2", resource_slug=res.slug, as_qvm=True
)

program = pyquil.Program()
program = program.inst(H(0))
program = program.inst(CNOT(0, 1))
ro = program.declare("ro", "BIT", 2)
program = program.inst(MEASURE(0, ro[0]))
program = program.inst(MEASURE(1, ro[1]))
program.wrap_in_numshots_loop(10)

res = qc.run(program, circuit_type="qasm")

print(res)

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

😅 Something went wrong? Find us in Slack!