Skip to content

Commit a9e2422

Browse files
authored
Promote analysis results deprecation (#1532)
* Replace `deprecate_arg` with `warn_from_qe` for issuing deprecation warnings from internal qiskit-experiments code. `deprecate_arg` was not working for the cases it was being used for (deprecating the default value of a keyword argument, deprecating the type of an argument in a function that could be called at different stack levels). `warn_from_qe` blames the caller of qiskit-experiments. The docstring deprecation message has to be added separately. * Promote the deprecation of `ExperimentData.add_analysis_results(results)`. This was previously a pending deprecation. Now results must be added via keyword arguments for their properties. All internal usage was updated not to issue deprecation warnings. `add_analysis_result` was added as an alias to reflect that only one result should be added at a time now. * Promote deprecation of `ExperimentData.analysis_results(dataframe=False)`. All internal usage was updated not to trigger deprecation warnings. The default remains `dataframe=False` for backwards compatibility. This default should not change in the near term because this is a major user-facing change. * Update `RBAnalysis` to accept the dataframe version of the analysis result as the `epg_1_qubit` option. * Add `AnalysisResultData.as_table_element` for convenience in passing a result data object to `add_analysis_result`. * Use `warn_from_qe` to warn about slice and integer arguments to `analysis_results`. This might result in warnings being visible that were previously hidden by stack level.
1 parent 3467069 commit a9e2422

File tree

60 files changed

+737
-748
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+737
-748
lines changed

docs/howtos/cloud_service.rst

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -67,51 +67,11 @@ Now we can display the figure from the loaded experiment data:
6767

6868
.. image:: ./experiment_cloud_service/t1_loaded.png
6969

70-
The analysis results have been retrieved as well:
70+
The analysis results have been retrieved as well and can be accessed normally.
7171

7272
.. jupyter-input::
7373

74-
for result in load_expdata.analysis_results():
75-
print(result)
76-
77-
.. jupyter-output::
78-
79-
AnalysisResult
80-
- name: T1
81-
- value: 0.0001040+/-0.0000028
82-
- χ²: 0.8523786276663019
83-
- quality: good
84-
- extra: <1 items>
85-
- device_components: ['Q0']
86-
- verified: False
87-
AnalysisResult
88-
- name: @Parameters_T1Analysis
89-
- value: CurveFitResult:
90-
- fitting method: least_squares
91-
- number of sub-models: 1
92-
* F_exp_decay(x) = amp * exp(-x/tau) + base
93-
- success: True
94-
- number of function evals: 9
95-
- degree of freedom: 9
96-
- chi-square: 7.671407648996717
97-
- reduced chi-square: 0.8523786276663019
98-
- Akaike info crit.: 0.6311217041870707
99-
- Bayesian info crit.: 2.085841653551072
100-
- init params:
101-
* amp = 0.923076923076923
102-
* tau = 0.00016946294665316433
103-
* base = 0.033466533466533464
104-
- fit params:
105-
* amp = 0.9266620487665083 ± 0.007096409569790425
106-
* tau = 0.00010401411623191737 ± 2.767679521974391e-06
107-
* base = 0.036302726197354626 ± 0.0037184540724124844
108-
- correlations:
109-
* (tau, base) = -0.6740808746060173
110-
* (amp, base) = -0.4231810882291163
111-
* (amp, tau) = 0.09302612202500576
112-
- quality: good
113-
- device_components: ['Q0']
114-
- verified: False
74+
results = load_expdata.analysis_results(dataframe=True))
11575

11676
Discussion
11777
----------

docs/manuals/characterization/t1.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ for qubit 0.
7575

7676
# Print the result
7777
display(exp_data.figure(0))
78-
for result in exp_data.analysis_results():
79-
print(result)
78+
print(exp_data.analysis_results(dataframe=True))
8079

8180

8281
:math:`T_1` experiments with kerneled measurement
@@ -135,8 +134,7 @@ that is close to a logical value '0'.
135134

136135
# Displaying results
137136
display(expdataT1_kerneled.figure(0))
138-
for result in expdataT1_kerneled.analysis_results():
139-
print(result)
137+
display(expdataT1_kerneled.analysis_results(dataframe=True))
140138

141139
See also
142140
--------

docs/manuals/characterization/t2hahn.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ The resulting graph will have the form:
105105
.. jupyter-execute::
106106

