text
stringlengths 0
828
|
---|
except: |
# if the function crashes without any arguments |
raise Exception('runs_per_second needs a working function that accepts no arguments') |
else: |
# this usage of iter infinitely calls a function until the second argument is the output |
# so I set the second argument to something that isnt what output was. |
generator = iter(generator, (1 if output is None else None)) |
del output |
c=0 # run counter, keep this one short for performance reasons |
entire_test_time_used = False |
start = ts() |
end = start+seconds |
for _ in generator: |
if ts()>end: |
entire_test_time_used = True |
break |
else: |
c += 1 |
duration = (ts())-start # the ( ) around ts ensures that it will be the first thing calculated |
return int(c/(seconds if entire_test_time_used else duration))" |
4866,"def remove_unreachable_symbols(grammar, inplace=False): |
# type: (Grammar, bool) -> Grammar |
"""""" |
Remove unreachable symbols from the gramar |
:param grammar: Grammar where to symbols remove |
:param inplace: True if transformation should be performed in place. False by default. |
:return: Grammar without unreachable symbols. |
"""""" |
# copy if required |
if inplace is False: |
grammar = copy(grammar) |
# check if start symbol is set |
if grammar.start is None: |
raise StartSymbolNotSetException() |
# create process sets |
reachable = {grammar.start} |
rules = grammar.rules.copy() |
# begin iterations |
while True: |
# create sets for current iteration |
active = reachable.copy() |
# loop the working rules |
for rule in rules.copy(): |
# lf left part of rule already in reachable symbols |
if rule.fromSymbol in reachable: |
# set symbols on the right as reachable |
for symbol in rule.right: |
active.add(symbol) |
# remove rule from the next iteration |
rules.remove(rule) |
# end of rules loop |
# if current and previous iterations are same, we are done |
if active == reachable: |
break |
# otherwise swap the sets |
reachable = active |
# remove the symbols |
nonterminals_to_remove = grammar.nonterminals.difference(reachable) |
terminals_to_remove = grammar.terminals.difference(reachable) |
grammar.nonterminals.remove(*nonterminals_to_remove) |
grammar.terminals.remove(*terminals_to_remove) |
# return grammar |
return grammar" |
4867,"def fermion_avg(efermi, norm_hopping, func): |
""""""calcules for every slave it's average over the desired observable"""""" |
if func == 'ekin': |
func = bethe_ekin_zeroT |
elif func == 'ocupation': |
func = bethe_filling_zeroT |
return np.asarray([func(ef, tz) for ef, tz in zip(efermi, norm_hopping)])" |
4868,"def spinflipandhop(slaves): |
""""""Calculates the interaction term of a spin flip and pair hopping"""""" |
Sdw = [csr_matrix(spin_gen(slaves, i, 0)) for i in range(slaves)] |
Sup = [mat.T for mat in Sdw] |
sfh = np.zeros_like(Sup[0]) |
orbitals = slaves//2 |
for n in range(orbitals): |
for m in range(n+1, orbitals): |
sfh += Sup[2*n ] * Sdw[2*n + 1] * Sup[2*m + 1] * Sdw[2*m ] |
sfh += Sup[2*n+1] * Sdw[2*n ] * Sup[2*m ] * Sdw[2*m+1] |
sfh += Sup[2*n] * Sup[2*n + 1] * Sdw[2*m] * Sdw[2*m+1] |
sfh += Sup[2*m] * Sup[2*m + 1] * Sdw[2*n] * Sdw[2*n+1] |
return sfh" |
4869,"def spin_z_op(param, oper): |
""""""Generates the required Sz operators, given the system parameter setup |
and the operator dictionary"""""" |
slaves = param['slaves'] |
oper['Sz'] = np.array([spin_z(slaves, spin) for spin in range(slaves)]) |
oper['Sz+1/2'] = oper['Sz'] + 0.5*np.eye(2**slaves) |
oper['sumSz2'] = oper['Sz'].sum(axis=0)**2 # because Sz is diagonal |
Sz_mat_shape = oper['Sz'].reshape(param['orbitals'], 2, 2**slaves, 2**slaves) |
oper['sumSz-sp2'] = (Sz_mat_shape.sum(axis=1)**2).sum(axis=0) |
oper['sumSz-or2'] = (Sz_mat_shape.sum(axis=0)**2).sum(axis=0)" |
4870,"def spin_gen_op(oper, gauge): |
""""""Generates the generic spin matrices for the system"""""" |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.