示例#1
0
def main():
    # Reading the lists

    rating_list = read_rating_list()
    # rating_list = (id, name, rating, k)

    entry_list = read_entry_list()
    # entry_list = (name, n_games, score, av_op)

    # Getting the info from the tournament
    filename = input("Nombre del archivo de input: ")
    text = read_file(filename)
    check_file(text)
    tournament = read_tournament(text)

    player_list = read_players(text, tournament[4])
    # player_list = [(name, rating, results)]
    # results = [(oponent, result)]

    errors = check_players_rating(player_list, rating_list)
    if errors == 0:
        print("Everything OK")
    else:
        sys.exit()

    # Makes the messy things
    calculate(player_list)
    calculate_init(player_list, entry_list)

    # Write all the files!
    write_entry_list(entry_list)
    write_rating_list(player_list, entry_list)
    write_report(player_list, entry_list, tournament)
示例#2
0
def result_pressed():
    expression = line.get()
    line.delete(0, last=tk.END)
    try:
        line.insert(0, calculate(expression))
    except ZeroDivisionError:
        messagebox.showerror("Ошибка", "Деление на ноль")
    except BaseException:
        messagebox.showerror("Ошибка", "Неправильное выражение или сбой вычисления")
示例#3
0
def tubing_leak(df3):
    problemTrend=[]
    for x in range(8):
        colss=df3.iloc[:,x]
        problemTrend.append(calculate(colss))

    if problemTrend == tubing_leak:
        print(problemTrend)
        print(tubing_leak)
        return True
    else:
        return False
示例#4
0
def qfs(Nq, wq, Ec, wp, H, H_args, psi0, Nc, Np, Np_per_batch, options, home,
        parallel):
    """
    Applies a probe tone to an uncoupled qubit to find its transition frequency,
    which can be shifted due to a dispersive drive.
    
    Input
    -----
    The input parameters are equal to the names in 2p_sideband.ipynb.
    """
    i = wp[0]
    wp = wp[1]
    H_args['wp'] = wp
    b, nq = ops(Nq)
    e_ops = [nq]
    c_ops = []

    srcfolder = calculate(H,
                          psi0,
                          e_ops,
                          c_ops,
                          H_args,
                          options,
                          Nc,
                          Np,
                          Np_per_batch,
                          home,
                          parallel,
                          verbose=False)
    quants = ['times', 'expect']
    combine_batches(srcfolder, quants=quants, return_data=False)
    times, states, expect, e0, g1, e1, g0, coupling = load_data(
        quants, srcfolder)

    if i < 10:
        num = "0" + str(i)
    elif i >= 10:
        num = str(i)

    print("\nshift  =", (wp - wq) / 2 / pi)
    print("wp     =", wp / 2 / pi)
    print("max    =", max(expect[0]))

    plt.figure(figsize=[15, 3])
    plt.plot(times, expect[0], c='k')
    plt.title("shift {}, wp {}, max {}".format(np.round((wp - wq) / 2 / pi, 4),
                                               np.round(wp / 2 / pi, 4),
                                               np.round(max(expect[0]), 4)))
    plt.savefig(home + "temp/fig{}_{}.png".format(num, (wp - wq) / 2 / pi))
示例#5
0
    def start(self):
        while self.con:
            if self.mode == "normal":
                self.ins = "normal>"
                self.time = time.strftime(
                    "%Y %m %d, %H:%M:%S on ") + self._trans_time(
                        int(time.strftime("%w")))
                result = input(self.ins)
                result = check(result, name=self.name, time=self.time)
                if result == "quit":
                    for l in logs:
                        l.logger.info("Quiting...")
                    self.con = 0
                elif result == "cal":
                    for l in logs:
                        l.logger.info("Entering Calculating Mode...")
                    self.mode = "calculate"
                    result = "calq"
                    self.ins = "calculate>"
                elif result == "cmd":
                    for l in logs:
                        l.logger.info("Entering CMD Mode...")
                    self.mode = "cmd"
                    self.ins = "cmd>"
                elif result == "klam":
                    for l in logs:
                        l.logger.info("Entering Klam Execution Mode...")
                    self.mode = "klam"
                    self.ins = ""
                else:
                    if bool(result):
                        log_in("Read: " + result)
                    modules.listenAndSay.say_baidu(result)
                    print(result)


