コード例 #1
0
def run_legion(N):

    from legion import Client

    client = Client()
    alpha = 0.5
    beta = 0.5


    big_matrix = generate_big_matrix(N)

    current_inv_approx = np.eye(N)
    client.create_if_not_already_created("current_inv_approx", current_inv_approx)
    current_inv_approx = client.pull_full("current_inv_approx")
    #print "type(current_inv_approx)"
    #print type(current_inv_approx)


    current_error = get_error(current_inv_approx, big_matrix)
    original_noise = 0.001
    current_noise = original_noise

    last_index_with_good_proposal = 0
    for i in range(1000):
        (status, current_inv_approx, current_error) = try_one_guess(current_inv_approx, big_matrix, current_noise, current_error)
        #print "update %s, current_error %0.4f" % (status, current_error)

        time.sleep(1)

        if status == 'success':
            client.push_full("current_inv_approx", current_inv_approx, alpha, beta)
            print "Pushed current_inv_approx with error %0.12f to server." % current_error
            current_inv_approx = client.pull_full("current_inv_approx")
            last_index_with_good_proposal = i
            current_noise = original_noise
        else:
            current_noise = 0.9 * current_noise

        if last_index_with_good_proposal == i or 25 < last_index_with_good_proposal - i:
            current_inv_approx = client.pull_full("current_inv_approx")
            current_error = get_error(current_inv_approx, big_matrix)
            print "Pulled current_inv_approx with error %0.12f from server." % current_error

    """
コード例 #2
0
ファイル: example_user_script.py プロジェクト: JulesGM/legion
def main():
    leg = Client()
    test = -np.ones((10, 20, 30))
    test[2:5, 2:5, 2:5] = np.zeros((3, 3, 3))

    # We create the value on the server. If we try to create it from different clients at once,
    # it will only take the first value it receives, and send it back to the other clients so they know which one was picked.
    test = leg.create_if_not_already_created("test", test)
    test *= 2
    comp_test0 = leg.pull_full("test")
    leg.push_as_part("test", test, [[0], [1, 4], [1, 6]], 0.5, 0.5)
    comp_test1 = leg.pull_full("test")
    print comp_test0
    print comp_test1