Пример #1
0
def make_input(op, T):
    print("Available inputs: ")
    print("1. One single photon input")
    print("2. Two single photon inputs")
    print("3. One n-th state photon input")
    print("4. One coherent state input")
    inp = int(base.get("Choose an input: ", \
                "Select 1, 2, 3 or 4."))
    print("Generating input state wavefunction...")
    print("Specify first input.")
    if (inp == 1):
        dist1 = gen_dist(T)
        base.digitize(dist1)
        dist2 = np.zeros(T)
    elif (inp == 2):
        dist1 = gen_dist(T)
        print("Specify second input.")
        dist2 = gen_dist(T)
        base.digitize(dist1)
        base.digitize(dist2)
    elif (inp == 3):
        dist1 = gen_dist(T)
        base.digitize(dist1)
        n = int(
            base.get("Enter state number: ", "Please enter a natural number."))
        for i in range(len(dist1)):
            dist1[i] = dist1[i] * n
        dist2 = np.zeros(T)
    elif (inp == 4):
        dist1 = base.create_coh_state(T, op.N)
        dist2 = np.zeros(T)
    print("Digitizing outputs...")
    return dist1, dist2, op.decomp(dist1, dist2)
Пример #2
0
def make_operator():
    R = float(base.get("Enter reflectance for splitter: ", \
            "Reflectance must be between 0 and 1. Please try again."))
    while (not (R >= 0 and R <= 1)):
        print("Reflectance must be between 0 and 1. Please try again.")
        R = float(base.get("Enter reflectance for splitter: ", \
            "Reflectance must be between 0 and 1. Please try again."))
    N = int(
        base.get("Enter max allowed eigenstate: ",
                 "Please enter a natural number."))
    return oper.oper(R, N + 1)
Пример #3
0
def waitUntil():
    print("start checking jmsserver1 status")
    tail1 = 'domainRuntime/serverRuntimes/ms1/JMSRuntime/JMSServers/jmsserver1-01?links=none&fields=name,healthState'
    tail2 = 'domainRuntime/serverRuntimes/ms2/JMSRuntime/JMSServers/jmsserver1-01?links=none&fields=name,healthState'
    fail = True
    while (fail):
        sleep(2)
        res = base.get(tail1)
        if (res.ok):
            return
        res = base.get(tail2)
        if (res.ok):
            return
Пример #4
0
    def get_events(self, from_datetime=None, to_datetime=None,
                   traits=None, name=None, msg_id=None, debug=False):
        if msg_id:
            return base.get(self.url, "events/%s" % msg_id, {}, debug=debug)

        if traits:
            traits = ",".join(["%s:%s" % item for item in traits.items()])
        cmd = "events"
        params = base.remove_empty({'from_datetime': from_datetime,
                                    'to_datetime': to_datetime,
                                    'event_name': name,
                                    'traits': traits})

        return base.get(self.url, cmd, params, debug=debug)
Пример #5
0
def get(devID, devName, token):
    payload = base.build_device_payload(devID=devID,
                                        devName=devName,
                                        token=token)
    ret = base.get(url, headers, payload)

    return ret
Пример #6
0
def getTok(username, password):
  payload = base.build_payload(username=username, password=password)
  ret = base.get(url, headers, payload) 
  if ret and ret['success']:
    return ret['token']
  else:
    return ret 
Пример #7
0
def present():
    print("Demonstrations: ")
    print("1. Single Photon Source")
    print("2. Beam Splitter Operator")

    option = int(base.get("Choose a demo, or press 0 to exit: ", \
            "Select 0, 1 or 2."))
    while option not in [0, 1, 2]:
        print("Select 0, 1 or 2.")
        option = int(base.get("Choose a demo, or press 0 to exit: ", \
                "Select 0, 1 or 2."))

    if (option == 0):
        print("Closing.")
        sys.exit(0)
    elif (option == 1):
        sps_demo()
    elif (option == 2):
        op_demo()
Пример #8
0
    def get_streams(self, from_datetime=None, to_datetime=None,
                    traits=None, name=None, stream_id=None, debug=False,
                    state=None, details=None):
        if stream_id:
            params = base.remove_empty({'details': details})
            return base.get(self.url, "streams/%s" % stream_id, params,
                            debug=debug)

        if traits:
            traits = ",".join(["%s:%s" % item for item in traits.items()])
        cmd = "streams"
        params = base.remove_empty({'older_than': from_datetime,
                                    'younger_than': to_datetime,
                                    'name': name,
                                    'details': details,
                                    'state': state,
                                    'distinguishing_traits': traits})

        return base.get(self.url, cmd, params, debug=debug)