#                 print(decode(result, self.name, self.time))
            elif self.mode == "calculate":
                log_in("Entered Calculating Mode", "info")
                self.mode = calculate(self.ins)
            elif self.mode == "cmd":
                log_in("Entered CMD Mode", "info")
                self.mode = cmding(self.ins)
            elif self.mode == "klam":
                log_in("Entered Klam Execute Mode", "info")
                modules.Klam.demo()
                self.mode = "normal"
示例#6
0
def cfs(Nq, Nc, wc, Ec, wp, H, H_args, psi0, Np_per_batch, options, home,
        parallel):
    i = wp[0]
    wp = wp[1]
    H_args['wp'] = wp
    Np = 100 * int(
        H_args['t3']
    )  # number of discrete time steps for which to store the output
    b, a, nq, nc = ops(Nq, Nc)  # Operators
    e_ops = [nq, nc]
    c_ops = []

    srcfolder = calculate(H,
                          psi0,
                          e_ops,
                          c_ops,
                          H_args,
                          options,
                          Nc,
                          Np,
                          Np_per_batch,
                          home,
                          parallel,
                          verbose=False)
    quants = ['times', 'expect']
    combine_batches(srcfolder, quants=quants, return_data=False)
    times, states, expect, e0, g1, e1, g0, coupling = load_data(
        quants, srcfolder)

    if i < 10:
        num = "0" + str(i)
    elif i >= 10:
        num = str(i)

    print("wp     =", wp / 2 / pi)
    print("max    =", max(expect[1]))

    plt.figure(figsize=[15, 3])
    #    plt.plot(times, expect[0], c='b')
    plt.plot(times, expect[1], c='r')
    plt.title("shift {}, wp {}, max {}".format(np.round((wp - wc) / 2 / pi, 4),
                                               np.round(wp / 2 / pi, 4),
                                               np.round(max(expect[1]), 6)))
    plt.savefig(home + "temp/fig{}_{}.png".format(num, (wp - wc) / 2 / pi))
示例#7
0
def generate_gematria_dictionary():

    f = open("every_word.txt", 'r')
    g = open("every_word_plus_gematria.txt", 'w')

    #Copyright info has to be written in every file.
    g.write("Copyright 2020 Matteo Raso\n")
    g.write("This file is part of Gematria.\n")
    g.write(
        "Gematria is free software: you can redistribute it and/or modify\n")
    g.write(
        "it under the terms of the GNU General Public License as published by\n"
    )
    g.write(
        "the Free Software Foundation, either version 3 of the License, or\n")
    g.write("(at your option) any later version.\n")
    g.write("\n")
    g.write("Gematria is distributed in the hope that it will be useful,\n")
    g.write("but WITHOUT ANY WARRANTY; without even the implied warranty of\n")
    g.write("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n")
    g.write("GNU General Public License for more details.\n")
    g.write("\n")
    g.write(
        "You should have received a copy of the GNU General Public License\n")
    g.write(
        "along with Gematria.  If not, see <https://www.gnu.org/licenses/>.\n\n"
    )

    i = 1

    for line in f:
        #To avoid calculating the copyright info.
        if i > 15:
            formatted_line = line.replace('\n', '')
            string = formatted_line + "," + str(
                calculate(formatted_line)) + '\n'
            g.write(string)

        i += 1

    f.close()
    g.close()
示例#8
0
def equal():
    global last_number1, last_number2, turned_on, last_operation
    try:
        t = float(input1.get())
        if abs(t - last_number2) > 1e-10 and abs(last_number1 - t) > 1e-10:
            last_number2 = t
        a = last_number1
        b = last_number2
    except:
        show_error("Недостаточно чисел")
        return
    k, t, por = toIntValues(a, b)
    p = calculate(k, t, operation)
    p /= pow(10, por)
    turned_on = 0
    if p == None:
        show_error("Число не в 4 системе счисления")
        return
    last_operation = operation
    last_number1 = p
    last_number2 = b
    last_p = p
    input1.delete(0, END)
    input1.insert(0, p)