107107
# Print results
108-
for result in expdata1.analysis_results():
109-
print(result)
108+
display(expdata1.analysis_results(dataframe=True))
110109

111110

112111
Providing initial user estimates
@@ -136,8 +135,7 @@ computed for other qubits.
136135
.. jupyter-execute::
137136

138137
# Print results
139-
for result in expdata_with_p0.analysis_results():
140-
print(result)
138+
display(expdata_with_p0.analysis_results(dataframe=True))
141139

142140

143141

docs/manuals/characterization/t2ramsey.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ frequency.
9898
.. jupyter-execute::
9999

100100
# Print results
101-
for result in expdata1.analysis_results():
102-
print(result)
101+
display(expdata1.analysis_results(dataframe=True))
103102

104103

105104
Providing initial user estimates
@@ -137,8 +136,7 @@ computed for other qubits.
137136
.. jupyter-execute::
138137

139138
# Print results
140-
for result in expdata_with_p0.analysis_results():
141-
print(result)
139+
display(expdata_with_p0.analysis_results(dataframe=True))
142140

143141

144142
See also

docs/manuals/characterization/tphi.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,20 @@ Run the experiment and print results:
6666
.. jupyter-execute::
6767

6868
expdata = exp.run(backend=backend, seed_simulator=100).block_for_results()
69-
result = expdata.analysis_results("T_phi")
70-
print(result)
69+
display(expdata.analysis_results("T_phi", dataframe=True))
7170

7271
You can also retrieve the results and figures of the constituent experiments. :class:`.T1`:
7372

7473
.. jupyter-execute::
7574

76-
print(expdata.analysis_results("T1"))
75+
display(expdata.analysis_results("T1", dataframe=True))
7776
display(expdata.figure(0))
7877

7978
And :class:`.T2Hahn`:
8079

8180
.. jupyter-execute::
8281

83-
print(expdata.analysis_results("T2"))
82+
display(expdata.analysis_results("T2", dataframe=True))
8483
display(expdata.figure(1))
8584

8685
Let's now run the experiment with :class:`.T2Ramsey` by setting the ``t2type`` option to
@@ -102,7 +101,7 @@ Run and display results:
102101
.. jupyter-execute::
103102

104103
expdata = exp.run(backend=backend, seed_simulator=100).block_for_results()
105-
print(expdata.analysis_results("T_phi"))
104+
display(expdata.analysis_results("T_phi", dataframe=True))
106105
display(expdata.figure(1))
107106

108107
Because we are using a simulator that doesn't model inhomogeneous broadening, the

docs/manuals/measurement/readout_mitigation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ circuits, one for all “0” and one for all “1” results.
7070

7171
exp.analysis.set_options(plot=True)
7272
result = exp.run(backend)
73-
mitigator = result.analysis_results("Local Readout Mitigator").value
73+
mitigator = result.analysis_results("Local Readout Mitigator", dataframe=True).iloc[0].value
7474

7575
The resulting measurement matrix can be illustrated by comparing it to
7676
the identity.

docs/manuals/verification/quantum_volume.rst

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,7 @@ Extra data included in the analysis results includes
100100
# View result data
101101
display(expdata.figure(0))
102102

103-
for result in expdata.analysis_results():
104-
print(result)
105-
106-
107-
.. jupyter-execute::
108-
109-
# Print extra data
110-
for result in expdata.analysis_results():
111-
print(f"\n{result.name} extra:")
112-
for key, val in result.extra.items():
113-
print(f"- {key}: {val}")
103+
display(expdata.analysis_results(dataframe=True))
114104

115105

116106
Adding trials
@@ -131,8 +121,7 @@ re-running the experiment.
131121

132122
# View result data
133123
display(expdata2.figure(0))
134-
for result in expdata2.analysis_results():
135-
print(result)
124+
display(expdata2.analysis_results(dataframe=True))
136125

137126

138127
Calculating Quantum Volume using a batch experiment
@@ -157,10 +146,7 @@ Extracting the maximum Quantum Volume.
157146

158147
.. jupyter-execute::
159148

160-
qv_values = [
161-
batch_expdata.analysis_results("quantum_volume")[i].value
162-
for i in range(batch_exp.num_experiments)
163-
]
149+
qv_values = batch_expdata.analysis_results("quantum_volume", dataframe=True).value.tolist()
164150

