Package: qiskit-rigetti
Rigetti Provider for QiskitTry It OutTo try out this library, you can run example notebooks in a pre-madebinder. Alternately, you can run the following to build and run the image locally:dockerbuild-tqiskit-tutorials.
dockerrun--rm-p8888:8888qiskit-tutorialsthen click on the link that is displayed after the container starts up.Pre-requisitesInstallDockerDownloadqelib1.incPlaceqelib1.incin a folder calledincin the project rootSetup QVM and quilcUsing Docker ComposeRundocker compose upto see service logs ordocker compose up -dto run in the background.Using Docker ManuallyStart the QVM:dockerrun--rm-it-p5000:5000rigetti/qvm-SStart the compiler:dockerrun--rm-it-p5555:5555-v"$PWD"/inc:/incrigetti/quilc-S-P--safe-include-directory/inc/UsageExample:fromqiskitimportexecutefromqiskit_rigettiimportRigettiQCSProvider,QuilCircuit# Get provider and backendp=RigettiQCSProvider()backend=p.get_simulator(num_qubits=2,noisy=True)# or p.get_backend(name='Aspen-9')# Create a Bell state circuitcircuit=QuilCircuit(2,2)circuit.h(0)circuit.cx(0,1)circuit.measure([0,1],[0,1])# Execute the circuit on the backendjob=execute(circuit,backend,shots=10,coupling_map=backend.coupling_map)# Grab results from the jobresult=job.result()# Return memory and countsmemory=result.get_memory(circuit)counts=result.get_counts(circuit)print("Result memory:",memory)print("Result counts:",counts)Rigetti Quantum Cloud Services (QCS)Execution against a QPU requires areservation via QCS.
For more information on using QCS, see theQCS documentation.AdvancedLifecycle HooksFor advanced QASM and Quil manipulation,before_compileandbefore_executekeyword arguments can be passed toRigettiQCSBackend.run()or to Qiskit'sexecute().Pre-compilation HooksAnybefore_compilehooks will apply, in order, just before compilation from QASM to native Quil.
For example:...defcustom_hook_1(qasm:str)->str:new_qasm=...returnnew_qasmdefcustom_hook_2(qasm:str)->str:new_qasm=...returnnew_qasmjob=execute(circuit,backend,shots=10,before_compile=[custom_hook_1,custom_hook_2])...Pre-execution HooksAnybefore_executehooks will apply, in order, just before execution (after translation from QASM to native Quil).
For example:frompyquilimportProgram...defcustom_hook_1(quil:Program)->Program:new_quil=...returnnew_quildefcustom_hook_2(quil:Program)->Program:new_quil=...returnnew_quiljob=execute(circuit,backend,shots=10,before_execute=[custom_hook_1,custom_hook_2])...Note:Onlycertain forms of Quil can can be executed on a QPU.
If pre-execution transformations produce a final program that is not QPU-compliant,ensure_native_quil=Truecan be
passed toexecute()orRigettiQCSBackend.run()to recompile the final Quil program to native Quil prior to
execution. If no pre-execution hooks were supplied, this setting is ignored. If this setting is omitted, a value ofFalseis assumed.Example: Adding the Quil instructionH 0would result in an error ifensure_native_quil=Falseand the QPU does
not natively implement Hadamard gates.Built-in HooksThehooks.pre_compilationandhooks.pre_executionpackages provide a number of convenient hooks:set_rewiringUseset_rewiringto provide arewiring directiveto the Quil compiler. For example:fromqiskit_rigetti.hooks.pre_compilationimportset_rewiring...job=execute(circuit,backend,shots=10,before_compile=[set_rewiring("NAIVE")])...Note: Rewiring directives requirequilcversion 1.25 or higher.enable_active_resetUseenable_active_resetto enableactive qubit reset,
an optimization that can significantly reduce the time between executions. For example:fromqiskit_rigetti.hooks.pre_executionimportenable_active_reset...job=execute(circuit,backend,shots=10,before_execute=[enable_active_reset])...DevelopmentNote: This module is developed in Python 3.8, 3.9, and 3.10, other versions will currently fail type checking.Dependencies are managed withPoetryso you need to install that first. Once you've installed all dependencies (poetry install) and activated the virtual environment (poetry shell), you can use these rules from theMakefileto run common tasks:Run tests:make testCheck style and types:make check-allCheck style only:make check-styleCheck types only:make check-typesReformat all code (to makecheck-stylepass):make formatBuild documentation, serve locally, and watch for changes:make watch-docs(requiresdocsextra:poetry install -E docs)