Пример #9
0
def beam_split(dist):
    R = float(base.get("Enter reflectance for splitter: ", \
            "Reflectance must be between 0 and 1. Please try again."))
    while (not (R >= 0 and R <= 1)):
        print("Reflectance must be between 0 and 1. Please try again.")
        R = float(base.get("Enter reflectance for splitter: ", \
            "Reflectance must be between 0 and 1. Please try again."))
    print("Splitting photons...")
    refl, trans = base.split(dist, thresh=R)
    print("Plotting distributions...")
    plot.simul_bar_plot([dist, refl, trans], \
            ["Input", "Reflected", "Transmitted"])
    flag = input("Show histograms? (y/n): ")
    while (flag != 'n' and flag != 'y'):
        print("Please enter y or n.")
        flag = input("Show histograms? (y/n): ")
    if (flag == 'y'):
        plot.simul_hist_plot([dist, refl, trans], \
            ["Input", "Reflected", "Transmitted"])
    return refl, trans
Пример #10
0
def gen_dist(T):
    print("Distributions: ")
    print("1. Uniform")
    print("2. Exponential")
    print("3. Logarithmic")
    distr = int(base.get("Pick a distribution: ", \
                "Select 1, 2 or 3."))
    while distr not in [1, 2, 3]:
        print("Select 1, 2 or 3.")
        distr = int(base.get("Pick a distribution: ", \
            "Select 1, 2 or 3."))
    print("Generating distribution...")
    if (distr == 1):
        dist = base.create_unif_dist(T)
    elif (distr == 2):
        dist = base.create_exp_dist(T)
    elif (distr == 3):
        dist = base.create_log_dist(T)
    print("Digitizing distribution...")
    base.digitize(dist)
    return dist
Пример #11
0
def sps_demo():
    T = int(base.get("Enter length of array, or enter 0 to go back: ", \
                "Please enter a natural number."))
    if (T == 0):
        present()
    else:
        dist = demos.gen_dist(T)
        demos.plot_dist(dist)
        refl, trans = demos.beam_split(dist)
        demos.correlate(refl, trans)
        print("End of demo.")
        present()
Пример #12
0
def weather():
    if request.method == 'POST':
        location = request.form['city'].lower()
        if location:
            sqliteConnection = conn(location)
            details = get(sqliteConnection,
                          location)  # gives details of location from db
            temp = celsius(details[2])
            print({
                "city": details[0],
                "Weather description": details[1],
                "temp(in k)": details[2],
                "temp(in C)": temp
            })
            return render_template('second.html',
                                   city=details[0],
                                   description=details[1],
                                   tempk=details[2],
                                   tempc=temp,
                                   time=details[3])
        else:
            return "<h1> City Name <h1> <a href=\"/\"> Home</a>"
Пример #13
0
def op_demo():
    T = int(base.get("Enter length of array, or enter 0 to go back: ", \
                "Please enter a natural number."))
    if (T == 0):
        present()
    else:
        operator = demos.make_operator()
        B = operator.build()
        dist1, dist2, psi_in = demos.make_input(operator, T)
        psi_out = np.matmul(B, psi_in)
        refl, trans = demos.measure(operator, psi_out)
        print("Plotting distributions...")
        plot.simul_bar_plot([dist1, dist2, refl, trans], \
            ["Input 1", "Input 2", "Reflected", "Transmitted"])
        flag = input("Show histograms? (y/n): ")
        while (flag != 'n' and flag != 'y'):
            print("Please enter y or n.")
            flag = input("Show histograms? (y/n): ")
        if (flag == 'y'):
            plot.simul_hist_plot([dist1, dist2, refl, trans], \
                ["Input 1", "Input 2", "Reflected", "Transmitted"])
        demos.correlate(refl, trans)
        print("End of demo.")
        present()
Пример #14
0
def get(username, token):
  payload = base.build_payload(username=username, token=token)
  ret = base.get(url, headers, payload) 

  return ret