author | description | ms.date | ms.author | ms.service | ms.subservice | ms.topic | no-loc | title | uid | ||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
SoniaLopezBravo |
Learn how to run multiple configurations of target parameters and compare them using the Resource Estimator. |
06/03/2024 |
sonialopez |
azure-quantum |
qdk |
how-to |
|
Batching with the Resource Estimator |
microsoft.quantum.resource-estimator-batching |
In this article, you learn how to run multiple configurations of target parameters and compare them using the Azure Quantum Resource Estimator.
For information about how to run the Resource Estimator, see Different ways to use the Resource Estimator.
The following prerequisites are required to run the Resource Estimator:
To run Q# programs in the Resource Estimator, you need the following:
- The latest version of Visual Studio Code or open VS Code on the Web.
- The latest version of the Azure Quantum Development Kit extension. For installation details, see Installing the QDK on VS Code.
If you want to use Python in VS Code, you also need the following:
-
Install the latest version of the Python, and Jupyter extensions for VS Code.
-
The latest Azure Quantum
qsharp
package.python -m pip install --upgrade qsharp
To submit jobs to the Resource Estimator, you need the following:
- An Azure account with an active subscription. If you don’t have an Azure account, register for free and sign up for a pay-as-you-go subscription.
- An Azure Quantum workspace. For more information, see Create an Azure Quantum workspace.
The Azure Quantum Resource Estimator allows you to submit jobs with multiple configurations of job parameters, also referred as items, as a single job to avoid rerunning multiple jobs on the same quantum program.
A resource estimation job consist of two types of job parameters:
- Target parameters: qubit model, QEC schemes, error budget, constraints on the component-level, and distillation units.
- Operation arguments: arguments that can be passed to the program (if the QIR entry point contains arguments).
One item consists of one configuration of job parameters, that is one configuration of target parameters and operation arguments. Several items are represented as an array of job parameters.
Some scenarios where you may want to submit multiple items as a single job:
- Submit multiple target parameters with same operation arguments in all items.
- Submit multiple target parameters with different operation arguments in all items.
- Easily compare multiple results in a tabular format.
- Easily compare multiple results in a chart.
Select the desired tabs for examples of Resource Estimator batching.
If you are estimating the resources of a Q# program, you can run multiple configurations of target parameters, also known as batching. Batching with Q# can be done in a Jupyter Notebook in VS Code.
You can perform a batch estimation by passing a list of target parameters to the params
parameter of the qsharp.estimate
function. The following example shows how to submit two configurations of target parameters as a single job. The first configuration uses the default target parameters, and the second configuration uses the qubit_maj_ns_e6
qubit parameter and the floquet_code
QEC scheme.
In the same Jupyter Notebook of your Q# program, add a new cell and run the following code:
result_batch = qsharp.estimate("RunProgram()", params=
[{}, # Default parameters
{
"qubitParams": {
"name": "qubit_maj_ns_e6"
},
"qecScheme": {
"name": "floquet_code"
}
}])
result_batch.summary_data_frame(labels=["Gate-based ns, 10⁻³", "Majorana ns, 10⁻⁶"])
You can also construct a list of estimation target parameters using the EstimatorParams
class. The following code shows how to submit six configurations of target parameters as a single job.
from qsharp.estimator import EstimatorParams, QubitParams, QECScheme
labels = ["Gate-based µs, 10⁻³", "Gate-based µs, 10⁻⁴", "Gate-based ns, 10⁻³", "Gate-based ns, 10⁻⁴", "Majorana ns, 10⁻⁴", "Majorana ns, 10⁻⁶"]
params = EstimatorParams(num_items=6)
params.error_budget = 0.333
params.items[0].qubit_params.name = QubitParams.GATE_US_E3
params.items[1].qubit_params.name = QubitParams.GATE_US_E4
params.items[2].qubit_params.name = QubitParams.GATE_NS_E3
params.items[3].qubit_params.name = QubitParams.GATE_NS_E4
params.items[4].qubit_params.name = QubitParams.MAJ_NS_E4
params.items[4].qec_scheme.name = QECScheme.FLOQUET_CODE
params.items[5].qubit_params.name = QubitParams.MAJ_NS_E6
params.items[5].qec_scheme.name = QECScheme.FLOQUET_CODE
qsharp.estimate("RunProgram()", params=params).summary_data_frame(labels=labels)
If you are estimating the resources of a Qiskit program, you can run multiple configurations of target parameters, also known as batching. Batching with Qiskit can be done in a notebook in Azure portal.
Consider the following Qiskit circuit that takes three qubits and apply a CCX or Toffoli gate using the third qubit as target. In this case, you want to estimate the resources of this quantum circuit for four different target parameters, so each configuration consists of one target parameter. Batching allows you to submit all configurations at the same time.
In the same notebook of your Qiskit program, add a new cell and run the following code:
from azure.quantum import Workspace
from azure.quantum.qiskit import AzureQuantumProvider
workspace = Workspace (
resource_id = "",
location = ""
)
provider = AzureQuantumProvider(workspace)
backend = provider.get_backend('microsoft.estimator')
from qiskit import QuantumCircuit
circ = QuantumCircuit(3)
circ.ccx(0, 1, 2)
items = [
{"qubitParams": {"name": "qubit_gate_ns_e3"}, "errorBudget": 0.0001},
{"qubitParams": {"name": "qubit_gate_ns_e4"}, "errorBudget": 0.0001},
{"qubitParams": {"name": "qubit_maj_ns_e4"}, "errorBudget": 0.0001},
{"qubitParams": {"name": "qubit_maj_ns_e6"}, "errorBudget": 0.0001},
] # target parameters
job = backend.run(circ, items=items)
results = job.result()
results
The result of the resource estimation job is displayed in a table with multiple results coming from the list of items. By default the maximum number of items to be displayed is five. To display a list of results[0:N]
. You can also access individual results by providing a number as index. For example, results[0]
to show the results table of the first configuration.
If you are estimating the resources of a PyQIR program, you can run multiple configurations of target parameters, also known as batching. Batching with PyQIR can be done in a notebook in Azure portal.
Consider that you want to estimate the resources of a quantum operation using all six pre-defined qubit parameters. As pre-defined QEC scheme we are using surface_code
with gate-based qubit parameters, and floquet_code
with Majorana based qubit parameters. The operation takes six different arguments.
In the same notebook of your PyQIR program, add a new cell and run:
-
First, you import some packages to use the Resource Estimator target and the
QubitParams
class.from azure.quantum.target.microsoft import MicrosoftEstimator, QubitParams, QECScheme
-
You define the labels for the qubit parameters. The labels are used to identify the qubit parameters in the results table. You set a number of items for the job by passing the
num_items
parameter to themake_params
method. In this case, the number of items is six, one for each pre-defined qubit parameter.estimator = MicrosoftEstimator(workspace) labels = ["Gate-based µs, 10⁻³", "Gate-based µs, 10⁻⁴", "Gate-based ns, 10⁻³", "Gate-based ns, 10⁻⁴", "Majorana ns, 10⁻⁴", "Majorana ns, 10⁻⁶"] params = estimator.make_params(num_items=6)
-
The arguments are passed as a dictionary. The keys are the names of the arguments and the values are the values of the arguments. Arguments can be numbers or arrays of numbers. In this case, you pass the following arguments:
params.arguments["N"] = 10 params.arguments["J"] = 1.0 params.arguments["g"] = 1.0 params.arguments["totTime"] = 20.0 params.arguments["dt"] = 0.25 params.arguments["eps"] = 0.001
-
Next, you can pass the qubit parameters for each configuration by specifying the item in
items[]
. Usequbit_params.name
and specify theQubitParams
class, for exampleGATE_US_E3
, and useqec_scheme.name
and then specify theQECScheme
class, for exampleFLOQUET_CODE
.params.items[0].qubit_params.name = QubitParams.GATE_US_E3 params.items[1].qubit_params.name = QubitParams.GATE_US_E4 params.items[2].qubit_params.name = QubitParams.GATE_NS_E3 params.items[3].qubit_params.name = QubitParams.GATE_NS_E4 params.items[4].qubit_params.name = QubitParams.MAJ_NS_E4 params.items[4].qec_scheme.name = QECScheme.FLOQUET_CODE params.items[5].qubit_params.name = QubitParams.MAJ_NS_E6 params.items[5].qec_scheme.name = QECScheme.FLOQUET_CODE
-
By running each configuration as a single job, this would lead to the submission of six jobs, which means six separate compilations for the same program. Instead, you submit one batching job with multiple items.
job = estimator.submit(Operation, input_params=params, name="My operation") results = job.get_results()
[!NOTE] You can set a name for the job by passing the
name
parameter to thesubmit
method.job = estimator.submit(operation, input_params=params, name="My operation")
Note
If you run into any issue while working with the Resource Estimator, check out the Troubleshooting page, or contact AzureQuantumInfo@microsoft.com.
- Understand the results of the Resource Estimator
- Use different SDKs and IDEs with Resource Estimator
- Customize resource estimates to machine characteristics
- Tutorial: Estimate the resources of a quantum chemistry problem