@@ -769,7 +769,7 @@ def create_random_circuit(pspec, length, qubit_labels=None, sampler='Qeliminatio
769
769
layer = sample_circuit_layer_of_one_q_gates (pspec , qubit_labels , * lsargs , rand_state = rand_state )
770
770
# For even layers, we sample according to the given distribution
771
771
else :
772
- layer = sampler (pspec , qubit_labels , * samplerargs )
772
+ layer = sampler (pspec , qubit_labels , * samplerargs , rand_state = rand_state )
773
773
circuit .insert_layer_inplace (layer , 0 )
774
774
775
775
circuit .done_editing ()
@@ -1990,7 +1990,7 @@ def create_random_germpower_mirror_circuits(pspec, absolute_compilation, depths,
1990
1990
return circlist , outlist , aux
1991
1991
1992
1992
###begin BiRB tools###
1993
- def _stabilizer_to_all_zs (stabilizer , qubit_labels , absolute_compilation ):
1993
+ def _stabilizer_to_all_zs (stabilizer , qubit_labels , absolute_compilation , seed = None ):
1994
1994
#inputs:
1995
1995
# - stabilizer: An n-qubit Pauli, represented as a string of X, Y, Z, and Is.
1996
1996
# - qubit_labels: list/tuple of qubit labels
@@ -1999,6 +1999,8 @@ def _stabilizer_to_all_zs(stabilizer, qubit_labels, absolute_compilation):
1999
1999
# into a Pauli with only Zs and Is.
2000
2000
# - s, layer, p_layer: Symplectic representation of the layer
2001
2001
# - stab_circuit: Layer as a compiled circuit
2002
+ rng = _np .random .default_rng (seed )
2003
+
2002
2004
n = len (stabilizer )
2003
2005
2004
2006
symp_reps = _symp .compute_internal_gate_symplectic_representations ()
@@ -2018,7 +2020,7 @@ def _stabilizer_to_all_zs(stabilizer, qubit_labels, absolute_compilation):
2018
2020
stab_layer .append ((s_h , p_h ))
2019
2021
c .append (_lbl .Label ('C12' ,'{}' .format (qubit_labels [i ])))
2020
2022
elif stabilizer [i ] == 'I' :
2021
- rand_clifford = str (_np . random .choice (_np .arange (24 )))
2023
+ rand_clifford = str (rng .choice (_np .arange (24 )))
2022
2024
s_rand , p_rand = symp_reps ['C' + rand_clifford ]
2023
2025
stab_layer .append ((s_rand , p_rand ))
2024
2026
c .append (_lbl .Label ('C' + rand_clifford ,'{}' .format (qubit_labels [i ])))
@@ -2064,7 +2066,7 @@ def _symplectic_to_pauli(s,p):
2064
2066
2065
2067
return pauli
2066
2068
2067
- def _sample_random_pauli (n ,pspec = None , absolute_compilation = None , qubit_labels = None , circuit = False , include_identity = False ):
2069
+ def _sample_random_pauli (n ,pspec = None , absolute_compilation = None , qubit_labels = None , circuit = False , include_identity = False , seed = None ):
2068
2070
# Samples a random Pauli along with a +-1 phase. Returns the Pauli as a list or as a circuit depending
2069
2071
# upon the value of "circuit"
2070
2072
# - n: Number of qubits
@@ -2077,18 +2079,20 @@ def _sample_random_pauli(n,pspec = None, absolute_compilation = None, qubit_labe
2077
2079
if qubit_labels is not None : qubits = qubit_labels [:] # copy this list
2078
2080
else : qubits = pspec .qubit_labels [:]
2079
2081
2082
+ rng = _np .random .default_rng (seed )
2083
+
2080
2084
pauli_list = ['I' ,'X' ,'Y' ,'Z' ]
2081
2085
2082
2086
if include_identity is False :
2083
2087
while True :
2084
- rand_ints = _np . random . randint (0 ,4 , n )
2088
+ rand_ints = rng . integers (0 , 4 , n )
2085
2089
if sum (rand_ints ) != 0 : # make sure we don't get all identities
2086
2090
break
2087
2091
else :
2088
- rand_ints = _np . random . randint (0 , 4 , n )
2092
+ rand_ints = rng . integers (0 , 4 , n )
2089
2093
2090
2094
pauli = [pauli_list [i ] for i in rand_ints ]
2091
- if set (pauli ) != set ('I' ): sign = _np . random .choice ([- 1 ,1 ])
2095
+ if set (pauli ) != set ('I' ): sign = rng .choice ([- 1 ,1 ])
2092
2096
else : sign = 1
2093
2097
2094
2098
if circuit is False :
@@ -2106,11 +2110,13 @@ def _sample_random_pauli(n,pspec = None, absolute_compilation = None, qubit_labe
2106
2110
return pauli , sign , pauli_circuit
2107
2111
2108
2112
2109
- def _select_neg_evecs (pauli , sign ):
2113
+ def _select_neg_evecs (pauli , sign , seed = None ):
2110
2114
# Selects the entries in an n-qubit that will be turned be given a -1 1Q eigenstates
2111
2115
# - pauli: The n-qubit Pauli
2112
2116
# - sign: Whether you want a -1 or +1 eigenvector
2113
2117
# Returns: A bitstring whose 0/1 entries specify if you have a +1 or -1 1Q eigenstate
2118
+ rng = _np .random .default_rng (seed )
2119
+
2114
2120
n = len (pauli )
2115
2121
identity_bitstring = [0 if i == 'I' else 1 for i in pauli ]
2116
2122
nonzero_indices = _np .nonzero (identity_bitstring )[0 ]
@@ -2125,10 +2131,10 @@ def _select_neg_evecs(pauli, sign):
2125
2131
choices = _np .arange (start = 0 , stop = num_nid , step = 2 )
2126
2132
else :
2127
2133
choices = _np .arange (start = 1 , stop = num_nid + 1 , step = 2 )
2128
- num_neg_evecs = _np . random .choice (choices )
2134
+ num_neg_evecs = rng .choice (choices )
2129
2135
assert ((- 1 )** num_neg_evecs == sign )
2130
2136
2131
- neg_evecs = _np . random .choice (nonzero_indices , num_neg_evecs , replace = False )
2137
+ neg_evecs = rng .choice (nonzero_indices , num_neg_evecs , replace = False )
2132
2138
2133
2139
bit_evecs = _np .zeros (n )
2134
2140
bit_evecs [neg_evecs ] = 1
@@ -2160,7 +2166,7 @@ def _compose_initial_cliffords(prep_circuit):
2160
2166
composed_layer .append (new_gate )
2161
2167
return composed_layer
2162
2168
2163
- def _sample_stabilizer (pauli , sign , absolute_compilation , qubit_labels ):
2169
+ def _sample_stabilizer (pauli , sign , absolute_compilation , qubit_labels , seed = None ):
2164
2170
# Samples a random stabilizer of a Pauli, s = s_1 \otimes ... \otimes s_n. For each s_i,
2165
2171
# we perform the following gates:
2166
2172
# - s_i = X: H
@@ -2176,10 +2182,10 @@ def _sample_stabilizer(pauli, sign, absolute_compilation, qubit_labels):
2176
2182
# preparation circuit, and a pygsti circuit representation of the prep circuit
2177
2183
2178
2184
2179
-
2185
+ rng = _np . random . default_rng ( seed )
2180
2186
2181
2187
n = len (pauli )
2182
- neg_evecs = _select_neg_evecs (pauli , sign )
2188
+ neg_evecs = _select_neg_evecs (pauli , sign , seed = seed )
2183
2189
assert ((- 1 )** sum (neg_evecs ) == sign )
2184
2190
zvals = [0 if neg_evecs [i ] == 0 else - 1 for i in range (n )]
2185
2191
@@ -2199,7 +2205,7 @@ def _sample_stabilizer(pauli, sign, absolute_compilation, qubit_labels):
2199
2205
'Z' : 'C0' }
2200
2206
2201
2207
x_layer = [symp_reps ['I' ] if zvals [i ] == 0 else symp_reps ['X' ] for i in range (len (zvals ))]
2202
- circ_layer = [circ_dict [i ] if i in circ_dict .keys () else 'C' + str (_np . random . randint (24 )) for i in pauli ]
2208
+ circ_layer = [circ_dict [i ] if i in circ_dict .keys () else 'C' + str (rng . integers (24 )) for i in pauli ]
2203
2209
2204
2210
init_layer = [symp_reps [circ_layer [i ]] for i in range (len (pauli ))]
2205
2211
@@ -2257,8 +2263,7 @@ def _determine_sign(s_state, p_state, measurement):
2257
2263
2258
2264
2259
2265
def create_binary_rb_circuit (pspec , clifford_compilations , length , qubit_labels = None , layer_sampling = 'mixed1q2q' , sampler = 'Qelimination' ,
2260
- samplerargs = None , addlocal = False , lsargs = None ,
2261
- seed = None ):
2266
+ samplerargs = None , addlocal = False , lsargs = None , seed = None ):
2262
2267
"""
2263
2268
Generates a "binary randomized benchmarking" (BiRB) circuit.
2264
2269
@@ -2343,19 +2348,21 @@ def create_binary_rb_circuit(pspec, clifford_compilations, length, qubit_labels=
2343
2348
2344
2349
2345
2350
rand_pauli , rand_sign , pauli_circuit = _sample_random_pauli (n = n , pspec = pspec , qubit_labels = qubit_labels ,
2346
- absolute_compilation = clifford_compilations ,
2347
- circuit = True , include_identity = False )
2351
+ absolute_compilation = clifford_compilations ,
2352
+ circuit = True , include_identity = False , seed = seed + 42 )
2348
2353
2349
- s_inputstate , p_inputstate , s_init_layer , p_init_layer , prep_circuit = _sample_stabilizer (rand_pauli , rand_sign , clifford_compilations , qubit_labels )
2354
+ s_inputstate , p_inputstate , s_init_layer , p_init_layer , prep_circuit = _sample_stabilizer (rand_pauli , rand_sign , clifford_compilations ,
2355
+ qubit_labels , seed = seed + 43 )
2350
2356
2351
- s_pc , p_pc = _symp .symplectic_rep_of_clifford_circuit (pauli_circuit , pspec = pspec .subset (gate_names_to_include = 'all' , qubit_labels_to_keep = qubit_labels )) #note: if the pspec contains gates not in pyGSTi, this
2357
+ s_pc , p_pc = _symp .symplectic_rep_of_clifford_circuit (pauli_circuit , pspec = pspec .subset (gate_names_to_include = 'all' ,
2358
+ qubit_labels_to_keep = qubit_labels )) #note: if the pspec contains gates not in pyGSTi, this
2352
2359
2353
2360
# build the initial layer of the circuit
2354
2361
full_circuit = prep_circuit .copy (editable = True )
2355
2362
2356
2363
# Sample a random circuit of "native gates".
2357
2364
if layer_sampling == 'alternating1q2q' :
2358
- circuit = random_alternating_clifford_circ (pspec , length , qubit_labels = qubit_labels , two_q_gate_density = samplerargs [0 ])
2365
+ circuit = random_alternating_clifford_circ (pspec , length , qubit_labels = qubit_labels , two_q_gate_density = samplerargs [0 ], rand_state = rand_state )
2359
2366
elif layer_sampling == 'mixed1q2q' :
2360
2367
circuit = create_random_circuit (pspec = pspec , length = length , qubit_labels = qubit_labels , sampler = sampler ,
2361
2368
samplerargs = samplerargs , addlocal = addlocal , lsargs = lsargs , rand_state = rand_state )
@@ -2386,7 +2393,7 @@ def create_binary_rb_circuit(pspec, clifford_compilations, length, qubit_labels=
2386
2393
2387
2394
# Turn the stabilizer into an all Z and I stabilizer. Append this to the circuit.
2388
2395
2389
- s_stab , p_stab , stab_circuit = _stabilizer_to_all_zs (pauli , qubit_labels , clifford_compilations )
2396
+ s_stab , p_stab , stab_circuit = _stabilizer_to_all_zs (pauli , qubit_labels , clifford_compilations , seed = seed + 404 )
2390
2397
2391
2398
full_circuit .append_circuit_inplace (stab_circuit )
2392
2399
@@ -2405,7 +2412,7 @@ def create_binary_rb_circuit(pspec, clifford_compilations, length, qubit_labels=
2405
2412
2406
2413
return outcircuit , measurement , sign
2407
2414
2408
- def random_alternating_clifford_circ (pspec , depth , qubit_labels = None , two_q_gate_density = 0.25 ):
2415
+ def random_alternating_clifford_circ (pspec , depth , qubit_labels = None , two_q_gate_density = 0.25 , rand_state = None ):
2409
2416
"""
2410
2417
Generates a random circuit with composite layers cponsisting of a layer of two-qubit gates followed by
2411
2418
a layer of of single-qubit gates.
@@ -2443,8 +2450,9 @@ def random_alternating_clifford_circ(pspec, depth, qubit_labels=None, two_q_gate
2443
2450
#sample # benchmarking layers = depth
2444
2451
circ = _cir .Circuit (layer_labels = [], line_labels = qubit_labels , editable = True )
2445
2452
for _ in range (depth ):
2446
- oneQ_layer = _cir .Circuit ([sample_circuit_layer_of_one_q_gates (pspec , qubit_labels = qubit_labels )]).parallelize ()
2447
- twoQ_layer = _cir .Circuit (sample_circuit_layer_by_edgegrab (pspec , qubit_labels = qubit_labels , two_q_gate_density = two_q_gate_density )).parallelize ()
2453
+ oneQ_layer = _cir .Circuit ([sample_circuit_layer_of_one_q_gates (pspec , qubit_labels = qubit_labels , rand_state = rand_state )]).parallelize ()
2454
+ twoQ_layer = _cir .Circuit (sample_circuit_layer_by_edgegrab (pspec , qubit_labels = qubit_labels , two_q_gate_density = two_q_gate_density ,
2455
+ rand_state = rand_state )).parallelize ()
2448
2456
circ .append_circuit_inplace (twoQ_layer )
2449
2457
circ .append_circuit_inplace (oneQ_layer )
2450
2458
circ .done_editing ()
0 commit comments