Cost functions
Halaman ini belum diterjemahkan. Anda sedang melihat versi asal dalam bahasa Inggeris.
During this lesson, we'll learn how to evaluate a cost function:
- First, we'll learn about Qiskit Runtime primitives
- Define a cost function . This is a problem-specific function that defines the problem's goal for the optimizer to minimize (or maximize)
- Defining a measurement strategy with the Qiskit Runtime primitives to optimize speed versus accuracy
Primitives
All physical systems, whether classical or quantum, can exist in different states. For example, a car on a road can have a certain mass, position, speed, or acceleration that characterize its state. Similarly, quantum systems can also have different configurations or states, but they differ from classical systems in how we deal with measurements and state evolution. This leads to unique properties such as superposition and entanglement that are exclusive to quantum mechanics. Just like we can describe a car's state using physical properties like speed or acceleration, we can also describe the state of a quantum system using observables, which are mathematical objects.
In quantum mechanics, states are represented by normalized complex column vectors, or kets (), and observables are Hermitian linear operators () that act on the kets. An eigenvector () of an observable is known as an eigenstate. Measuring an observable for one of its eigenstates () will give us the corresponding eigenvalue () as readout.
If you're wondering how to measure a quantum system and what you can measure, Qiskit offers two primitives that can help:
Sampler: Given a quantum state , this primitive obtains the probability of each possible computational basis state.Estimator: Given a quantum observable and a state , this primitive computes the expected value of .
The Sampler primitive
The Sampler primitive calculates the probability of obtaining each possible state from the computational basis, given a quantum circuit that prepares the state . It calculates
Where is the number of qubits, and the integer representation of any possible output binary string (that is, integers base ).
The Qiskit Runtime Sampler runs the circuit multiple times on a quantum device, performing measurements on each run, and reconstructing the probability distribution from the recovered bitstrings. The more runs (or shots) it performs, the more accurate the results will be, but this requires more time and quantum resources.
However, since the number of possible outputs grows exponentially with the number of qubits (that is, ), the number of shots will need to grow exponentially as well in order to capture a dense probability distribution. Therefore, Sampler is only efficient for sparse probability distributions; where the target state must be expressible as a linear combination of the computational basis states, with the number of terms growing at most polynomially with the number of qubits:
The Sampler can also be configured to retrieve probabilities from a subsection of the circuit, representing a subset of the total possible states.
The Estimator primitive
The Estimator primitive calculates the expectation value of an observable for a quantum state ; where the observable probabilities can be expressed as , being the eigenstates of the observable . The expectation value is then defined as the average of all possible outcomes (that is, the eigenvalues of the observable) of a measurement of the state