002 - An Introduction to Qiskit Runtime Primitives Version 2 with Chris Wood: Qiskit Summer School 2024
Finished
Finished
Note
Status
To Learn
Tags
Qiskit
Total Videos
1
Video Duration
00:44:11
An Introduction to Qiskit Runtime Primitives Version 2
The release of Qiskit 1.0 introduced version 2 of the Sampler and Estimator primitives interfaces for executing quantum programs[1]. These primitives are foundational building blocks for quantum programs, designed to optimize the execution of quantum workloads[1].
What's New in Version 2?
The main change in the version 2 primitives over version 1 was to allow more efficient specification and execution of parametric programs[1]. The implementation of the primitives for IBM hardware in the Qiskit IBM Runtime was introduced in version 0.21.0 and includes built-in support for error suppression and error mitigation techniques used for utility scale workflows[1].
Some key changes in version 2 include[2]:
- Explicit import of V2 primitives for backward compatibility
- Unified input format called Primitive Unified Blocs (PUBs)
- Updated primitive result data formats
- Ability to set options during primitive initialization or after using
options
attribute
- Support for gate twirling for error mitigation (requires qiskit_ibm_runtime 0.23.0+)
The Sampler Primitive
The Sampler V2 primitive is a low-level execution primitive intended for workflows where the measurement outcomes of quantum circuits are needed[1]. It returns single-shot measurement outcomes, so circuits run on the Sampler should include measurements[1].
The Estimator Primitive
The Estimator V2 primitive is a higher-level abstraction for running quantum circuits where expectation values of operators are desired[1]. Since it returns expectation values, circuits do not need to contain measurements as they will be added to compute the expectation values[1].
Benefits of Qiskit Primitives
Primitives allow Qiskit users to write quantum code for a specific QPU without having to explicitly manage every detail[3]. Because of the additional abstraction layer, primitives can optimize execution in ways that are not possible with circuits alone, such as batching circuits together, optimizing qubit mappings globally, and including built-in error mitigation techniques[3].
Getting Started
To use the Qiskit Runtime primitives, you first need to initialize your account since it is a managed service[5]. You can then select the QPU to use. The primitives can also be run on any provider using the
BackendSampler
and BackendEstimator
classes from qiskit.primitives
[5].As of March 1, 2024, circuits and observables need to be transpiled to the QPU's supported instruction set architecture (ISA) before being submitted to the Runtime primitives for faster, more efficient results[5]. The only exception is when initializing the Qiskit Runtime Service with the Q-CTRL channel strategy[5].
In summary, the Qiskit Runtime primitives provide a powerful, optimized interface for executing quantum programs on IBM's quantum computers and beyond. The version 2 release brings many enhancements to enable more efficient parametric programs and error mitigation techniques.
Citations:
[1] https://www.youtube.com/watch?v=OuYz02clnx4
[2] https://docs.quantum.ibm.com/migration-guides/v2-primitives
[3] https://docs.quantum.ibm.com/guides/primitives
[4] https://pypi.org/project/qiskit-ibm-runtime/0.9.2/
[5] https://docs.quantum.ibm.com/guides/get-started-with-primitives
[6] https://cloud.ibm.com/docs/quantum-computing?topic=quantum-computing-overview
The diagram illustrates how the Qiskit Runtime Service integrates classical and quantum computing components. Here's a brief overview:
- At the top, there's a box labeled "Your Code" which includes both Classical and Quantum elements.
- The main component is the "Qiskit Runtime Service" which acts as an intermediary between the user's code and the quantum hardware.
- Inside the Qiskit Runtime Service, there are three main components:
- Qiskit Runtime API: This handles primitive programs.
- QASM circuits: These are quantum assembly language circuits that interface between the API and the hardware.
- Quantum Hardware: This represents the actual quantum computing devices.
- The diagram shows data flow with arrows:
- Primitive program inputs go from the user's code to the Qiskit Runtime API.
- There's a bidirectional flow between the API and QASM circuits, and between QASM circuits and Quantum Hardware.
- Return values flow back up to the user's code.
This architecture allows for seamless integration of classical and quantum computations, enabling users to run hybrid algorithms efficiently.
This image provides an overview of V2 Primitives in Qiskit, detailing two main categories: Qiskit V2 Primitives and IBM V2 Primitives. Let me break down the key points:
- Qiskit V2 Primitives:
- Introduced in Qiskit 1.0
- Allows efficient specification of parametric programs
- IBM V2 Primitives:
- Introduced in Qiskit IBM Runtime 0.21
- Enables efficient execution of parametric programs on IBM hardware
- Includes built-in error suppression and mitigation techniques
- The image highlights two main primitives:
- Used for low-level execution of circuits
- Returns single-shot measurement outcomes
- Circuits should include measurements
- Illustrated with a quantum circuit diagram showing measurements
- Used for higher-level execution of algorithms and applications
- Returns expectation values of observables
- Circuits should not include measurements
- Illustrated with a simpler quantum circuit diagram without measurements
a) Sampler primitive:
b) Estimator primitive:
- The Sampler primitive is visualized with a bell curve graph, suggesting it deals with probability distributions of measurement outcomes.
- The Estimator primitive is visualized with a box plot, indicating it provides statistical estimates of expectation values.
These primitives represent different levels of abstraction in quantum computing, with the Sampler operating at a lower level (dealing with direct measurements) and the Estimator operating at a higher level (dealing with expectation values of observables). This structure allows for flexibility in how quantum algorithms are implemented and executed on quantum hardware.
Hadamard Test:
This method can estimate the real or imaginary parts of the expectation value of an operator with respect to a state.
‣
‘
The image provides information about the Sampler V2 Results, focusing on two main classes: PubResult and DataBin.
PubResult Class:
- When running a Sampler Job, it returns a PrimitiveResult object containing an ordered list of PubResult objects.
- Each PubResult corresponds to an input pub's execution results.
- PubResult.data contains measurement outcome data for all classical registers in the input pub's circuit.
- PubResult.metadata contains any additional metadata that a primitive might record.
DataBin Class:
- PubResult.data is a container called a DataBin.
- It stores the outcomes of measurements in ClassicalRegister in the PUB circuit.
- Register results can be accessed by name, either as attributes or as a mapping.
This information appears to be related to quantum computing or quantum circuit simulation, specifically about how results are structured and accessed after running a simulation or computation.
The image provides an overview of ISA (Instruction Set Architecture) Circuits in the context of quantum computing. Let me break down the key components and concepts presented:
What is an ISA Circuit?
An ISA circuit is defined as a QuantumCircuit that satisfies three main criteria:
- It has the same number of qubits as a device
- It only contains basis gates for a device
- It satisfies the connectivity of a device
These characteristics ensure that the ISA circuit is tailored to the specific quantum device it's designed for.
Transpilation Process
The image illustrates the concept of transpilation, which is crucial for working with ISA circuits. If you're accustomed to working with abstract or logical circuits, you typically obtain an ISA circuit through transpilation to a target or backend. This process adapts the circuit to the specific requirements and constraints of the target quantum hardware.
Circuit Examples
The image provides two examples of quantum circuits:
2-qubit Circuit
This simpler circuit shows:
- Two qubits (q0 and q1)
- An H gate (Hadamard) on q0
- A controlled-NOT (CNOT) gate with q0 as control and q1 as target
- Measurement operations on both qubits
27-qubit ISA Circuit
This more complex circuit demonstrates:
- 27 qubits in total (num_qubits: 27)
- 2 classical bits (num_clbits: 2)
- A global phase of π/4
- The first two qubits (q0 and q1) have specific operations:
- q0: Rz gate, X gate (NOT), and another Rz gate
- q1: CNOT gate controlled by q0
- Additional qubits labeled as "ancilla" (ancillary qubits) from 2 to 26
- Measurement operations at the end
The transpilation arrow between these circuits suggests that the 2-qubit circuit could be transpiled into the 27-qubit ISA circuit to run on a specific quantum device with 27 qubits.
This information provides a foundational understanding of ISA circuits and their role in adapting quantum algorithms to specific quantum hardware architectures.
The image provides an overview of parametric circuits in quantum computing. Here's a summary of the key points:
- Definition of a parametric circuit:
- It's a circuit (ISA or abstract) that contains unbound parameter values.
- Example given:
- The Ry gate on q0 is labeled with "Ry θ", where θ is the parameter.
- This θ parameter controls the angle of rotation around the Y-axis for qubit q0.
- By adjusting θ, you can control the degree of entanglement between q0 and q1 when they interact through the subsequent controlled operation (represented by the vertical line connecting the two qubits)
The parameter in this circuit is θ (theta), which is shown inside the Ry (rotation around Y-axis) gate applied to qubit q0.
Specifically:
This parametric circuit allows for fine-tuning of the entanglement between the two qubits by adjusting the θ parameter in the initial Ry rotation on q0.
- The shape of a Pub and PubResult:
- A sampler Pub shape is given the tensor shape of its parameterizations to be evaluated.
- A non-parametric Pub has shape ().
- For an ISA circuit with K parameters and (N, K) shaped parameter values array, it has shape (N,).
- A parametric Pub can be converted to a list of non-parametric pubs by binding all parameter values.
Let's discuss the function of the Ry gate in this circuit and its matrix representation:
- Function of Ry in the circuit:
The Ry(θ) gate performs a rotation around the y-axis of the Bloch sphere by an angle θ. In this circuit, it's applied to the first qubit (q0) before the CNOT gate. Its primary functions are:
a) State preparation: It prepares q0 in a superposition state between |0⟩ and |1⟩.
b) Entanglement control: By varying θ, it controls how much the state of q0 affects q1 through the subsequent CNOT gate, thus controlling the degree of entanglement.
- Matrix representation of Ry(θ):
The Ry(θ) gate is represented by the following 2x2 matrix:
Ry(θ) = [ cos(θ/2) -sin(θ/2) ]
[ sin(θ/2) cos(θ/2) ]
- Effect on qubit states:
- When applied to |0⟩: Ry(θ)|0⟩ = cos(θ/2)|0⟩ + sin(θ/2)|1⟩
- When applied to |1⟩: Ry(θ)|1⟩ = -sin(θ/2)|0⟩ + cos(θ/2)|1⟩
- Behavior for specific θ values:
- θ = 0: Ry(0) is the identity matrix, leaving the qubit state unchanged.
- θ = π: Ry(π) performs a bit flip (equivalent to X gate).
- θ = π/2: Ry(π/2) creates an equal superposition of |0⟩ and |1⟩.
In the context of this circuit:
- At θ = 0, q0 remains in |0⟩, resulting in no entanglement.
- As θ increases, q0 gets into superposition, leading to entanglement when interacting with q1 via CNOT.
- At θ = π, q0 is fully flipped to |1⟩, maximizing the effect on q1 through the CNOT gate.
This explains why we see the smooth transition in probabilities of measuring "00" and "11" as θ varies from 0 to π in the graph.
Let's explain the curve in the graph using the properties of the Ry gate and its effect on the circuit:
- θ = 0:
- Ry(0) is the identity matrix, so q0 remains in |0⟩.
- The initial state is |00⟩.
- CNOT does nothing to |00⟩.
- Result: P("00") ≈ 1, P("11") ≈ 0
- As θ increases from 0 to π/2:
- Ry(θ) puts q0 in a superposition: cos(θ/2)|0⟩ + sin(θ/2)|1⟩
- The state before CNOT: (cos(θ/2)|0⟩ + sin(θ/2)|1⟩) ⊗ |0⟩
- After CNOT: cos(θ/2)|00⟩ + sin(θ/2)|11⟩
- Result: P("00") decreases, P("11") increases
- At θ = π/2:
- Ry(π/2) puts q0 in equal superposition: (1/√2)(|0⟩ + |1⟩)
- After CNOT: (1/√2)(|00⟩ + |11⟩) - maximally entangled Bell state
- Result: P("00") = P("11") = 0.5
- As θ increases from π/2 to π:
- The superposition of q0 becomes increasingly biased towards |1⟩
- After CNOT, this leads to an increasing probability of |11⟩
- Result: P("00") continues to decrease, P("11") continues to increase
- At θ = π:
- Ry(π) performs a bit flip, putting q0 in |1⟩
- The initial state becomes |10⟩
- After CNOT, the state is |11⟩
- Result: P("00") ≈ 0, P("11") ≈ 1
The smooth, sinusoidal shape of the curves is due to the cos²(θ/2) and sin²(θ/2) terms in the probabilities:
- P("00") ∝ cos²(θ/2)
- P("11") ∝ sin²(θ/2)
This explanation accounts for the symmetric, crossing curves we see in the graph, with P("00") starting high and decreasing, while P("11") starts low and increases, crossing at θ = π/2 where both probabilities are equal.
14:43
Shots and one has 200 shots so essentially the shots argument of the Run call has been ignored because both pubs specified the shots themselves
This image provides information about the Estimator V2 Results in what appears to be documentation or training material from the Qiskit Global Summer School 2024.
Key points from the image:
- An Estimator Job contains a PrimitiveResult with a list of PubResults for each input pub.
- The DataBin of an Estimator contains two main fields:
- evs: The mean expectation value estimates for all input pub parameter values and observables.
- stds: The standard error of the mean of expectation value estimates.
- The image provides an example of how to use the Estimator:
- It shows how to construct an Estimator and a pub.
- It demonstrates running the Estimator job and retrieving the results.
- It shows how to access and print the data, specifically the evs and stds.
- The example output shows a result of 1.002 ± 0.008, which represents the mean and standard error of the expectation value estimate.
This image explains the broadcasting rules for Estimator V2, which follow the same principles as NumPy ND-array broadcasting. Here are the key points:
- Input arrays don't need to have the same number of dimensions.
- The resulting array will have the same number of dimensions as the largest input array.
- The size of each dimension in the result is the largest size of the corresponding dimension among the input arrays.
- Missing dimensions are assumed to have size one.
- Broadcasting starts with the trailing (rightmost) dimension and works its way left.
- Two dimensions are compatible when their sizes are equal or one of them is 1.
The image provides two examples to illustrate these rules:
Example 1:
- A: 2d array of shape 5 x 4
- B: 1d array of shape 1
- Result: 2d array of shape 5 x 4
Example 2:
- A: 3d array of shape 15 x 3 x 5
- B: 3d array of shape 15 x 1 x 5
- Result: 3d array of shape 15 x 3 x 5
These examples demonstrate how arrays of different dimensions can be broadcast together, resulting in an output that matches the largest dimensions while following the compatibility rules.
The image provides an overview of ISA Observables in quantum computing. Here's a summary of the key points:
- Definition: An ISA Observable is a linear combination of Pauli operators with real coefficients.
- Characteristics:
- Each Pauli operator is defined on the same number of qubits as an ISA circuit.
- When working with abstract observables, you need to apply the layout of a transpiled circuit to map the observable qubits.
- Implementation:
- Several SparsePauliOp and Pauli operator classes have an apply_layout method to simplify this process.
- Example: The image shows a code snippet demonstrating how to create and display an ISA example:
- It creates a QuantumCircuit with one qubit.
- The circuit is transpiled with a specific backend and initial layout.
- The resulting circuit is displayed, showing a sequence of gates (Rz, √X, Rz) applied to qubit q0.
- An abstract observable is created using SparsePauliOp with Pauli operators X, Y, and Z.
- The layout is applied to the abstract observable.
- Visual representation: The image includes a circuit diagram showing the gates applied to qubit q0, with a global phase of π/4.
This information provides a basic understanding of ISA Observables and how they are implemented in quantum computing frameworks. If you'd like more details on any specific aspect, please feel free to ask.
This image provides an overview of Estimator Containers in what appears to be a programming or scientific computing context. It introduces two new helper container classes: ObservablesArray and BindingsArray.
Key points from the image:
- ObservablesArray and BindingsArray are new helper classes for manipulating arrays.
- ObservablesArray is described as being similar to a NumPy array of SparsePauliOp observables.
- BindingsArray is described as being similar to a NumPy array for named parameter value sets.
- Both classes have convenience methods, such as reshape.
- The image provides code examples for both classes, showing how to import and use them.
- There's a disclaimer noting that these classes are experimental, and their API is not guaranteed to be stable.
The examples demonstrate how to create and use these arrays, including importing them from specific modules, creating instances with certain parameters, and applying operations like reshape and layout.
This information seems to be related to quantum computing or quantum information processing, given the mention of Pauli arrays and observables. The classes appear to be part of a library or framework designed to handle quantum-related computations more efficiently.
Key points from the slide:
- Decomposing Measurement Observables:
- IBM primitives use Pauli grouping to minimize the number of measurement circuits.
- Groups Pauli's that can be computed from marginals of a single measurement.
- Grouping is done using the method
PauliList.group_commuting(qubit_wise=True)
.
- Component Expectation Values:
- When evaluating a Hamiltonian H = Σi αiPi, individual Pi term expectation values can be included.
- This doesn't increase QPU time and only slightly increases classical post-processing time.
- Code Examples:
- The slide shows Python code using Qiskit to demonstrate Pauli list grouping and creating an ObservablesArray.
This presentation seems to be discussing advanced topics in quantum computing, specifically how to efficiently measure and process quantum observables using Qiskit's tools and primitives.
The image provides an overview of IBM Runtime Primitives Options, focusing on the Sampler and Estimator API. Here's a summary of the key points:
- The Sampler and Estimator API allows for the creation of portable programs.
- IBM runtime primitives offer additional functionality that can be configured through options.
- This enables automatic error suppression and mitigation methods.
- Sampler Options include:
- default_shots: Sets the default number of shots when running jobs
- dynamical_decoupling: Configures automatic dynamical decoupling (DD)
- twirling: Configures automatic Pauli-twirling
- Estimator Options include:
- default_precision: Sets the default precision for running jobs
- default_shots: A proxy for setting default precision in terms of shots
- resilience_level: Enables preset resilience options
- dynamical_decoupling: Configures automatic dynamical decoupling (DD)
- twirling: Configures automatic Pauli-twirling
- resilience: Configures error mitigation methods
These options provide users with various tools to optimize and control their quantum computations using IBM's quantum computing platform.
This image explains the concept of Pauli Twirling in quantum computing. Here's a breakdown of the key points:
- Definition: Pauli twirling is a technique that converts a general noise channel into a Pauli error channel.
- Visual Representation:
- The left matrix represents a general error channel with various colored squares indicating different types of errors.
- The middle diagram shows the twirling process, where Pauli operators (P1, P2, P3, P4) are applied before and after the noisy channel (represented by Λ).
- The right matrix shows the resulting Pauli error channel, which is simpler and has errors only along the diagonal.
- Implementation:
- It requires a transpiling circuit to identify layers of twirled 2-qubit gates or measurements.
- The circuit is reparameterized to allow for parametrically inserting random Pauli operators.
- Random Pauli operators are sampled and inserted into the circuit in a specific way.
- Result Processing:
- For an Estimator, the results are averaged over samples.
- For a Sampler, the results are concatenated over samples.
The main benefit of Pauli twirling is that it simplifies the error model of a quantum system, making it easier to analyze and potentially correct for errors in quantum computations. This technique is part of the error mitigation strategies used in quantum computing to improve the reliability and accuracy of quantum operations.
The image describes the twirling options available when working with quantum computing primitives, specifically for the Sampler. It outlines two ways to specify these options:
- Twirling Options:
- enable_gates: Controls whether to apply 2-qubit gate twirling
- enable_measure: Determines if twirling of measurements is enabled
- num_randomizations: Sets the number of random samples for twirling or sampled mitigation
- shots_per_randomization: Specifies the number of shots to run for each random sample
- strategy: Defines the strategy for twirling qubits in identified layers of 2-qubit twirled gates
- Two ways to specify options:
a) Set options after initializing:
b) Pass options during initialization:
These options allow users to fine-tune the twirling process in their quantum computations, providing flexibility in how error mitigation is applied to their circuits.
- Giscus
Last update: 2024-9-14