示例#9
0
from calculate import *
f1 = open("out.txt", "w")
f1.write("")
f1.close()
file = open("test.txt")
for i in range(10):
    c1 = file.readline()
    c2 = file.readline()
    f1 = open("out.txt", "a")
    f1.write(str(calculate(int(c1), int(c2), 1)) + "\n")
    f1.close()
for i in range(9):
    c1 = file.readline()
    c2 = file.readline()
    f1 = open("out.txt", "a")
    f1.write(str(calculate(int(c1), int(c2), 0)) + "\n")
    f1.close()
r = open("right.txt")
o = open("out.txt")
for i in range(19):
    f = r.readline()
    s = o.readline()
    if f != s:
        print("{} строка: out: {}\nright: {}".format(i+1, s, f))
    else:
        print(i+1, "OK")
示例#10
0
def sbsample_visualize_sweep(Nq, wq, wc, Ec, g, wd, sb, Nt, H, H_args, psi0,
                             Np_per_batch, options, home, parallel, *args):
    from envelopes import drive

    i = wd[0]
    wd = wd[1]

    Nc = 10  # number of levels in resonator 1

    Np = 100 * int(
        H_args['t3']
    )  # number of discrete time steps for which to store the output
    b, a, nq, nc = ops(Nq, Nc)  # Operators
    if Nt == 1:
        H_args['wd'] = wd
    elif Nt == 2:
        dw = args[2]
        wdq = wd
        wdc = wc - dw
        H_args['wdq'] = wdq
        H_args['wdc'] = wdc
    e_ops = [nq, nc]
    c_ops = []

    srcfolder = calculate(H,
                          psi0,
                          e_ops,
                          c_ops,
                          H_args,
                          options,
                          Nc,
                          Np,
                          Np_per_batch,
                          home,
                          parallel,
                          verbose=False)

    quants = ['times', 'expect', 'e0', 'g1', 'e1', 'g0', 'coupling']
    ID = getID(srcfolder)
    combine_batches(srcfolder, quants=quants, return_data=False)
    times, states, expect, e0, g1, e1, g0, coupling = load_data(
        quants, srcfolder)

    if i < 10:
        num = "0" + str(i)
    elif i >= 10:
        num = str(i)

    print(" ")

    if Nt == 1:
        eps = args[0]
        print("$\\omega_d /2\\pi = ${} GHz".format(wd / 2 / pi))
        if sb == 'red':
            expect_title = "$\\omega_d /2\\pi = ${} GHz".format(
                np.round(wd / 2 / pi, 4))
            cp_title = "$\\omega_d /2\\pi = ${} GHz".format(
                np.round(wd / 2 / pi, 4))
            figqc, axqc = sb_expect_temporary(times,
                                              expect,
                                              sb,
                                              Nt,
                                              H_args,
                                              coupling,
                                              xlim=[0, 1000],
                                              ylim=[-0.02, 1.02],
                                              figsize=[12, 4],
                                              wd=wd,
                                              wsb=0,
                                              title=expect_title,
                                              eps=eps)
            fig, axp = sb_combined_probs_temporary(times,
                                                   sb,
                                                   Nt,
                                                   H_args,
                                                   coupling,
                                                   figsize=[12, 4],
                                                   e0=e0,
                                                   g1=g1,
                                                   wd=wd,
                                                   wsb=0,
                                                   xlim=[0, 1000],
                                                   ylim=[-1.02, 1.02],
                                                   title=cp_title,
                                                   eps=eps)
        elif sb == 'blue':
            expect_title = "$\\omega_d /2\\pi = ${} GHz".format(
                np.round(wd / 2 / pi, 4))
            cp_title = "$\\omega_d /2\\pi = ${} GHz".format(
                np.round(wd / 2 / pi, 4))
            figqc, axqc = sb_expect_temporary(times,
                                              expect,
                                              sb,
                                              Nt,
                                              H_args,
                                              coupling,
                                              xlim=[0, 1000],
                                              ylim=[-0.02, 1.02],
                                              figsize=[12, 4],
                                              wd=wd,
                                              wsb=0,
                                              title=expect_title,
                                              eps=eps)
            fig, axp = sb_combined_probs_temporary(times,
                                                   sb,
                                                   Nt,
                                                   H_args,
                                                   coupling,
                                                   figsize=[12, 4],
                                                   e1=e1,
                                                   g0=g0,
                                                   wd=wd,
                                                   wsb=0,
                                                   xlim=[0, 1000],
                                                   ylim=[-1.02, 1.02],
                                                   title=cp_title,
                                                   eps=eps)

    elif Nt == 2:
        epsq = args[0]
        epsc = args[1]
        print("$\\omega_dq /2\\pi = ${} GHz".format(np.round(wdq / 2 / pi, 4)))
        if sb == 'red':
            expect_title = "$\\omega_dq /2\\pi = ${} GHz".format(
                np.round(wdq / 2 / pi, 4))
            cp_title = "$\\omega_dq /2\\pi = ${} GHz".format(
                np.round(wdq / 2 / pi, 4))
            figqc, axqc = sb_expect_temporary(times,
                                              expect,
                                              sb,
                                              Nt,
                                              H_args,
                                              coupling,
                                              xlim=[0, 1000],
                                              ylim=[-0.02, 1.02],
                                              figsize=[12, 4],
                                              wsb=0,
                                              title=expect_title,
                                              epsq=epsq,
                                              epsc=epsc)
            fig, axp = sb_combined_probs_temporary(times,
                                                   sb,
                                                   Nt,
                                                   H_args,
                                                   coupling,
                                                   xlim=[0, 1000],
                                                   ylim=[-1.02, 1.02],
                                                   figsize=[15, 3],
                                                   e0=e0,
                                                   g1=g1,
                                                   wsb=0,
                                                   title=cp_title,
                                                   epsq=epsq,
                                                   epsc=epsc)
        elif sb == 'blue':
            expect_title = "$\\omega_dq /2\\pi = ${} GHz".format(
                np.round(wdq / 2 / pi, 4))
            cp_title = "$\\omega_dq /2\\pi = ${} GHz".format(
                np.round(wdq / 2 / pi, 4))
            figqc, axqc = sb_expect_temporary(times,
                                              expect,
                                              sb,
                                              Nt,
                                              H_args,
                                              coupling,
                                              xlim=[0, 1000],
                                              ylim=[-0.02, 1.02],
                                              figsize=[12, 4],
                                              wsb=0,
                                              title=expect_title,
                                              epsq=epsq,
                                              epsc=epsc)
            fig, axp = sb_combined_probs_temporary(times,
                                                   sb,
                                                   Nt,
                                                   H_args,
                                                   coupling,
                                                   xlim=[0, 1000],
                                                   ylim=[-1.02, 1.02],
                                                   figsize=[12, 4],
                                                   e1=e1,
                                                   g0=g0,
                                                   wsb=0,
                                                   title=cp_title,
                                                   epsq=epsq,
                                                   epsc=epsc)
    fig.savefig(
        "/Users/Wouter/Documents/TU/TN/Master/Thesis project/Midterm presentation/freq sweep method/fig_{}.png"
        .format(num))
    figqc.savefig(
        "/Users/Wouter/Documents/TU/TN/Master/Thesis project/Midterm presentation/freq sweep method/figqc_{}.png"
        .format(num))
    plt.close(fig)
    plt.close(figqc)
    return figqc, fig
