reorganize files as per discussion with Robert

This commit is contained in:
Sebastien Bourdeauducq 2015-01-17 19:38:20 +08:00
parent 6cc3a9d973
commit 3e22fe86b5
31 changed files with 131 additions and 130 deletions

View File

@ -8,10 +8,14 @@ from operator import itemgetter
from prettytable import PrettyTable from prettytable import PrettyTable
from artiq.management.pc_rpc import Client from artiq.protocols.pc_rpc import Client
from artiq.management.sync_struct import Subscriber from artiq.protocols.sync_struct import Subscriber
from artiq.management.tools import clear_screen, format_run_arguments from artiq.protocols import pyon
from artiq.management import pyon from artiq.tools import format_run_arguments
def clear_screen():
sys.stdout.write("\x1b[2J\x1b[H")
def _get_args(): def _get_args():

View File

@ -2,7 +2,7 @@
import argparse import argparse
from artiq.management.pc_rpc import Client from artiq.protocols.pc_rpc import Client
def _get_args(): def _get_args():

View File

@ -7,7 +7,7 @@ import atexit
import gbulb import gbulb
from gi.repository import Gtk from gi.repository import Gtk
from artiq.management.pc_rpc import AsyncioClient from artiq.protocols.pc_rpc import AsyncioClient
from artiq.gui.scheduler import SchedulerWindow from artiq.gui.scheduler import SchedulerWindow
from artiq.gui.parameters import ParametersWindow from artiq.gui.parameters import ParametersWindow
from artiq.gui.rt_results import RTResults from artiq.gui.rt_results import RTResults

View File

@ -2,7 +2,7 @@
import argparse import argparse
from artiq.management.pc_rpc import Client from artiq.protocols.pc_rpc import Client
def main(): def main():

View File

@ -3,7 +3,7 @@
import argparse import argparse
from artiq.devices.lda.driver import Lda, Ldasim from artiq.devices.lda.driver import Lda, Ldasim
from artiq.management.pc_rpc import simple_server_loop from artiq.protocols.pc_rpc import simple_server_loop
def main(): def main():

View File

@ -4,9 +4,9 @@ import asyncio
import argparse import argparse
import atexit import atexit
from artiq.management.pc_rpc import Server from artiq.protocols.pc_rpc import Server
from artiq.management.sync_struct import Publisher from artiq.protocols.sync_struct import Publisher
from artiq.management.db import FlatFileDB, SimpleHistory from artiq.protocols.file_db import FlatFileDB, SimpleHistory
from artiq.master.scheduler import Scheduler from artiq.master.scheduler import Scheduler
from artiq.master.rt_results import RTResults from artiq.master.rt_results import RTResults

View File

@ -8,7 +8,7 @@ import time
from scipy import interpolate from scipy import interpolate
import numpy as np import numpy as np
from artiq.management.pc_rpc import Client from artiq.protocols.pc_rpc import Client
def _get_args(): def _get_args():

View File

@ -4,7 +4,7 @@ import argparse
import logging import logging
from artiq.devices.pdq2.driver import Pdq2 from artiq.devices.pdq2.driver import Pdq2
from artiq.management.pc_rpc import simple_server_loop from artiq.protocols.pc_rpc import simple_server_loop
def _get_args(): def _get_args():

View File

@ -6,10 +6,11 @@ from inspect import isclass
from operator import itemgetter from operator import itemgetter
from itertools import chain from itertools import chain
from artiq.management.file_import import file_import
from artiq.language.db import * from artiq.language.db import *
from artiq.management import pyon from artiq.protocols import pyon
from artiq.management.db import * from artiq.protocols.file_db import FlatFileDB
from artiq.master.db import DBHub, ResultDB
from artiq.tools import file_import
class ELFRunner(AutoDB): class ELFRunner(AutoDB):

View File

@ -5,7 +5,7 @@ import time
from gi.repository import Gtk from gi.repository import Gtk
from artiq.gui.tools import Window, ListSyncer, DictSyncer from artiq.gui.tools import Window, ListSyncer, DictSyncer
from artiq.management.sync_struct import Subscriber from artiq.protocols.sync_struct import Subscriber
class _ParameterStoreSyncer(DictSyncer): class _ParameterStoreSyncer(DictSyncer):

