Skip to content

Commit 312b6c6

Browse files
Update code for runtime 0.24.1 (#1580)
This PR bumps the `qiskit_ibm_runtime` version to the most recent, and updates our code examples to work with that version. --------- Co-authored-by: Eric Arellano <[email protected]>
1 parent 1f2a2c2 commit 312b6c6

22 files changed

+105
-103
lines changed

docs/build/pulse.ipynb

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@
8787
"source": [
8888
"from qiskit import pulse\n",
8989
"from qiskit.pulse.library import Gaussian\n",
90-
"from qiskit_ibm_runtime.fake_provider import FakeValencia\n",
90+
"from qiskit_ibm_runtime.fake_provider import FakeValenciaV2\n",
9191
"\n",
92-
"backend = FakeValencia()\n",
92+
"backend = FakeValenciaV2()\n",
9393
"\n",
9494
"with pulse.build(backend, name='hadamard') as h_q0:\n",
9595
" pulse.play(Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(0))"
@@ -169,7 +169,22 @@
169169
"name": "stdout",
170170
"output_type": "stream",
171171
"text": [
172-
"['id', 'rz', 'sx', 'x', 'cx', 'reset']\n"
172+
"Instruction(name='sx', num_qubits=1, num_clbits=0, params=[]) (0,)\n",
173+
"Instruction(name='sx', num_qubits=1, num_clbits=0, params=[]) (1,)\n",
174+
"Instruction(name='cx', num_qubits=2, num_clbits=0, params=[]) (0, 1)\n",
175+
"Instruction(name='cx', num_qubits=2, num_clbits=0, params=[]) (1, 0)\n",
176+
"Instruction(name='reset', num_qubits=1, num_clbits=0, params=[]) (0,)\n",
177+
"Instruction(name='reset', num_qubits=1, num_clbits=0, params=[]) (1,)\n",
178+
"Instruction(name='x', num_qubits=1, num_clbits=0, params=[]) (0,)\n",
179+
"Instruction(name='x', num_qubits=1, num_clbits=0, params=[]) (1,)\n",
180+
"Delay(duration=t[unit=dt]) (0,)\n",
181+
"Delay(duration=t[unit=dt]) (1,)\n",
182+
"Instruction(name='measure', num_qubits=1, num_clbits=1, params=[]) (0,)\n",
183+
"Instruction(name='measure', num_qubits=1, num_clbits=1, params=[]) (1,)\n",
184+
"Instruction(name='id', num_qubits=1, num_clbits=0, params=[]) (0,)\n",
185+
"Instruction(name='id', num_qubits=1, num_clbits=0, params=[]) (1,)\n",
186+
"Instruction(name='rz', num_qubits=1, num_clbits=0, params=[Parameter(λ)]) (0,)\n",
187+
"Instruction(name='rz', num_qubits=1, num_clbits=0, params=[Parameter(λ)]) (1,)\n"
173188
]
174189
},
175190
{
@@ -187,14 +202,17 @@
187202
}
188203
],
189204
"source": [
190-
"from qiskit_ibm_runtime.fake_provider import FakeHanoi\n",
205+
"from qiskit_ibm_runtime.fake_provider import FakeHanoiV2\n",
191206
"from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager\n",
192207
"\n",
193-
"backend = FakeHanoi()\n",
208+
"backend = FakeHanoiV2()\n",
194209
"passmanager = generate_preset_pass_manager(optimization_level=1, backend=backend)\n",
195210
"circ = passmanager.run(circ)\n",
196211
"\n",
197-
"print(backend.configuration().basis_gates)\n",
212+
"# Print instructions that only affect qubits 0 and 1\n",
213+
"for instruction, qubits in FakeHanoiV2().instructions:\n",
214+
" if qubits and set(qubits).issubset({0, 1}):\n",
215+
" print(instruction, qubits)\n",
198216
"circ.draw('mpl', idle_wires=False)"
199217
]
200218
},
@@ -203,7 +221,7 @@
203221
"id": "aa09ca2c-25cb-4220-859e-c03dc710c6ea",
204222
"metadata": {},
205223
"source": [
206-
"Notice that `h` is not a basis gate for the mock backend `FakeHanoi`. Since you added a calibration for it, the transpiler will treat the gate as a basis gate, _but only on the qubits for which it was defined_. A Hadamard applied to a different qubit would be unrolled to the basis gates.\n",
224+
"Notice that `h` is not a basis gate for the mock backend `FakeHanoiV2`. Since you added a calibration for it, the transpiler will treat the gate as a basis gate, _but only on the qubits for which it was defined_. A Hadamard applied to a different qubit would be unrolled to the basis gates.\n",
207225
"\n",
208226
"### Custom gates\n",
209227
"\n",
@@ -339,12 +357,12 @@
339357
"metadata": {},
340358
"outputs": [],
341359
"source": [
342-
"from qiskit_ibm_runtime.fake_provider import FakePerth\n",
360+
"from qiskit_ibm_runtime.fake_provider import FakeKyoto\n",
343361
"from qiskit.circuit import QuantumCircuit, Gate\n",
344362
"from qiskit.pulse import builder, DriveChannel\n",
345363
"from qiskit.transpiler import InstructionProperties\n",
346364
"\n",
347-
"backend = FakePerth()\n",
365+
"backend = FakeKyoto()\n",
348366
"\n",
349367
"custom_gate = Gate(\"my_gate\", 1, [])\n",
350368
"qc = QuantumCircuit(1, 1)\n",
@@ -493,9 +511,9 @@
493511
}
494512
],
495513
"source": [
496-
"from qiskit_ibm_runtime.fake_provider import FakeValencia\n",
514+
"from qiskit_ibm_runtime.fake_provider import FakeValenciaV2\n",
497515
"\n",
498-
"backend = FakeValencia()\n",
516+
"backend = FakeValenciaV2()\n",
499517
"\n",
500518
"with pulse.build(backend=backend, name='backend_aware') as backend_aware_program:\n",
501519
" channel = pulse.drive_channel(0)\n",

docs/run/advanced-runtime-options.mdx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ When creating an instance of the `Estimator` or `Sampler` class, you can pass in
6161
`SamplerV2` and `EstimatorV2` have separate options classes that do not need to be instantiated. You can see the available options and update option values during or after primitive initialization. Those options will then be applied when you use `run()` to perform the calculation. Example:
6262

6363
```python
64-
estimator = Estimator(backend=backend)
64+
estimator = Estimator(mode=backend)
6565

6666
# Setting options after primitive initialization
6767
# This uses auto complete.
@@ -74,7 +74,7 @@ estimator.options.default_shots = 4000
7474
When creating an instance of the `Estimator` or `Sampler` class, you can pass in the `options` you created in the options class. Those options will then be applied when you use `run()` to perform the calculation. Example:
7575

7676
```python
77-
estimator = Estimator(session=backend, options=options)
77+
estimator = Estimator(mode=backend, options=options)
7878
result = estimator.run(circuit, observable).result()
7979
print(f">>> Metadata: {result.metadata[0]}")
8080
```
@@ -131,7 +131,7 @@ sampler.run([circuit1, circuit2], shots=128)
131131
<TabItem value="PrimV1" label="V1 primitives">
132132
You can pass any options to `run()`. Because most users will only overwrite a few options at the job level, it is not necessary to specify the options category. The code below, for example, specifies `shots=1024` instead of `execution={"shots": 1024}` (which is also valid).
133133
```python
134-
estimator = Estimator(session=backend, options=options)
134+
estimator = Estimator(mode=backend, options=options)
135135
result = estimator.run(circuit, observable, shots=1024).result()
136136
print(f">>> Metadata: {result.metadata[0]}")
137137
```
@@ -176,7 +176,7 @@ from qiskit_ibm_runtime import Estimator, Options
176176
options = Options()
177177
options.execution.shots = 1024
178178

179-
estimator = Estimator(session=backend, options=options)
179+
estimator = Estimator(mode=backend, options=options)
180180
```
181181

182182
If you need to modify the number of shots set between iterations (primitive calls), you can set the
@@ -185,7 +185,7 @@ shots directly in the `run()` method. This overwrites the initial `shots` settin
185185
```python
186186
from qiskit_ibm_runtime import Estimator
187187

188-
estimator = Estimator(session=backend)
188+
estimator = Estimator(mode=backend)
189189

190190
estimator.run(circuits=circuits, observables=observables, shots=50)
191191

@@ -218,7 +218,7 @@ See the Optimization level table in the
218218
```python
219219
from qiskit_ibm_runtime import EstimatorV2 as Estimator
220220

221-
estimator = Estimator(session=backend, options={"optimization_level": 1})
221+
estimator = Estimator(mode=backend, options={"optimization_level": 1})
222222

223223
# or..
224224
estimator.options.optimization_level = 1
@@ -243,7 +243,7 @@ options = Options(optimization_level=1)
243243
options = Options()
244244
options.optimization_level = 1
245245

246-
estimator = Estimator(session=backend, options=options)
246+
estimator = Estimator(mode=backend, options=options)
247247
```
248248

249249
Turning off all optional runtime compilation steps requires a "second-level option", as follows:
@@ -254,7 +254,7 @@ from qiskit_ibm_runtime import Estimator, Options
254254
options = Options()
255255
options.transpilation.skip_transpilation = True
256256

257-
estimator = Estimator(session=backend, options=options)
257+
estimator = Estimator(mode=backend, options=options)
258258
```
259259

260260
For more information and a complete list of advanced transpilation options, see the Advanced transpilation options table in the
@@ -274,7 +274,7 @@ algorithm. These methods can be set through the `resilience_level` option. For
274274
With Estimator V2, you can set resilience levels 0-2 and you can also turn on and off various error mitigation settings for fine-tuning.
275275

276276
```python
277-
estimator = Estimator(backend=backend)
277+
estimator = Estimator(mode=backend)
278278

279279
estimator.options.resilience_level = 2
280280
estimator.options.resilience.zne_mitigation = True
@@ -298,7 +298,7 @@ options = Options(resilience_level = 2)
298298
options = Options()
299299
options.resilience_level = 2
300300

301-
estimator = Estimator(session=backend, options=options)
301+
estimator = Estimator(mode=backend, options=options)
302302
```
303303
</TabItem>
304304
</Tabs>

docs/run/circuit-execution.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ backend = service.least_busy(operational=True, min_num_qubits=100, dynamic_repra
4040

4141
# Determine the allowable range
4242
backend.rep_delay_range
43-
sampler = Sampler(backend=backend)
43+
sampler = Sampler(mode=backend)
4444

4545
#Specify a value in the supported range
4646
sampler.options.execution.rep_delay = 0.0005

docs/run/configure-error-mitigation.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ options.resilience_level = 2
334334
options.optimization_level = 1
335335
backend = service.least_busy(operational=True, simulator=False)
336336

337-
estimator = Estimator(options=options, backend=backend)
337+
estimator = Estimator(options=options, mode=backend)
338338
```
339339

340340
<Admonition type="info" title="Note">
@@ -466,7 +466,7 @@ options.resilience.noise_amplifier = 'CxAmplifier'
466466
options.resilience.extrapolator = 'QuadraticExtrapolator'
467467
backend = service.least_busy(operational=True, simulator=False)
468468

469-
estimator = Estimator(options=options, backend=backend)
469+
estimator = Estimator(options=options, mode=backend)
470470
job = estimator.run(circuits=[psi1], observables=[H1], parameter_values=[theta1])
471471
psi1_H1 = job.result()
472472
```

docs/run/configure-runtime-compilation.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pm = generate_preset_pass_manager(backend=backend, optimization_level=1)
8888
psi = pm.run(psi)
8989
H = H.apply_layout(psi.layout)
9090

91-
estimator = Estimator(backend=backend)
91+
estimator = Estimator(mode=backend)
9292

9393
estimator.options.optimization_level = 1
9494

@@ -117,7 +117,7 @@ pm = generate_preset_pass_manager(backend=backend, optimization_level=1)
117117
psi = pm.run(psi)
118118
H = H.apply_layout(psi.layout)
119119

120-
estimator = Estimator (options=options, backend=backend)
120+
estimator = Estimator(options=options, mode=backend)
121121

122122
job = estimator.run(circuits=[psi], observables=[H], parameter_values=[theta])
123123
psi1_H1 = job.result()

docs/run/error-mitigation-explanation.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
},
6969
"outputs": [],
7070
"source": [
71-
"estimator = Estimator(backend=backend)\n",
71+
"estimator = Estimator(mode=backend)\n",
7272
"estimator.options.dynamical_decoupling.enable = True\n",
7373
"estimator.options.dynamical_decoupling.sequence_type = \"XpXm\""
7474
]
@@ -114,7 +114,7 @@
114114
"metadata": {},
115115
"outputs": [],
116116
"source": [
117-
"estimator = Estimator(backend=backend)\n",
117+
"estimator = Estimator(mode=backend)\n",
118118
"estimator.options.twirling.enable_gates = True\n",
119119
"estimator.options.twirling.num_randomizations = 32\n",
120120
"estimator.options.twirling.shots_per_randomization = 100"
@@ -153,7 +153,7 @@
153153
"metadata": {},
154154
"outputs": [],
155155
"source": [
156-
"estimator = Estimator(backend=backend)\n",
156+
"estimator = Estimator(mode=backend)\n",
157157
"estimator.options.resilience.measure_mitigation = True\n",
158158
"estimator.options.resilience.measure_noise_learning.num_randomizations = 32\n",
159159
"estimator.options.resilience.measure_noise_learning.shots_per_randomization = 100"
@@ -201,7 +201,7 @@
201201
"metadata": {},
202202
"outputs": [],
203203
"source": [
204-
"estimator = Estimator(backend=backend)\n",
204+
"estimator = Estimator(mode=backend)\n",
205205
"estimator.options.resilience.zne_mitigation = True\n",
206206
"estimator.options.resilience.zne.noise_factors = (1, 3, 5)\n",
207207
"estimator.options.resilience.zne.extrapolator = \"exponential\""
@@ -243,7 +243,7 @@
243243
"metadata": {},
244244
"outputs": [],
245245
"source": [
246-
"estimator = Estimator(backend=backend)\n",
246+
"estimator = Estimator(mode=backend)\n",
247247
"estimator.options.resilience.pec_mitigation = True\n",
248248
"estimator.options.resilience.pec.max_overhead = 100"
249249
]

docs/run/instances.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ backend1 = service.backend("ibmq_manila")
6969
# Optional: Specify it at the backend level, which overwrites the service-level specification when this backend is used.
7070
backend2 = service.backend("ibmq_manila", instance="hub2/group2/project2")
7171

72-
sampler1 = SamplerV2(backend=backend1) # this will use hub1/group1/project1
73-
sampler2 = SamplerV2(backend=backend2) # this will use hub2/group2/project2
72+
sampler1 = SamplerV2(mode=backend1) # this will use hub1/group1/project1
73+
sampler2 = SamplerV2(mode=backend2) # this will use hub2/group2/project2
7474
```
7575
</TabItem>
7676

@@ -88,8 +88,8 @@ backend1 = service.backend("ibmq_manila")
8888
# Optional: Specify it at the backend level, which overwrites the service-level specification when this backend is used.
8989
backend2 = service.backend("ibmq_manila", instance="hub2/group2/project2")
9090

91-
sampler1 = Sampler(backend=backend1) # this will use hub1/group1/project1
92-
sampler2 = Sampler(backend=backend2) # this will use hub2/group2/project2
91+
sampler1 = Sampler(mode=backend1) # this will use hub1/group1/project1
92+
sampler2 = Sampler(mode=backend2) # this will use hub2/group2/project2
9393
```
9494
</TabItem>
9595
</Tabs>

docs/run/primitives-examples.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ isa_observable = observable.apply_layout(isa_circuit.layout)
355355
another_isa_observable = another_observable.apply_layout(another_isa_circuit.layout)
356356

357357
with Session(service=service, backend=backend) as session:
358-
estimator = Estimator(session=session)
358+
estimator = Estimator(mode=session)
359359

360360
estimator.options.optimization_level = 1
361361
estimator.options.resilience_level = 1
@@ -414,7 +414,7 @@ options.optimization_level = 2
414414
options.resilience_level = 2
415415

416416
with Session(service=service, backend=backend) as session:
417-
estimator = Estimator(session=session, options=options)
417+
estimator = Estimator(mode=session, options=options)
418418
job = estimator.run(isa_circuit, isa_observable)
419419
another_job = estimator.run(another_isa_circuit, another_isa_observable)
420420
result = job.result()
@@ -692,7 +692,7 @@ isa_circuit = pm.run(circuit)
692692
another_isa_circuit = pm.run(another_circuit)
693693

694694
with Session(backend=backend) as session:
695-
sampler = Sampler(session=session)
695+
sampler = Sampler(mode=session)
696696
job = sampler.run([isa_circuit])
697697
another_job = sampler.run([another_isa_circuit])
698698
result = job.result()
@@ -746,7 +746,7 @@ options.optimization_level = 2
746746
options.resilience_level = 0
747747

748748
with Session(service=service, backend=backend) as session:
749-
sampler = Sampler(session=session, options=options)
749+
sampler = Sampler(mode=session, options=options)
750750
job = sampler.run(isa_circuit)
751751
another_job = sampler.run(another_isa_circuit)
752752
result = job.result()

docs/run/primitives-get-started.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ from qiskit_ibm_runtime import QiskitRuntimeService, EstimatorV2 as Estimator
3939

4040
service = QiskitRuntimeService()
4141
backend = service.least_busy(operational=True, simulator=False, min_num_qubits=127)
42-
estimator = Estimator(backend)
42+
estimator = Estimator(mode=backend)
4343
```
4444

4545
### 2. Create a circuit and an observable
@@ -83,15 +83,15 @@ To use the Estimator V2, import the **EstimatorV2** class. The **Estimator** cla
8383
```python
8484
from qiskit_ibm_runtime import EstimatorV2 as Estimator
8585

86-
estimator = Estimator(backend=backend)
86+
estimator = Estimator(mode=backend)
8787
```
8888
</TabItem>
8989

9090
<TabItem value="EstimatorV1" label="Estimator (V1)">
9191
```python
9292
from qiskit_ibm_runtime import Estimator
9393

94-
estimator = Estimator(backend=backend)
94+
estimator = Estimator(mode=backend)
9595
```
9696
</TabItem>
9797
</Tabs>
@@ -197,15 +197,15 @@ To use the Sampler V2, import the **SamplerV2** class. The **Sampler** class sti
197197
```python
198198
from qiskit_ibm_runtime import SamplerV2 as Sampler
199199

200-
sampler = Sampler(backend=backend)
200+
sampler = Sampler(mode=backend)
201201
```
202202
</TabItem>
203203

204204
<TabItem value="SamplerV1" label="Sampler (V1)">
205205
```python
206206
from qiskit_ibm_runtime import Sampler
207207

208-
sampler = Sampler(backend=backend)
208+
sampler = Sampler(mode=backend)
209209
```
210210
</TabItem>
211211
</Tabs>

docs/run/quantum-serverless.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ target_circuit = selector.optimized_circuit
166166
# target_circuit = pm.run(abstract_circuit)
167167

168168
# Step 3: Execute the target circuit
169-
sampler = Sampler(backend=backend, options={"default_shots": 1024})
169+
sampler = Sampler(mode=backend, options={"default_shots": 1024})
170170
job = sampler.run([target_circuit])
171171
result = job.result()
172172

0 commit comments

Comments
 (0)