示例#11
0
def sbsample(Nq, wq, wc, Ec, g, wd, sb, Nt, H, H_args, psi0, c_ops,
             Np_per_batch, options, home, parallel, *args, **kwargs):
    """
    Performs a single- or double-tone sideband transition simulation
    with the given input parameters. Plots the expectation
    values of the qubit & cavity, and the combined probability
    |e0>-|g1> in the case of red sideband transitions, or
    |e1>-|g0> in the case of blue sideband transitions.
    
    Due to the use of the pool.starmap function, the additional
    arguments of *args, dependent on Nt, have to be passed in
    a definite order.
    Nt = 1 : eps
    Nt = 2 : epsq, epsc, dw
    
    Input
    -----
    The input parameters are equal to the names in 2p_sideband.ipynb.
    
    Returns
    -------
    figqc : matplotlib.pyplot.Figure class object
        Figure with expected qubit and cavity occupation number
    fig : matplot.pyplot.Figure class object
        Figure with combined probabilities
    """
    from envelopes import drive

    i = wd[0]
    wd = wd[1]

    Nc = 10  # number of levels in resonator 1

    Np = 100 * int(
        H_args['t3']
    )  # number of discrete time steps for which to store the output
    b, a, nq, nc = ops(Nq, Nc)  # Operators
    if Nt == 1:
        H_args['wd'] = wd
    elif Nt == 2:
        dw = args[2]
        wdq = wd
        wdc = wc - dw
        H_args['wdq'] = wdq
        H_args['wdc'] = wdc
    e_ops = [nq, nc]

    srcfolder = calculate(H,
                          psi0,
                          e_ops,
                          c_ops,
                          H_args,
                          options,
                          Nc,
                          Np,
                          Np_per_batch,
                          home,
                          parallel,
                          verbose=False,
                          method='me')

    quants = ['times', 'expect', 'e0', 'g1', 'e1', 'g0', 'coupling']
    ID = getID(srcfolder)
    combine_batches(srcfolder, quants=quants, return_data=False)
    times, states, expect, e0, g1, e1, g0, coupling = load_data(
        quants, srcfolder)

    if i < 10:
        num = "0" + str(i)
    elif i >= 10:
        num = str(i)

    print(" ")

    if Nt == 1:
        eps = args[0]
        print("wd = {}".format(wd / 2 / pi))
        if sb == 'red':
            print("min = {}, max = {}".format(round(min(e0 - g1), 4),
                                              round(max(e0 - g1), 4)))
            expect_title = "wd = {}".format(wd / 2 / pi)
            cp_title = "wd = {}, min = {}, max = {}".format(
                wd / 2 / pi, round(min(e0 - g1), 4), round(max(e0 - g1), 4))
            figqc, axqc = sb_expect(times,
                                    expect,
                                    sb,
                                    Nt,
                                    H_args,
                                    coupling,
                                    xlim=None,
                                    ylim=None,
                                    figsize=[15, 3],
                                    wd=wd,
                                    wsb=0,
                                    title=expect_title,
                                    eps=eps)
            fig, axp = sb_combined_probs(times,
                                         sb,
                                         Nt,
                                         H_args,
                                         coupling,
                                         e0=e0,
                                         g1=g1,
                                         wd=wd,
                                         wsb=0,
                                         title=cp_title,
                                         eps=eps)
        elif sb == 'blue':
            print("min = {}, max = {}".format(round(min(e1 - g0), 4),
                                              round(max(e1 - g0), 4)))
            expect_title = "wd = {}".format(wd / 2 / pi)
            cp_title = "wd = {}, min = {}, max = {}".format(
                wd / 2 / pi, round(min(e1 - g0), 4), round(max(e1 - g0), 4))
            figqc, axqc = sb_expect(times,
                                    expect,
                                    sb,
                                    Nt,
                                    H_args,
                                    coupling,
                                    xlim=None,
                                    ylim=None,
                                    figsize=[15, 3],
                                    wd=wd,
                                    wsb=0,
                                    title=expect_title,
                                    eps=eps)
            fig, axp = sb_combined_probs(times,
                                         sb,
                                         Nt,
                                         H_args,
                                         coupling,
                                         e1=e1,
                                         g0=g0,
                                         wd=wd,
                                         wsb=0,
                                         title=cp_title,
                                         eps=eps)
        fig.savefig(home + "temp/fig{}_{}.png".format(num, wd / 2 / pi))
        figqc.savefig(home + "temp/figqc{}_{}.png".format(num, wd / 2 / pi))

    elif Nt == 2:
        epsq = args[0]
        epsc = args[1]
        print("wdq = {}".format(wdq / 2 / pi))
        if sb == 'red':
            print("min = {}, max = {}".format(round(min(e0 - g1), 4),
                                              round(max(e0 - g1), 4)))
            expect_title = "wdq = {}".format(wdq / 2 / pi)
            cp_title = "wdq = {}, min = {}, max = {}".format(
                wdq / 2 / pi, round(min(e0 - g1), 4), round(max(e0 - g1), 4))
            figqc, axqc = sb_expect(times,
                                    expect,
                                    sb,
                                    Nt,
                                    H_args,
                                    coupling,
                                    xlim=None,
                                    ylim=None,
                                    figsize=[15, 3],
                                    wsb=0,
                                    title=expect_title,
                                    epsq=epsq,
                                    epsc=epsc)
            fig, axp = sb_combined_probs(times,
                                         sb,
                                         Nt,
                                         H_args,
                                         coupling,
                                         xlim=None,
                                         ylim=None,
                                         figsize=[15, 3],
                                         e0=e0,
                                         g1=g1,
                                         wsb=0,
                                         title=cp_title,
                                         epsq=epsq,
                                         epsc=epsc)
        elif sb == 'blue':
            print("min = {}, max = {}".format(round(min(e1 - g0), 4),
                                              round(max(e1 - g0), 4)))
            expect_title = "wdq = {}".format(wdq / 2 / pi)
            cp_title = "wdq = {}, min = {}, max = {}".format(
                wdq / 2 / pi, round(min(e1 - g0), 4), round(max(e1 - g0), 4))
            figqc, axqc = sb_expect(times,
                                    expect,
                                    sb,
                                    Nt,
                                    H_args,
                                    coupling,
                                    xlim=None,
                                    ylim=None,
                                    figsize=[15, 3],
                                    wsb=0,
                                    title=expect_title,
                                    epsq=epsq,
                                    epsc=epsc)
            fig, axp = sb_combined_probs(times,
                                         sb,
                                         Nt,
                                         H_args,
                                         coupling,
                                         xlim=None,
                                         ylim=None,
                                         figsize=[15, 3],
                                         e1=e1,
                                         g0=g0,
                                         wsb=0,
                                         title=cp_title,
                                         epsq=epsq,
                                         epsc=epsc)
        fig.savefig(home + "temp/fig{}_{}.png".format(num, wdq / 2 / pi))
        figqc.savefig(home + "temp/figqc{}_{}.png".format(num, wdq / 2 / pi))
    plt.close(fig)
    plt.close(figqc)
    return figqc, fig