View File

@ -4,7 +4,7 @@ from collections import defaultdict
from gi.repository import Gtk from gi.repository import Gtk
import cairoplot import cairoplot
from artiq.management.sync_struct import Subscriber from artiq.protocols.sync_struct import Subscriber
from artiq.gui.tools import Window from artiq.gui.tools import Window

View File

@ -4,8 +4,8 @@ import asyncio
from gi.repository import Gtk from gi.repository import Gtk
from artiq.gui.tools import Window, ListSyncer, DictSyncer from artiq.gui.tools import Window, ListSyncer, DictSyncer
from artiq.management.sync_struct import Subscriber from artiq.protocols.sync_struct import Subscriber
from artiq.management.tools import format_run_arguments from artiq.tools import format_run_arguments
class _QueueStoreSyncer(ListSyncer): class _QueueStoreSyncer(ListSyncer):

View File

@ -1,53 +1,7 @@
from collections import OrderedDict from collections import OrderedDict
import importlib import importlib
from time import time
from artiq.language.db import * from artiq.protocols.sync_struct import Notifier
from artiq.management import pyon
from artiq.management.sync_struct import Notifier
class FlatFileDB:
def __init__(self, filename):
self.filename = filename
self.data = Notifier(pyon.load_file(self.filename))
self.hooks = []
def save(self):
pyon.store_file(self.filename, self.data.read)
def request(self, name):
return self.data.read[name]
def set(self, name, value):
self.data[name] = value
self.save()
timestamp = time()
for hook in self.hooks:
hook.set(timestamp, name, value)
def delete(self, name):
del self.data[name]
self.save()
timestamp = time()
for hook in self.hooks:
hook.delete(timestamp, name)
class SimpleHistory:
def __init__(self, depth):
self.depth = depth
self.history = Notifier([])
def set(self, timestamp, name, value):
if len(self.history.read) >= self.depth:
del self.history[0]
self.history.append((timestamp, name, value))
def delete(self, timestamp, name):
if len(self.history.read) >= self.depth:
del self.history[0]
self.history.append((timestamp, name))
class ResultDB: class ResultDB:

View File

@ -1,4 +1,4 @@
from artiq.management.sync_struct import Notifier, process_mod from artiq.protocols.sync_struct import Notifier, process_mod
class RTResults: class RTResults:

View File

@ -1,7 +1,7 @@
import asyncio import asyncio
from time import time from time import time
from artiq.management.sync_struct import Notifier from artiq.protocols.sync_struct import Notifier
from artiq.master.worker import Worker from artiq.master.worker import Worker

View File

@ -4,7 +4,7 @@ import subprocess
import signal import signal
import traceback import traceback
from artiq.management import pyon from artiq.protocols import pyon
class WorkerFailed(Exception): class WorkerFailed(Exception):

View File

@ -2,10 +2,10 @@ import sys
from inspect import isclass from inspect import isclass
import traceback import traceback
from artiq.management import pyon from artiq.protocols import pyon
from artiq.management.file_import import file_import from artiq.tools import file_import
from artiq.language.db import AutoDB from artiq.language.db import AutoDB
from artiq.management.db import DBHub, ResultDB from artiq.master.db import DBHub, ResultDB
def get_object(): def get_object():

View File

@ -1,21 +1,5 @@
import asyncio import asyncio
import sys
from copy import copy from copy import copy
from operator import itemgetter
def clear_screen():
sys.stdout.write("\x1b[2J\x1b[H")
def format_run_arguments(arguments):
fmtargs = []
for k, v in sorted(arguments.items(), key=itemgetter(0)):
fmtargs.append(k + "=" + str(v))
if fmtargs:
return " ".join(fmtargs)
else:
return "-"
class AsyncioServer: class AsyncioServer:

View File

