View on GitHub
Open this notebook in GitHub to run it yourself
Example 1: Sampling Arithmetics and changing number of shots
Output:
sample:
Output:
sample is a dataframe with information regarding execution:
| x | y | counts | probability | bitstring | |
|---|---|---|---|---|---|
| 0 | 7 | 50 | 280 | 0.136719 | 110010111 |
| 1 | 5 | 26 | 273 | 0.133301 | 011010101 |
| 2 | 1 | 2 | 266 | 0.129883 | 000010001 |
| 3 | 0 | 1 | 262 | 0.127930 | 000001000 |
| 4 | 2 | 5 | 250 | 0.122070 | 000101010 |
| 5 | 6 | 37 | 243 | 0.118652 | 100101110 |
| 6 | 3 | 10 | 238 | 0.116211 | 001010011 |
| 7 | 4 | 17 | 236 | 0.115234 | 010001100 |
countsshows the number of times each state was measured.bitstringis the bitstring that represents each state measured.xandyare the numerical representation of the states associated with the measurement.probabilityis the probability associated with each measured state.
sample.
For instance, if we want to execute the same circuit with shots:
Output:
| x | y | counts | probability | bitstring | |
|---|---|---|---|---|---|
| 0 | 3 | 10 | 1308 | 0.1308 | 001010011 |
| 1 | 7 | 50 | 1271 | 0.1271 | 110010111 |
| 2 | 4 | 17 | 1266 | 0.1266 | 010001100 |
| 3 | 0 | 1 | 1256 | 0.1256 | 000001000 |
| 4 | 2 | 5 | 1256 | 0.1256 | 000101010 |
| 5 | 6 | 37 | 1229 | 0.1229 | 100101110 |
| 6 | 1 | 2 | 1214 | 0.1214 | 000010001 |
| 7 | 5 | 26 | 1200 | 0.1200 | 011010101 |
Example 2: GHZ States and noise
Many simulators provide noise models that approximate the behavior of real quantum hardware. In this example, we create a GHZ state using the Classiq simulator while emulating the noise profile of IBM Pittsburgh, an IBM backend available through Classiq. We begin by defining the model for the GHZ state:noise_model entry through the config argument:
Output:
| x | counts | probability | bitstring | |
|---|---|---|---|---|
| 0 | [1, 1, 1] | 1014 | 0.495117 | 111 |
| 1 | [0, 0, 0] | 985 | 0.480957 | 000 |
| 2 | [0, 0, 1] | 10 | 0.004883 | 100 |
| 3 | [1, 1, 0] | 9 | 0.004395 | 011 |
| 4 | [0, 1, 1] | 9 | 0.004395 | 110 |
| 5 | [0, 1, 0] | 8 | 0.003906 | 010 |
| 6 | [1, 0, 1] | 7 | 0.003418 | 101 |
| 7 | [1, 0, 0] | 6 | 0.002930 | 001 |
[0, 0, 0] and [1, 1, 1], each occurring with approximately equal probability.
All other basis states should have zero probability.
Here, because the simulation includes a realistic noise model, a small fraction of the measurements appears in other states.
The dominant outcomes are still [0, 0, 0] and [1, 1, 1], but the presence of low-probability additional bitstrings reflects the effect of hardware noise on the quantum program execution.
State vector simulation
A state vector simulator returns the amplitudes of the quantum states produced by a quantum program. Unlike sampling, which estimates output probabilities from repeated measurements, state vector simulation gives direct access to the simulated quantum state. On real quantum hardware, these amplitudes are not directly observable. Reconstructing them requires quantum state tomography, which involves measuring the system in different bases to infer the output state. In this example, we calculate the state vector of the quantum program usingcalculate_state_vector:
Output:
| x | amplitude | magnitude | phase | probability | bitstring | |
|---|---|---|---|---|---|---|
| 0 | [0, 0, 0] | 0.707107+0.000000j | 0.71 | 0.00π | 0.5 | 000 |
| 1 | [1, 1, 1] | 0.707107+0.000000j | 0.71 | 0.00π | 0.5 | 111 |
amplitudeis the complex amplitude associated with each basis state.magnitudeis the absolute value of the amplitude.phaseis the phase of the amplitude.probabilityis the probability of measuring the corresponding state.bitstringis the bitstring representation of the basis state.xis the value of the quantum array. It is displayed as a list of 0s and 1s, with each entry corresponding to one qubit in the array.
[0, 0, 0] and [1, 1, 1], each with probability 0.5 and amplitude approximately .
Backend selection
The backend of an execution is the hardware or simulator where the quantum program is executed. To select a specific backend, it is necessary to know its correct name and provider. To do so, runget_backend_details() for a concise list of available backends.
| provider | backend | type | num_qubits | is_available | pending_jobs | queue_time | |
|---|---|---|---|---|---|---|---|
| 0 | classiq | nvidia_simulator | simulator | 29 | True | NaN | NaT |
| 1 | classiq | simulator | simulator | 28 | True | NaN | NaT |
| 2 | classiq | simulator_density_matrix | simulator | 28 | True | NaN | NaT |
| 3 | classiq | simulator_matrix_product_state | simulator | 28 | True | NaN | NaT |
| 4 | alice&bob | LOGICAL_EARLY | simulator | 15 | True | NaN | NaT |
"provider/backend" under the execution function used.
For example, you can use the Classiq simulator to realize a state vector simulation of the GHZ state, or the MPS simulator to sample over the same state:
Output:
| x | amplitude | magnitude | phase | probability | bitstring | |
|---|---|---|---|---|---|---|
| 0 | [0, 0, 0] | 0.707107+0.000000j | 0.71 | 0.00π | 0.5 | 000 |
| 1 | [1, 1, 1] | 0.707107+0.000000j | 0.71 | 0.00π | 0.5 | 111 |
| x | counts | probability | bitstring | |
|---|---|---|---|---|
| 0 | [0, 0, 0] | 1062 | 0.518555 | 000 |
| 1 | [1, 1, 1] | 986 | 0.481445 | 111 |