示例#12
0
文件: main.py 项目: Zonzely/calculate
 def output(self,exp):
     '''return the result of  exp'''
     return str(calculate(exp))
示例#13
0
sys.path.append('./rawData')
import calculate
from calculate import *

sys.path.append('./fitToCurve')
import splitData
from splitData import *

def checkInput():
	bla = raw_input('Do these numbers match up with data book? [y,n]: ')
	if bla == 'y' or bla == 'Yes' or bla == 'yes':
		os.system('mv ' + sys.argv[1] + ' ./rawData')
		return True
	elif bla == 'n' or bla == 'No' or bla == 'no':
		print('Check your typed and printed data! Removing generated file, run this program again when fixed')
		os.system('rm ' + sys.argv[1] + 'Activity')
		return False
	else:
		print("You didn't type 'y' or 'n', try again")
		if checkInput() == True:
			return True
		else:
			return False
	
calculate(sys.argv[1])

if checkInput() == True:
	#run the fit curve program
	fitToCurve(sys.argv[1] + 'Activity')
	os.system('mv ' + sys.argv[1] + 'Activity ' + './fitToCurve')
示例#14
0
from get_gematria_sentences import *
from get_gematria_words import *

if sys.argv[1] == '-h':
    print("-c           Gets the gematria of a string.")
    print("-d           Generates a dictionary of words and their gematria.")
    print("-dc          Same as '-d', but with no swear words.")
    print(
        "-w           Gets every word with a user-given gematria. The user may optionally input a boolean to determine whether swear words are allowed."
    )
    print("-s           Gets every sentence with a user-given gematria.")
    print("-h           Brings up this help page.")
    print("-b           Boring license info for lawyers and nerds.")

elif sys.argv[1] == '-c':
    gem = calculate(sys.argv[2])
    print("The gematria of " + sys.argv[2] + " is " + str(gem) + '.')

elif sys.argv[1] == '-d':
    generate_gematria_dictionary()

elif sys.argv[1] == '-dc':
    generate_clean_gematria_dictionary()

elif sys.argv[1] == '-w':
    try:
        get_gematria_words(int(sys.argv[2]), sys.argv[3])

    #The user might not input the boolean.
    except:
        get_gematria_words(int(sys.argv[2]))
示例#15
0
def repeat():
    global last_number1
    p = calculate(last_number1, last_number2, last_operation)
    last_number1 = p
    input1.delete(0, END)
    input1.insert(0, p)