From 7409f095f1468f19476ccfc6397a78b2a5e18c91 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 28 May 2014 22:40:26 +0200 Subject: [PATCH] Do not deal with threads for now --- examples/threads_test.py | 21 --------- examples/threads_test_lowered.py | 81 -------------------------------- 2 files changed, 102 deletions(-) delete mode 100644 examples/threads_test.py delete mode 100644 examples/threads_test_lowered.py diff --git a/examples/threads_test.py b/examples/threads_test.py deleted file mode 100644 index be95c7125..000000000 --- a/examples/threads_test.py +++ /dev/null @@ -1,21 +0,0 @@ -from artiq.sim import * -from artiq.units import * - -def threads_test(): - pulse("x", 1*MHz, 10*ms) - with parallel: - with sequential: - wait_edge("a") - delay(5*ms) - pulse("a", 30*MHz, 1*us) - wait_edge("a") - delay(10*ms) - pulse("a", 60*MHz, 1*us) - with sequential: - wait_edge("b") - delay(3*ms) - pulse("b", 30*MHz, 1*us) - -if __name__ == "__main__": - threads_test() - print(time_manager.format_timeline()) diff --git a/examples/threads_test_lowered.py b/examples/threads_test_lowered.py deleted file mode 100644 index a2c90ea39..000000000 --- a/examples/threads_test_lowered.py +++ /dev/null @@ -1,81 +0,0 @@ -from random import Random -from collections import namedtuple - -Pulse = namedtuple("Pulse", "time output frequency duration") -WaitEdge = namedtuple("WaitEdge", "time input") - -class Parallel: - def __init__(self, *threads): - self.threads = threads - -def threads_test(now): - yield Pulse(now, "x", 1, 10) - now += 10 - - def thread0(now): - now = yield WaitEdge(now, "a") - now += 5 - yield Pulse(now, "a", 30, 1) - now += 1 - now = yield WaitEdge(now, "a") - now += 10 - yield Pulse(now, "a", 60, 1) - now += 1 - return now - - def thread1(now): - now = yield WaitEdge(now, "b") - now += 3 - yield Pulse(now, "b", 30, 1) - now += 1 - return now - - now = yield Parallel(thread0(now), thread1(now)) - - return now - -prng = Random(42) - -def execute(threads): - end_time = 0 - thread_replies = [None]*len(threads) - continue_execute = True - - while continue_execute: - continue_execute = False - new_thread_replies = [] - for thread, send_data in zip(threads, thread_replies): - try: - thread_request = thread.send(send_data) - except StopIteration as e: - if e.value > end_time: - end_time = e.value - else: - continue_execute = True - thread_reply = None - if isinstance(thread_request, Pulse): - yield thread_request - elif isinstance(thread_request, WaitEdge): - yield thread_request - edge_delay = prng.randrange(100) - print("*** Simulating input edge on '{}' after {}".format(thread_request.input, edge_delay)) - thread_reply = thread_request.time + edge_delay - elif isinstance(thread_request, Parallel): - thread_reply = yield from execute(thread_request.threads) - else: - raise TypeError - new_thread_replies.append(thread_reply) - thread_replies = new_thread_replies - - return end_time - -if __name__ == "__main__": - ex = execute([threads_test(0)]) - while True: - try: - ev = next(ex) - except StopIteration as e: - print("*** Execution ended at {}".format(e.value)) - break - else: - print(ev)