Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 72c24ba3202e
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e814da1ba3f9
Choose a head ref
  • 2 commits
  • 7 files changed
  • 1 contributor

Commits on Dec 8, 2014

  1. Copy the full SHA
    123656e View commit details
  2. Copy the full SHA
    e814da1 View commit details
Showing with 67 additions and 36 deletions.
  1. +2 −2 artiq/management/scheduler.py
  2. +5 −2 artiq/management/worker.py
  3. +27 −18 artiq/management/worker_impl.py
  4. +1 −1 artiq/py2llvm/fractions.py
  5. +26 −10 frontend/artiq_client.py
  6. +2 −2 frontend/artiq_master.py
  7. +4 −1 frontend/artiq_run.py
4 changes: 2 additions & 2 deletions artiq/management/scheduler.py
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@


class Scheduler:
def __init__(self):
self.worker = Worker()
def __init__(self, *args, **kwargs):
self.worker = Worker(*args, **kwargs)
self.queue = asyncio.Queue()

@asyncio.coroutine
7 changes: 5 additions & 2 deletions artiq/management/worker.py
Original file line number Diff line number Diff line change
@@ -11,8 +11,10 @@ class WorkerFailed(Exception):


class Worker:
def __init__(self, send_timeout=0.5, start_reply_timeout=1.0,
term_timeout=1.0):
def __init__(self, ddb, pdb,
send_timeout=0.5, start_reply_timeout=1.0, term_timeout=1.0):
self.ddb = ddb
self.pdb = pdb
self.send_timeout = send_timeout
self.start_reply_timeout = start_reply_timeout
self.term_timeout = term_timeout
@@ -21,6 +23,7 @@ def __init__(self, send_timeout=0.5, start_reply_timeout=1.0,
def create_process(self):
self.process = yield from asyncio.create_subprocess_exec(
sys.executable, "-m", "artiq.management.worker_impl",
self.ddb, self.pdb,
stdout=subprocess.PIPE, stdin=subprocess.PIPE)

@asyncio.coroutine
45 changes: 27 additions & 18 deletions artiq/management/worker_impl.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import sys
import importlib
from inspect import isclass

from artiq.management import pyon


def import_in_folder(path, name):
try:
del sys.modules[name] # force path search
except KeyError:
pass
loader = importlib.find_loader(name, [path])
if loader is None:
raise ImportError("Could not find loader")
return loader.load_module()


def run(path, name):
module = import_in_folder(path, name)
module.main()
from artiq.management.file_import import file_import
from artiq.language.context import AutoContext
from artiq.management.dpdb import DeviceParamDB


def run(dpdb, file, unit, function):
module = file_import(file)
if unit is None:
units = [v for k, v in module.__dict__.items()
if k[0] != "_"
and isclass(v)
and issubclass(v, AutoContext)
and v is not AutoContext]
if len(units) != 1:
raise ValueError("Found {} units in module".format(len(units)))
unit = units[0]
else:
unit = getattr(module, unit)
unit_inst = unit(dpdb)
f = getattr(unit_inst, function)
f()


def put_object(obj):
@@ -30,13 +35,17 @@ def put_object(obj):
def main():
sys.stdout = sys.stderr

devices = pyon.load_file(sys.argv[1])
parameters = pyon.load_file(sys.argv[2])
dpdb = DeviceParamDB(devices, parameters)

while True:
line = sys.__stdin__.readline()
obj = pyon.decode(line)
put_object("ack")

try:
run(**obj)
run(dpdb, **obj)
except Exception as e:
put_object({"status": "failed", "message": str(e)})
else:
2 changes: 1 addition & 1 deletion artiq/py2llvm/fractions.py
Original file line number Diff line number Diff line change
@@ -193,7 +193,7 @@ def _o_cmp(self, other, icmp, builder):
diff = diff.auto_load(builder)
a = builder.extract_value(diff, 0)
zero = ll.Constant(ll.IntType(64), 0)
ssa_r = builder.icmp(icmp, a, zero)
ssa_r = builder.icmp_signed(icmp, a, zero)
r.auto_store(builder, ssa_r)
return r

36 changes: 26 additions & 10 deletions frontend/artiq_client.py
Original file line number Diff line number Diff line change
@@ -13,23 +13,39 @@ def _get_args():
parser.add_argument(
"--port", default=8888, type=int,
help="TCP port to use to connect to the master")
parser.add_argument(
"-o", "--run-once", default=[], nargs=3,
action="append",
help="run experiment once. arguments: <path> <name> <timeout>")

subparsers = parser.add_subparsers(dest="action")

parser_add = subparsers.add_parser("add", help="add an experiment")
parser_add.add_argument(
"-p", "--periodic", default=None, type=float,
help="run the experiment periodically every given number of seconds")
parser_add.add_argument(
"-t", "--timeout", default=None, type=float,
help="specify a timeout for the experiment to complete")
parser_add.add_argument("-f", "--function", default="run",
help="function to run")
parser_add.add_argument("-u", "--unit", default=None,
help="unit to run")
parser_add.add_argument("file", help="file containing the unit to run")

return parser.parse_args()


def main():
args = _get_args()
remote = Client(args.server, args.port, "master")
try:
for path, name, timeout in args.run_once:
remote.run_once(
{
"path": path,
"name": name
}, int(timeout))
if args.action == "add":
if args.periodic is None:
remote.run_once(
{
"file": args.file,
"unit": args.unit,
"function": args.function
}, args.timeout)
else:
raise NotImplementedError
finally:
remote.close_rpc()

4 changes: 2 additions & 2 deletions frontend/artiq_master.py
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@


def _get_args():
parser = argparse.ArgumentParser(description="PDQ2 controller")
parser = argparse.ArgumentParser(description="ARTIQ master")
parser.add_argument(
"--bind", default="::1",
help="hostname or IP address to bind to")
@@ -22,7 +22,7 @@ def main():
args = _get_args()
loop = asyncio.get_event_loop()
try:
scheduler = Scheduler()
scheduler = Scheduler("ddb.pyon", "pdb.pyon")
loop.run_until_complete(scheduler.start())
try:
server = Server(scheduler, "master")
5 changes: 4 additions & 1 deletion frontend/artiq_run.py
Original file line number Diff line number Diff line change
@@ -57,7 +57,10 @@ def main():
module = file_import(args.file)
if args.unit is None:
units = [(k, v) for k, v in module.__dict__.items()
if k[0] != "_" and isclass(v) and issubclass(v, AutoContext) and v is not AutoContext]
if k[0] != "_"
and isclass(v)
and issubclass(v, AutoContext)
and v is not AutoContext]
l = len(units)
if l == 0:
print("No units found in module")