@@ -136,6 +136,25 @@ def xeb_error(self, q0: 'cirq.GridQubit', q1: 'cirq.GridQubit') -> float:
136136 p = self ._record (q0 , q1 ).layer_fid
137137 return 1 - p
138138
139+ def all_errors (self ) -> Dict [Tuple ['cirq.GridQubit' , 'cirq.GridQubit' ], float ]:
140+ """Return the XEB error of all qubit pairs."""
141+ return {(q0 , q1 ): self .xeb_error (q0 , q1 ) for q0 , q1 in self .all_qubit_pairs }
142+
143+ def plot_histogram (self , ax : Optional [plt .Axes ] = None , ** plot_kwargs ):
144+ """plot a histogram of all xeb errors
145+
146+ Args:
147+ ax: the plt.Axes to plot on. If not given, a new figure is created,
148+ plotted on, and shown.
149+ **plot_kwargs: Arguments to be passed to 'plt.Axes.plot'.
150+ """
151+ fig = None
152+ if ax is None :
153+ fig , ax = plt .subplots (1 , 1 , figsize = (8 , 8 ))
154+ vis .integrated_histogram (data = self .all_errors (), ax = ax , ** plot_kwargs )
155+ if fig is not None :
156+ fig .show (** plot_kwargs )
157+
139158
140159def parallel_two_qubit_xeb (
141160 sampler : 'cirq.Sampler' ,
@@ -177,20 +196,17 @@ def parallel_two_qubit_xeb(
177196 ax .set_title ('device layout' )
178197 ax .plot (** plot_kwargs )
179198
180- print ('Generate circuit library' )
181199 circuit_library = rqcg .generate_library_of_2q_circuits (
182200 n_library_circuits = n_circuits , two_qubit_gate = entangling_gate , random_state = rs
183201 )
184202
185- print ('Generate random two qubit combinations' )
186203 combs_by_layer = rqcg .get_random_combinations_for_device (
187204 n_library_circuits = len (circuit_library ),
188205 n_combinations = n_combinations ,
189206 device_graph = graph ,
190207 random_state = rs ,
191208 )
192209
193- print ('Run circuits' )
194210 sampled_df = sample_2q_xeb_circuits (
195211 sampler = sampler ,
196212 circuits = circuit_library ,
@@ -200,10 +216,8 @@ def parallel_two_qubit_xeb(
200216 repetitions = n_repetitions ,
201217 )
202218
203- print ('Compute fidelities' )
204219 fids = benchmark_2q_xeb_fidelities (
205220 sampled_df = sampled_df , circuits = circuit_library , cycle_depths = cycle_depths
206221 )
207222
208- print ('Fit exponential decays' )
209223 return TwoQubitXEBResult (fit_exponential_decays (fids ))
0 commit comments