@ -0,0 +1,47 @@
from time import time
from artiq.protocols import pyon
from artiq.protocols.sync_struct import Notifier
class FlatFileDB:
def __init__(self, filename):
self.filename = filename
self.data = Notifier(pyon.load_file(self.filename))
self.hooks = []
def save(self):
pyon.store_file(self.filename, self.data.read)
def request(self, name):
return self.data.read[name]
def set(self, name, value):
self.data[name] = value
self.save()
timestamp = time()
for hook in self.hooks:
hook.set(timestamp, name, value)
def delete(self, name):
del self.data[name]
self.save()
timestamp = time()
for hook in self.hooks:
hook.delete(timestamp, name)
class SimpleHistory:
def __init__(self, depth):
self.depth = depth
self.history = Notifier([])
def set(self, timestamp, name, value):
if len(self.history.read) >= self.depth:
del self.history[0]
self.history.append((timestamp, name, value))
def delete(self, timestamp, name):
if len(self.history.read) >= self.depth:
del self.history[0]
self.history.append((timestamp, name))

View File

@ -1,7 +1,7 @@
""" """
This module provides a remote procedure call (RPC) mechanism over sockets This module provides a remote procedure call (RPC) mechanism over sockets
between conventional computers (PCs) running Python. It strives to be between conventional computers (PCs) running Python. It strives to be
transparent and uses ``artiq.management.pyon`` internally so that e.g. Numpy transparent and uses ``artiq.protocols.pyon`` internally so that e.g. Numpy
arrays can be easily used. arrays can be easily used.
Note that the server operates on copies of objects provided by the client, Note that the server operates on copies of objects provided by the client,
@ -16,8 +16,8 @@ import socket
import asyncio import asyncio
import traceback import traceback
from artiq.management import pyon from artiq.protocols import pyon
from artiq.management.tools import AsyncioServer as _AsyncioServer from artiq.protocols.asyncio_server import AsyncioServer as _AsyncioServer
class RemoteError(Exception): class RemoteError(Exception):
@ -140,7 +140,7 @@ class Client:
class AsyncioClient: class AsyncioClient:
"""This class is similar to :class:`artiq.management.pc_rpc.Client`, but """This class is similar to :class:`artiq.protocols.pc_rpc.Client`, but
uses ``asyncio`` instead of blocking calls. uses ``asyncio`` instead of blocking calls.
All RPC methods are coroutines. All RPC methods are coroutines.

View File

@ -1,8 +1,8 @@
import asyncio import asyncio
from operator import getitem from operator import getitem
from artiq.management import pyon from artiq.protocols import pyon
from artiq.management.tools import AsyncioServer from artiq.protocols.asyncio_server import AsyncioServer
_init_string = b"ARTIQ sync_struct\n" _init_string = b"ARTIQ sync_struct\n"

View File

@ -6,7 +6,7 @@ import time
import numpy as np import numpy as np
from artiq.management import pc_rpc from artiq.protocols import pc_rpc
test_address = "::1" test_address = "::1"

View File

