|
6 | 6 | "metadata": {}, |
7 | 7 | "source": [ |
8 | 8 | "---\n", |
9 | | - "title: Primitives examples\n", |
10 | | - "description: Practical examples of using primitives in Qiskit Runtime.\n", |
| 9 | + "title: Examples\n", |
| 10 | + "description: Practical examples of using the Executor primitve in Qiskit Runtime.\n", |
11 | 11 | "---\n", |
12 | 12 | "\n", |
13 | 13 | "\n", |
14 | | - "# Primitives examples" |
| 14 | + "# Executor examples" |
15 | 15 | ] |
16 | 16 | }, |
17 | 17 | { |
|
58 | 58 | "id": "bae32e60", |
59 | 59 | "metadata": {}, |
60 | 60 | "source": [ |
61 | | - "The examples in this section illustrate some common ways to use primitives. Before running these examples, follow the instructions in [Install and set up.](install-qiskit)\n", |
62 | | - "\n", |
63 | | - "<Admonition type=\"note\">\n", |
64 | | - " These examples all use the primitives from Qiskit Runtime, but you could use the base primitives instead.\n", |
65 | | - "</Admonition>\n", |
66 | | - "\n", |
67 | | - "## Estimator examples\n", |
68 | | - "\n", |
69 | | - "Efficiently calculate and interpret expectation values of the quantum operators required for many algorithms with Estimator. Explore uses in molecular modeling, machine learning, and complex optimization problems.\n", |
| 61 | + "The examples in this section illustrate some common ways to use the Executor primitive. Before running these examples, follow the instructions in [Install and set up.](install-qiskit)\n", |
70 | 62 | "\n", |
71 | 63 | "### Run a single experiment\n", |
72 | 64 | "\n", |
73 | | - "Use Estimator to determine the expectation value of a single circuit-observable pair." |
| 65 | + "Consider a circuit that generates a three-qubit GHZ state, rotates\n", |
| 66 | + "the qubits around the Pauli-Z axis, and measures the qubits in the computational basis. We show how\n", |
| 67 | + "to add this circuit to a `QuantumProgram`, optionally randomizing its content with twirling\n", |
| 68 | + "gates, and execute the program by using the `Executor` class." |
74 | 69 | ] |
75 | 70 | }, |
76 | 71 | { |
77 | 72 | "cell_type": "code", |
78 | | - "execution_count": 1, |
79 | | - "id": "24573866-7cf2-40e1-b61c-a2bdcecb759b", |
| 73 | + "execution_count": null, |
80 | 74 | "metadata": {}, |
81 | | - "outputs": [ |
82 | | - { |
83 | | - "name": "stdout", |
84 | | - "output_type": "stream", |
85 | | - "text": [ |
86 | | - " > Expectation value: -0.13582342954159593\n", |
87 | | - " > Metadata: {'shots': 4096, 'target_precision': 0.015625, 'circuit_metadata': {}, 'resilience': {}, 'num_randomizations': 32}\n" |
88 | | - ] |
89 | | - } |
90 | | - ], |
| 75 | + "outputs": [], |
91 | 76 | "source": [ |
92 | | - "import numpy as np\n", |
93 | | - "from qiskit.circuit.library import iqp\n", |
94 | | - "from qiskit.transpiler import generate_preset_pass_manager\n", |
95 | | - "from qiskit.quantum_info import SparsePauliOp, random_hermitian\n", |
96 | | - "from qiskit_ibm_runtime import QiskitRuntimeService, EstimatorV2 as Estimator\n", |
97 | | - "\n", |
98 | | - "n_qubits = 50\n", |
| 77 | + "from qiskit.circuit import Parameter, QuantumCircuit\n", |
| 78 | + "from qiskit_ibm_runtime import QiskitRuntimeService, Executor\n", |
| 79 | + "\n", |
| 80 | + "# Generate the circuit\n", |
| 81 | + "circuit = QuantumCircuit(3)\n", |
| 82 | + "circuit.h(0)\n", |
| 83 | + "circuit.h(1)\n", |
| 84 | + "circuit.cz(0, 1)\n", |
| 85 | + "circuit.h(1)\n", |
| 86 | + "circuit.h(2)\n", |
| 87 | + "circuit.cz(1, 2)\n", |
| 88 | + "circuit.h(2)\n", |
| 89 | + "circuit.rz(Parameter(\"theta\"), 0)\n", |
| 90 | + "circuit.rz(Parameter(\"phi\"), 1)\n", |
| 91 | + "circuit.rz(Parameter(\"lam\"), 2)\n", |
| 92 | + "circuit.measure_all()\n", |
99 | 93 | "\n", |
| 94 | + "# Initialize the service and choose a backend\n", |
100 | 95 | "service = QiskitRuntimeService()\n", |
101 | | - "backend = service.least_busy(\n", |
102 | | - " operational=True, simulator=False, min_num_qubits=n_qubits\n", |
103 | | - ")\n", |
104 | | - "\n", |
105 | | - "mat = np.real(random_hermitian(n_qubits, seed=1234))\n", |
106 | | - "circuit = iqp(mat)\n", |
107 | | - "observable = SparsePauliOp(\"Z\" * 50)\n", |
108 | | - "\n", |
109 | | - "pm = generate_preset_pass_manager(backend=backend, optimization_level=1)\n", |
110 | | - "isa_circuit = pm.run(circuit)\n", |
111 | | - "isa_observable = observable.apply_layout(isa_circuit.layout)\n", |
112 | | - "\n", |
113 | | - "estimator = Estimator(mode=backend)\n", |
114 | | - "job = estimator.run([(isa_circuit, isa_observable)])\n", |
115 | | - "result = job.result()\n", |
116 | | - "\n", |
117 | | - "print(f\" > Expectation value: {result[0].data.evs}\")\n", |
118 | | - "print(f\" > Metadata: {result[0].metadata}\")" |
| 96 | + "backend = service.least_busy(operational=True, simulator=False)" |
| 97 | + ] |
| 98 | + }, |
| 99 | + { |
| 100 | + "cell_type": "markdown", |
| 101 | + "metadata": {}, |
| 102 | + "source": [ |
| 103 | + "The inputs to the `Executor` are `QuantumProgram`s. For full details, see [Executor input and output.](/docs/guides/executor-input-output)" |
119 | 104 | ] |
120 | 105 | }, |
121 | 106 | { |
|
0 commit comments