Package: pyquil-for-azure-quantum
pyquil-for-azure-quantumThis library allows you to usepyQuilto run programs onAzure Quantumagainst Rigetti targets. Internally, it leverages theazure-quantumpackage.UsageGenerally, you usepyQuilnormally, with a few differences:Instead ofpyquil.get_qc(), you will use eitherpyquil_azure_quantum.get_qvm()orpyquil_azure_quantum.get_qpu().You do not need to haveqvmorquilcrunning in order to run programs throughpyquil_azure_quantum. You may still run them if you wish to run QVM locally instead of passing through Azure or if you wish to precompile your programs (e.g., to inspect the exact Quil that will run).You do not need a QCS account or credentials unless you wish to manually inspect the details of the QPU (e.g., list all qubits).Youmusthave these environment variables set:AZURE_QUANTUM_SUBSCRIPTION_ID: The Azure subscription ID where the Quantum Workspace is located.AZURE_QUANTUM_WORKSPACE_RG: The Azure resource group where the Quantum Workspace is located.AZURE_QUANTUM_WORKSPACE_NAME: The name of the Quantum Workspace.AZURE_QUANTUM_WORKSPACE_LOCATION: The region where the Quantum Workspace is located.Youmayset environment variablesto authenticate with Azure. If you do not, a browser will open to the Azure portal to authenticate.Whenever possible, you should prefer usingAzureQuantumComputer.run_batch()overProgram.write_memory(); AzureQuantumComputer.run()to run programs which have multiple parameters. Callingwrite_memory()followed byrun()will still work but will be much slower than running a batch of parameters all at once.Examples1. Leveraging Hosted QVM and quilcWith this program, you do not need to runqvmnorquilclocally in order to leverage them, as they can run through Azure Quantum.frompyquil_for_azure_quantumimportget_qpu,get_qvmfrompyquil.gatesimportCNOT,MEASURE,Hfrompyquil.quilimportProgramfrompyquil.quilbaseimportDeclareprogram=Program(Declare("ro","BIT",2),H(0),CNOT(0,1),MEASURE(0,("ro",0)),MEASURE(1,("ro",1)),).wrap_in_numshots_loop(1000)qpu=get_qpu("Aspen-11")qvm=get_qvm()exe=qpu.compile(program)# This does not run quilc yet.results=qpu.run(exe)# Quilc will run in the cloud before executing the program.qvm_results=qvm.run(exe)# This runs the program on QVM in the cloud, not locally.2. Running quilc LocallyYou can optionally run quilc yourself and disable the use of quilc in the cloud.frompyquil_for_azure_quantumimportget_qpufrompyquil.gatesimportCNOT,MEASURE,Hfrompyquil.quilimportProgramfrompyquil.quilbaseimportDeclareprogram=Program(Declare("ro","BIT",2),H(0),CNOT(0,1),MEASURE(0,("ro",0)),MEASURE(1,("ro",1)),).wrap_in_numshots_loop(1000)qpu=get_qpu("Aspen-11")native_quil=qpu.compiler.quil_to_native_quil(program)# quilc must be running locally to compileexe=qpu.compile(native_quil,to_native_gates=False)# Skip quilc in the cloudresults=qpu.run(exe)3. Running Parametrized Circuits in a BatchWhen you have a program which should be run across multiple parameters, you can submit all the parameters at once to significantly improve performance.importnumpyasnpfrompyquil_for_azure_quantumimportget_qpufrompyquil.gatesimportMEASURE,RXfrompyquil.quilimportProgramfrompyquil.quilbaseimportDeclarefrompyquil.quilatomimportMemoryReferenceprogram=Program(Declare("ro","BIT",1),Declare("theta","REAL",1),RX(MemoryReference("theta"),0),MEASURE(0,("ro",0)),).wrap_in_numshots_loop(1000)qpu=get_qpu("Aspen-11")compiled=qpu.compile(program)memory_map={"theta":[[0.0],[np.pi],[2*np.pi]]}results=qpu.run_batch(compiled,memory_map)# This is a list of results, one for each parameter set.results_0=results[0].readout_data["ro"]results_pi=results[1].readout_data["ro"]results_2pi=results[2].readout_data["ro"]Microsoft, Microsoft Azure, and Azure Quantum are trademarks of the Microsoft group of companies.