165151
print(f"Max quantum volume is: {max(qv_values)}")
166152

@@ -170,8 +156,7 @@ Extracting the maximum Quantum Volume.
170156
for i in range(batch_exp.num_experiments):
171157
print(f"\nComponent experiment {i}")
172158
display(batch_expdata.figure(i))
173-
for result in batch_expdata.analysis_results():
174-
print(result)
159+
display(batch_expdata.analysis_results(dataframe=True))
175160

176161
References
177162
----------

docs/manuals/verification/randomized_benchmarking.rst

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,11 @@ interleaved RB experiment will always give you accurate error value :math:`e_i`.
109109
# Run an RB experiment on qubit 0
110110
exp1 = StandardRB(qubits, lengths, num_samples=num_samples, seed=seed)
111111
expdata1 = exp1.run(backend).block_for_results()
112-
results1 = expdata1.analysis_results()
113112

114113
# View result data
115114
print("Gate error ratio: %s" % expdata1.experiment.analysis.options.gate_error_ratio)
116115
display(expdata1.figure(0))
117-
for result in results1:
118-
print(result)
119-
116+
display(expdata1.analysis_results(dataframe=True))
120117

121118

122119
Running a 2-qubit RB experiment
@@ -193,16 +190,15 @@ The EPGs of two-qubit RB are analyzed with the corrected EPC if available.
193190
exp_2q = StandardRB(qubits, lengths_2_qubit, num_samples=num_samples, seed=seed)
194191

195192
# Use the EPG data of the 1-qubit runs to ensure correct 2-qubit EPG computation
196-
exp_2q.analysis.set_options(epg_1_qubit=expdata_1q.analysis_results())
193+
exp_2q.analysis.set_options(epg_1_qubit=expdata_1q.analysis_results(dataframe=True))
197194

198195
# Run the 2-qubit experiment
199196
expdata_2q = exp_2q.run(backend).block_for_results()
200197

201198
# View result data
202199
print("Gate error ratio: %s" % expdata_2q.experiment.analysis.options.gate_error_ratio)
203200
display(expdata_2q.figure(0))
204-
for result in expdata_2q.analysis_results():
205-
print(result)
201+
display(expdata_2q.analysis_results(dataframe=True))
206202

207203

208204
Note that ``EPC_corrected`` value is smaller than one of raw ``EPC``, which indicates
@@ -280,14 +276,13 @@ Let's run an interleaved RB experiment on two qubits:
280276
circuits.CXGate(), qubits, lengths, num_samples=num_samples, seed=seed)
281277

282278
int_expdata2 = int_exp2.run(backend).block_for_results()
283-
int_results2 = int_expdata2.analysis_results()
279+
int_results2 = int_expdata2.analysis_results(dataframe=True)
284280

285281
.. jupyter-execute::
286282

287283
# View result data
288284
display(int_expdata2.figure(0))
289-
for result in int_results2:
290-
print(result)
285+
display(int_results2)
291286

292287

293288
References

docs/manuals/verification/state_tomography.rst

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ to describe the preparation circuit.
4545
qstdata1 = qstexp1.run(backend, seed_simulation=100).block_for_results()
4646

4747
# Print results
48-
for result in qstdata1.analysis_results():
49-
print(result)
50-
48+
display(qstdata1.analysis_results(dataframe=True))
5149

5250

5351
Tomography Results
@@ -58,15 +56,16 @@ The main result for tomography is the fitted state, which is stored as a
5856

5957
.. jupyter-execute::
6058

61-
state_result = qstdata1.analysis_results("state")
59+
state_result = qstdata1.analysis_results("state", dataframe=True).iloc[0]
6260
print(state_result.value)
6361

6462
We can also visualize the density matrix:
6563

6664
.. jupyter-execute::
6765

6866
from qiskit.visualization import plot_state_city
69-
plot_state_city(qstdata1.analysis_results("state").value, title='Density Matrix')
67+
state = qstdata1.analysis_results("state", dataframe=True).iloc[0].value
68+
plot_state_city(state, title='Density Matrix')
7069

7170
The state fidelity of the fitted state with the ideal state prepared by
7271
the input circuit is stored in the ``"state_fidelity"`` result field.
@@ -76,22 +75,19 @@ state cannot be automatically generated and this field will be set to
7675