@ -5,7 +5,7 @@ from fractions import Fraction
import numpy as np import numpy as np
from artiq.language.units import * from artiq.language.units import *
from artiq.management import pyon from artiq.protocols import pyon
_pyon_test_object = { _pyon_test_object = {

View File

@ -1,7 +1,18 @@
from operator import itemgetter
import importlib.machinery import importlib.machinery
import linecache import linecache
def format_run_arguments(arguments):
fmtargs = []
for k, v in sorted(arguments.items(), key=itemgetter(0)):
fmtargs.append(k + "=" + str(v))
if fmtargs:
return " ".join(fmtargs)
else:
return "-"
def file_import(filename): def file_import(filename):
linecache.checkcache(filename) linecache.checkcache(filename)

View File

@ -5,7 +5,7 @@ These drivers are for "slow" devices that are directly controlled by a PC, typic
Certain devices (such as the PDQ2) may still perform real-time operations by having certain controls physically connected to the core device (for example, the trigger and frame selection signals on the PDQ2). For handling such cases, parts of the drivers may be kernels executed on the core device. Certain devices (such as the PDQ2) may still perform real-time operations by having certain controls physically connected to the core device (for example, the trigger and frame selection signals on the PDQ2). For handling such cases, parts of the drivers may be kernels executed on the core device.
Each driver is run in a separate "controller" that exposes a RPC interface (based on :class:`artiq.management.pc_rpc`) to its functions. The master never does direct I/O to the devices, but issues RPCs to the controllers when needed. As opposed to running everything on the master, this architecture has those main advantages: Each driver is run in a separate "controller" that exposes a RPC interface (based on :class:`artiq.protocols.pc_rpc`) to its functions. The master never does direct I/O to the devices, but issues RPCs to the controllers when needed. As opposed to running everything on the master, this architecture has those main advantages:
* Each driver can be run on a different machine, which alleviates cabling issues and OS compatibility problems. * Each driver can be run on a different machine, which alleviates cabling issues and OS compatibility problems.
* Reduces the impact of driver crashes. * Reduces the impact of driver crashes.

View File

@ -11,6 +11,6 @@ Contents:
writing_a_driver writing_a_driver
core_language_reference core_language_reference
core_drivers_reference core_drivers_reference
management_reference protocols_reference
drivers_reference drivers_reference
fpga_board_ports fpga_board_ports

View File

@ -1,27 +0,0 @@
Management reference
====================
:mod:`artiq.management.pyon` module
-----------------------------------
.. automodule:: artiq.management.pyon
:members:
:mod:`artiq.management.tools` module
------------------------------------
.. automodule:: artiq.management.tools
:members:
:mod:`artiq.management.pc_rpc` module
-------------------------------------
.. automodule:: artiq.management.pc_rpc
:members:
:mod:`artiq.management.sync_struct` module
------------------------------------------
.. automodule:: artiq.management.sync_struct
:members:

View File

@ -0,0 +1,27 @@
Management reference
====================
:mod:`artiq.protocols.pyon` module
----------------------------------
.. automodule:: artiq.protocols.pyon
:members:
:mod:`artiq.protocols.tools` module
-----------------------------------
.. automodule:: artiq.protocols.tools
:members:
:mod:`artiq.protocols.pc_rpc` module
------------------------------------
.. automodule:: artiq.protocols.pc_rpc
:members:
:mod:`artiq.protocols.sync_struct` module
-----------------------------------------
.. automodule:: artiq.protocols.sync_struct
:members:

View File

@ -6,7 +6,7 @@ These instructions cover writing a simple driver for a "slow" device, that uses
The controller The controller
-------------- --------------
A controller is a piece of software that receives commands from a client over the network (or the ``localhost`` interface), drives a device, and returns information about the device to the client. The mechanism used is remote procedure calls (RPCs) using :class:`artiq.management.pc_rpc`, which makes the network layers transparent for the driver's user. A controller is a piece of software that receives commands from a client over the network (or the ``localhost`` interface), drives a device, and returns information about the device to the client. The mechanism used is remote procedure calls (RPCs) using :class:`artiq.protocols.pc_rpc`, which makes the network layers transparent for the driver's user.
The controller we will develop is for a "device" that is very easy to work with: the console from which the controller is run. The operation that the driver will implement is writing a message to that console. The controller we will develop is for a "device" that is very easy to work with: the console from which the controller is run. The operation that the driver will implement is writing a message to that console.
@ -16,9 +16,9 @@ For using RPC, the functions that a driver provides must be the methods of a sin
def message(self, msg): def message(self, msg):
print("message: " + msg) print("message: " + msg)
To turn it into a server, we use :class:`artiq.management.pc_rpc`. Import the function we will use: :: To turn it into a server, we use :class:`artiq.protocols.pc_rpc`. Import the function we will use: ::
from artiq.management.pc_rpc import simple_server_loop from artiq.protocols.pc_rpc import simple_server_loop
and add a ``main`` function that is run when the program is executed: :: and add a ``main`` function that is run when the program is executed: ::
@ -63,7 +63,7 @@ Create a ``hello_client.py`` file with the following contents: ::
#!/usr/bin/env python3 #!/usr/bin/env python3
from artiq.management.pc_rpc import Client from artiq.protocols.pc_rpc import Client
def main(): def main():