Exemple #1
0
def run(spool):
    # notify("I'm alive!")

    jobs = [Job(name, data, spool) for name, data in config['jobs'].items()]

    due_jobs = [job for job in jobs if job.is_due()]
    for job in due_jobs:
        print(f'⏲ {job} is due!')
        try:
            with time_limit(job.time_limit):
                job.execute()
            dur = job.last_success - job.last_executed
            notify(job.name,
                   f'ran successfully in {dur}',
                   icon='dialog-positive')
            job.status = 'SUCCESS'
        except subprocess.CalledProcessError as e:
            print(f'Error executing {job}: {e}', file=sys.stderr)
            notify(job.name,
                   f'encountered an error: {e}',
                   icon='dialog-error',
                   urgency='CRITICAL')
            with open(f'{SCHED_DIR}/{job.name}_log.txt',
                      'w') as error_log_file:
                error_log_file.write(job.output)
            job.status = 'ERROR'
            has_errors = True
        except TimeoutException as e:
            print(f'Timeout executing {job}: {e}', file=sys.stderr)
            notify(job.name,
                   'timed out',
                   icon='dialog-error',
                   urgency='CRITICAL')
            job.status = 'ERROR'
            has_errors = True

    job_to_last_executed = {job.name: job.to_spool() for job in jobs}

    return {
        'jobs': job_to_last_executed,
        'did_something': len(due_jobs) > 0,
        # We don't want to signal an error if it's not from the current execution.
        # Therefore, only due_jobs are considered.
        'has_errors': any(job.status == 'ERROR' for job in due_jobs),
    }
if __name__ == '__main__':

    nodes, connections, degrees, freedoms = read_graph_data('Graph500.txt')
    data_storage = join('data', 'mls')
    solutions = pd.DataFrame()
    limit_in_seconds = 15
    for j in range(25):
        tic2 = perf_counter()
        graph = Graph(nodes=nodes,
                      connections=connections,
                      freedoms=freedoms,
                      degrees=degrees)
        previous_solution = {}
        try:
            with (time_limit(limit_in_seconds, 'MLS')):
                while True:
                    if previous_solution:
                        graph.init_partition(previous_solution['solution'])
                    else:
                        graph.init_partition()

                    graph.setup_gains()
                    result = graph.fiduccia_mattheyses()
                    previous_solution = result

        except TimeoutException:
            pass
        solution = previous_solution['solution']
        solution['cutstate'] = previous_solution['cutstate']
        solution = previous_solution['solution']
Exemple #3
0
    current_position = update_position(current_position, user_move, False)

    # show the current view
    view = create_view(current_position, False)
    print_position(view)

    # update the information of the computer
    computer_view = create_view(current_position, True)
    possible = engine.update_possible(possible, True, computer_view)
    print(len(possible))

    # come up with computer move
    node = engine.Node(view=computer_view, possible=possible, turn=True)

    try:
        with time_limit(30):
            engine.iterative_deepening(node, 10)
    except TimeoutError as e:
        print("Timed out!")

    print(engine.lookup_table["principal_variation"])
    computer_move = engine.lookup_table["principal_variation"][0]

    # play computer move
    current_position = update_position(current_position, computer_move, True)

    # update the information of the computer
    computer_view = create_view(current_position, True)
    new_possible = set()
    for position in possible:
        new_position = update_position(position, computer_move, True)