7776
.. jupyter-execute::
7877

79-
fid_result = qstdata1.analysis_results("state_fidelity")
78+
fid_result = qstdata1.analysis_results("state_fidelity", dataframe=True).iloc[0]
8079
print("State Fidelity = {:.5f}".format(fid_result.value))
8180

8281

8382

8483
Additional state metadata
8584
^^^^^^^^^^^^^^^^^^^^^^^^^
8685

87-
Additional data is stored in the tomography under the
88-
``"state_metadata"`` field. This includes
86+
Additional data is stored in the tomography under additional fields. This includes
8987

9088
- ``eigvals``: the eigenvalues of the fitted state
9189
- ``trace``: the trace of the fitted state
9290
- ``positive``: Whether the eigenvalues are all non-negative
93-
- ``positive_delta``: the deviation from positivity given by 1-norm of negative
94-
eigenvalues.
9591

9692
If trace rescaling was performed this dictionary will also contain a ``raw_trace`` field
9793
containing the trace before rescaling. Futhermore, if the state was rescaled to be
@@ -100,7 +96,8 @@ eigenvalues before rescaling was performed.
10096

10197
.. jupyter-execute::
10298

103-
state_result.extra
99+
for col in ["eigvals", "trace", "positive"]:
100+
print(f"{col}: {state_result[col]}")
104101

105102
To see the effect of rescaling, we can perform a “bad” fit with very low
106103
counts:
@@ -109,14 +106,11 @@ counts:
109106

110107
# QST Experiment
111108
bad_data = qstexp1.run(backend, shots=10, seed_simulation=100).block_for_results()
112-
bad_state_result = bad_data.analysis_results("state")
109+
bad_state_result = bad_data.analysis_results("state", dataframe=True).iloc[0]
113110

114111
# Print result
115-
print(bad_state_result)
116-
117-
# Show extra data
118-
bad_state_result.extra
119-
112+
for key, val in bad_state_result.items():
113+
print(f"{key}: {val}")
120114

121115

122116
Tomography Fitters
@@ -144,11 +138,9 @@ PSD without requiring rescaling.
144138
# Re-run experiment
145139
qstdata2 = qstexp1.run(backend, seed_simulation=100).block_for_results()
146140

147-
state_result2 = qstdata2.analysis_results("state")
148-
print(state_result2)
149-
print("\nextra:")
150-
for key, val in state_result2.extra.items():
151-
print(f"- {key}: {val}")
141+
state_result2 = qstdata2.analysis_results("state", dataframe=True).iloc[0]
142+
for key, val in state_result2.items():
143+
print(f"{key}: {val}")
152144

153145
except ModuleNotFoundError:
154146
print("CVXPY is not installed")
@@ -175,20 +167,14 @@ For example if we want to perform 1-qubit QST on several qubits at once:
175167
parexp = ParallelExperiment(subexps)
176168
pardata = parexp.run(backend, seed_simulation=100).block_for_results()
177169

178-
for result in pardata.analysis_results():
179-
print(result)
170+
display(pardata.analysis_results(dataframe=True))
180171

181-
View component experiment analysis results:
172+
View experiment analysis results for one component:
182173

183174
.. jupyter-execute::
184175

185-
for i, expdata in enumerate(pardata.child_data()):
186-
state_result_i = expdata.analysis_results("state")
187-
fid_result_i = expdata.analysis_results("state_fidelity")
188-
189-
print(f'\nPARALLEL EXP {i}')
190-
print("State Fidelity: {:.5f}".format(fid_result_i.value))
191-
print("State: {}".format(state_result_i.value))
176+
results = pardata.analysis_results(dataframe=True)
177+
display(results[results.components.apply(lambda x: x == ["Q0"])])
192178

193179
References
194180
----------

docs/release_notes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2483,7 +2483,7 @@ Upgrade Notes
24832483
- The data format of analysis result data value has been replaced from
24842484
:class:`FitVal` to ``uncertainties.ufloat`` from the Python
24852485
`uncertainties <https://pythonhosted.org/uncertainties/>`__ package to support
2486-
error propatation for post analysis computation.
2486+
error propagation for post analysis computation.
24872487

24882488
.. code-block:: python
24892489

0 commit comments

Comments
 (0)