Beispiel #1
0
def test_call_returns_a_data_structure_with_result():
    r = Procedure.call()
    assert r.success is not None

    r = Procedure.call(foo="bar", baz="bang")
    assert r.foo == "bar"
    assert r.baz == "bang"
    assert r.success == True
Beispiel #2
0
def initData():
   """Load data and mappings from Raw data files and mapping files"""
   Patient.load()
   Med.load()
   Problem.load()
   Lab.load()
   Refill.load()
   VitalSigns.load()
   Immunization.load()
   Procedure.load()
   SocialHistory.load()
   FamilyHistory.load()
   Allergy.load()
Beispiel #3
0
def initData():
    """Load data and mappings from Raw data files and mapping files"""
    Patient.load()
    Med.load()
    Problem.load()
    Lab.load()
    Refill.load()
    VitalSigns.load()
    Immunization.load()
    Procedure.load()
    SocialHistory.load()
    FamilyHistory.load()
    ClinicalNote.load()
    Allergy.load()
Beispiel #4
0
def experiment(cfg):
    print(omegaconf.OmegaConf.to_yaml(cfg), end="\n\n\n")
    agent_conf = cfg.agent
    buffer_conf = cfg.buffer
    simulation_conf = cfg.simulation
    procedure_conf = cfg.procedure
    experiment_conf = cfg.experiment
    with Procedure(agent_conf, buffer_conf, simulation_conf,
                   procedure_conf) as procedure:
        n_episode_batch = experiment_conf.n_episodes // simulation_conf.n
        for episode_batch in range(n_episode_batch):
            policy = (episode_batch + 1) % experiment_conf.policy_every == 0
            critic = (episode_batch + 1) % experiment_conf.critic_every == 0
            evaluation = (episode_batch +
                          1) % experiment_conf.evaluate_every == 0
            save = (episode_batch + 1) % experiment_conf.save_every == 0
            record = (episode_batch +
                      1) % experiment_conf.record_episode_every == 0
            dump_buffers = episode_batch in experiment_conf.dump_buffers_at
            print_info = (episode_batch + 1) % 10 == 0
            print(
                "batch {: 5d}\tevaluation:{}\tpolicy:{}\tcritic:{}\tsave:{}\trecord:{}\tdump buffers:{}"
                .format(episode_batch + 1, evaluation, policy, critic, save,
                        record, dump_buffers))
            procedure.collect_train_and_log(policy=policy,
                                            critic=critic,
                                            evaluation=evaluation)
            if save:
                procedure.save()
            if record:
                procedure.replay(
                    record=True,
                    video_name='./replays/replay_{:05d}.mp4'.format(
                        episode_batch),
                    n_episodes=1,
                    exploration=False)
            if dump_buffers:
                procedure.dump_buffers()
            if print_info:
                print('n_exploration_episodes  ...  ',
                      procedure.n_exploration_episodes)
                print('n_evaluation_episodes  ....  ',
                      procedure.n_evaluation_episodes)
                print('n_transition_gathered  ....  ',
                      procedure.n_transition_gathered)
                print('n_policy_training  ........  ',
                      procedure.n_policy_training)
                print('n_critic_training  ........  ',
                      procedure.n_critic_training)
                print('n_global_training  ........  ',
                      procedure.n_global_training)
        if not save:
            procedure.save()
        if experiment_conf.final_recording:
            print("Generating final recording (without exploration)")
            procedure.replay(record=True,
                             video_name='./replays/replay_final.mp4',
                             n_episodes=1,
                             exploration=False)
        print("Experiment finished, hope it worked. Good bye!")
Beispiel #5
0
def initData():
    """Load data and mappings from Raw data files and mapping files"""
    Patient.load()
    VitalSigns.load()
    Lab.load()
    Procedure.load()
    Immunization.load()
    FamilyHistory.load()
    SocialHistory.load()
    Condition.load()
    Med.load()
    Refill.load()
    Document.load()
    Allergy.load()
    ClinicalNote.load()
    Practitioner.load()
    Coverage.load()
    ExplanationOfBenefit.load()
Beispiel #6
0
    def __processFiles(self,
                       path,
                       spacecraft,
                       procpath,
                       collection,
                       checkLoadable=True):

        if not os.path.isdir(path):
            LOG("Discarding file: " + path)
            return

        if not path in sys.path:
            LOG("Append python path: " + path)
            sys.path.append(path)

        filelist = os.listdir(path)
        for procfile in filelist:
            thefile = os.path.splitext(procfile)
            if thefile[1] == '.py' and thefile[0] != "__init__":
                try:
                    self.__parser.parseFile(path + os.sep + procfile)
                except ParseError, e:
                    LOG(e.message + ": " + procfile)
                    continue
                except NotLoadable, e:
                    LOG(e.message + ": " + procfile)
                    continue

                fullpath = path + os.sep + procfile
                procId = fullpath.split(procpath)[1][1:][:-3]
                theProcedure = Procedure(procId, self.__parser.properties(),
                                         fullpath)

                if self.__isDomainApplicable(theProcedure, spacecraft):
                    collection[procId] = theProcedure
                    self.__filenameToId[fullpath] = procId
                    procName = theProcedure.name()
                    id = procId + "|" + procName
                    if checkLoadable and theProcedure.isLoadable()\
                       and not id in self.__loadableProcedures:
                        self.__loadableProcedures.append(id)
                else:
                    LOG("Discarding procedure: " + procId)
Beispiel #7
0
    def __processFiles(self, path, spacecraft, procpath, collection, checkLoadable = True ):
    
        if not os.path.isdir(path):
            LOG("Discarding file: " + path)
            return

        if not path in sys.path:
            LOG("Append python path: " + path)
            sys.path.append( path )
        
        filelist = os.listdir(path)
        for procfile in filelist:
            thefile = os.path.splitext(procfile)
            if thefile[1] == '.py' and thefile[0] != "__init__":
                try:
                    self.__parser.parseFile( path + os.sep + procfile)
                except ParseError,e:
                    LOG(e.message + ": " + procfile)
                    continue
                except NotLoadable,e:
                    LOG(e.message + ": " + procfile)
                    continue
                
                fullpath = path + os.sep + procfile
                procId = fullpath.split( procpath )[1][1:][:-3]
                theProcedure = Procedure(procId, self.__parser.properties(), fullpath)

                if self.__isDomainApplicable(theProcedure, spacecraft):
                    collection[procId] = theProcedure
                    self.__filenameToId[fullpath] = procId
                    procName = theProcedure.name()
                    id = procId + "|" + procName
                    if checkLoadable and theProcedure.isLoadable()\
                       and not id in self.__loadableProcedures:
                        self.__loadableProcedures.append(id)
                else:
                    LOG("Discarding procedure: " + procId)
Beispiel #8
0
def test_it_raises_an_error_if_initialized_with_arguments():
    with pytest.raises(ValueError) as excinfo:
        Procedure(foo="bar", baz="bang")
    assert str(
        excinfo.value
    ) == "Do not call a class by initializing it. Use ClassName.call() instead."

    class Example(Procedure):
        def run(self):
            self.ctx.calc = 1 + 1

    with pytest.raises(ValueError) as excinfo:
        Example(foo="bar", baz="bang")
    assert str(
        excinfo.value
    ) == "Do not call a class by initializing it. Use ClassName.call() instead."
def processBatch(a_b):
    a, b = a_b
    d = DatastoreClient()
    p = Patient()
    e = Encounter()
    m = Medication()
    o = Observations()
    dr = DiagnosticReport()
    md = MedicationDispense()
    pr = Procedure()

    all_patient = sorted(p.all_patient())

    for i in range(a, b):
        if i >= len(all_patient):
            break
        id = all_patient[i]
        getPatientRecords(d, p, e, m, o, dr, md, pr, id)

    return True
Beispiel #10
0
from procedure import Procedure
from procedure import Parameter
import copy

procedure_list = []
{% for p in procs %}

proc = Procedure('{{ p.name }}')
{% for in_param in p.in_params %}
param = Parameter('{{ in_param.name }}')
param.set_type('{{ in_param.type }}')
proc.add_in_param(param)
{% endfor -%}
{% for out_param in p.out_params %}
param = Parameter('{{ out_param.name}}')
param.set_type('{{ out_param.type }}')
proc.add_out_param(param)
{% endfor -%}
procedure_list.append(proc)
{%- endfor %}

def get_procedure(proc_name):
    for p in procedure_list:
        if proc_name.upper() == p.name.upper():
            return copy.deepcopy(p)
    raise ValueError('Procedure %s doesn\'t exist' % proc_name)

Beispiel #11
0
def test_call_method_signature():
    Procedure.call(foo="bar", baz="bang")
def parseProcedure(fp,dataset):
    """
    FUNCTION IfcVectorSum
	(Arg1, Arg2 : IfcVectorOrDirection)
	: IfcVector;
    """
    func=Procedure()      
    
    #Function name 
    name=geti(fp)   

    #args begin
    token=geti(fp)
    if token!='(':
        log.error('Function has no args, line %d'%common.counter)
        return

    #args
    token=geti(fp)
    while True:
        args=[token]
        token=geti(fp)
        if token==',':
            while token!=':':   
                token=geti(fp)
                args.append(token)
                token=geti(fp)
        if token==':':
            value=''
            token=geti(fp)              
            while token!=';' and token!=')':
                value+=token+' '
                token=geti(fp)              
            
        for arg in args:
            func.arg[arg]=value.strip()
        
        if token==')':
            break

        #next element
        token=geti(fp)
    
    #:
    token=geti(fp)
    if token!=':':
        log.error('Function ret has no :, line %d'%common.counter)
        return

    #ret
    ret=''
    token=geti(fp)
    while token!=';':
        ret+=token+' '
        token=geti(fp)

    func.ret=ret.strip()
    
    #local
    parseLocal(fp,func)

    #code
    parseCode(fp,func)

    # where clause
    func.where=parseWhere(fp)       

    #parse END_TYPE
    token=geti(fp)
    if token!='END_FUNCTION':
        log.error('FUNCTION Defination has no END_FUNCTION, line %d'%common.counter)
        return
    token=geti(fp)#skip ;   
    if token!=';':
        log.error('FUNCTION Defination does not end with ;, line %d'%common.counter)
        return

    dataset.functions[name]=func
 def test(self):
     Procedure(self.driver).test()
Beispiel #14
0
def full_evaluate(expression, environment):
    """
    Fully evaluate an expression until its basic representation
    """

    while True:
        if is_thunk(expression):
            if not expression.is_evaluated:
                expression.is_evaluated = True
                expression.expression = full_evaluate(expression.expression,
                                                      expression.environment)
            return expression.expression
        elif is_symbol(expression):
            expression = environment[expression]
            continue
        elif (is_atom(expression) or is_nil(expression)
              or is_procedure(expression) or is_macro(expression)
              or callable(expression)):
            return expression
        elif not is_pair(expression):
            raise ValueError("Cannot evaluate: %s" % expression)
        elif car(expression) == 'delay':
            if len(expression) != 2:
                raise SyntaxError(
                    "Unexpected delay form: %s. Should be (delay <expression>)"
                    % expression)
            return Thunk(cadr(expression), environment)
        elif car(expression) == 'defined?':
            if len(expression) != 2:
                raise SyntaxError(
                    "Unexpected defined? form: %s. Should be (defined? <symbol>)"
                    % expression)
            name = cadr(expression)
            if not is_symbol(name):
                raise SyntaxError(
                    "Argument of defined? form should be a symbol. Evaluating: %s"
                    % expression)
            return environment.exists(name)
        elif car(expression) == 'define':
            if len(expression) != 3:
                raise SyntaxError(
                    "Unexpected define form: %s. Should be (define <symbol> <expression>)"
                    % expression)
            name = cadr(expression)
            if not is_symbol(name):
                raise SyntaxError(
                    "First argument of define form should be a symbol. Evaluating: %s"
                    % expression)
            environment[name] = Thunk(caddr(expression), environment)
            return name
        elif car(expression) == 'quote':
            if len(expression) != 2:
                raise SyntaxError(
                    "Unexpected quote form: %s. Should be (quote <expression>)"
                    % expression)
            return cadr(expression)
        elif car(expression) == 'eval':
            if len(expression) != 2:
                raise SyntaxError(
                    "Unexpected eval form: %s. Should be (eval <expression>)" %
                    expression)
            expression = full_evaluate(cadr(expression), environment)
            continue
        elif car(expression) == 'if':
            if len(expression) != 4:
                raise SyntaxError(
                    "Unexpected if form: %s. Should be (if <condition> <consequent> <alternative>)"
                    % expression)
            condition = full_evaluate(cadr(expression), environment)
            expression = caddr(expression) if condition else cadddr(expression)
            continue
        elif car(expression) == 'lambda':
            if len(expression) < 3:
                raise SyntaxError(
                    "Unexpected lambda form: %s. Should be (lambda (<param> ...) <expression> ...)"
                    % expression)
            parameters = cadr(expression)
            if is_pair(parameters):
                current = parameters
                while is_pair(current):
                    if not is_symbol(car(current)):
                        raise SyntaxError(
                            "Lambda parameters should be symbols. In %s" %
                            expression)
                    current = cdr(current)
                if not is_nil(current) and not is_symbol(current):
                    raise SyntaxError(
                        "Lambda optional parameter should be a symbol or nil. In %s"
                        % expression)
            elif not is_symbol(parameters) and not is_nil(parameters):
                raise SyntaxError(
                    "Lambda parameters should be a symbol or a list of zero or more. In %s"
                    % expression)

            return Procedure(
                parameters,  # parameters
                cddr(expression),  # body (list of expressions)
                environment)
        elif car(expression) == 'macro':
            if len(expression) < 3:
                raise SyntaxError(
                    "Unexpected define macro: %s. Should be (macro (<resword> ...) (<pattern> <transformation> ...) ...)"
                    % expression)
            res_words = cadr(expression)
            rules = cddr(expression)
            if not is_nil(res_words) and not is_pair(res_words):
                raise SyntaxError(
                    "Macro reserved words should be a list of symbols or nil. In %s"
                    % expression)
            if is_pair(res_words):
                for word in res_words:
                    if not is_symbol(word):
                        raise SyntaxError(
                            "Macro reserved words should all be symbols. In %s"
                            % expression)
            for rule in rules:
                if len(rule) < 2:
                    raise SyntaxError(
                        "Macro rule should be in the form (<pattern> <expression> ...). In %s"
                        % expression)
            return Macro(
                [(car(e), cdr(e)) for e in rules],  # rules
                []
                if not res_words else set(iter(res_words)))  # reserved words
        else:
            # evaluate head
            operator = full_evaluate(car(expression), environment)

            if is_macro(operator):
                # evaluate recursively only the inner expressions (not the last)
                current = operator.transform(expression)
                while cdr(current) is not None:
                    full_evaluate(car(current), environment)
                    current = cdr(current)
                expression = car(current)
                continue
            else:
                # The unevaluated operands
                unev_operands = cdr(expression)

                if callable(operator):
                    # evaluate each operand recursively
                    operands = [
                        full_evaluate(e, environment) for e in unev_operands
                    ] if unev_operands else []
                    # return the application of the built-in procedure
                    return operator(make_list(operands))
                elif is_procedure(operator):
                    # create Thunks (promise to evaluate) for each operand
                    unev_op_list = list(
                        iter(unev_operands)) if unev_operands else []
                    proc_environment = Environment(parent=operator.environment)
                    # if the lambda parameters is not in the format ( () [. <symbol>] )
                    # for taking zero or more arguments
                    if len(operator.parameters) != 1 or not is_nil(
                            operator.parameters[0]):
                        for name in operator.parameters:
                            try:
                                # take next argument
                                proc_environment[name] = Thunk(
                                    unev_op_list.pop(0), environment)
                            except IndexError:
                                raise ValueError(
                                    "Insufficient parameters for procedure %s. It should be at least %d"
                                    % (operator, len(operator.parameters)))
                    if not is_nil(operator.optional):
                        # the optional argument is something, that when
                        # evaluated, yields the list of rest of the operands
                        # evaluated
                        proc_environment[operator.optional] = Thunk(
                            cons(lambda x: x, make_list(unev_op_list)),
                            environment)
                    elif unev_op_list:
                        raise ValueError(
                            "Too much parameters for procedure %s. It should be %d."
                            % (operator, len(operator.parameters)))

                    # evaluate recursively only the inner procedure expressions
                    # (not the last)
                    current = operator.body
                    while cdr(current) is not None:
                        full_evaluate(car(current), proc_environment)
                        current = cdr(current)

                    environment = proc_environment
                    expression = car(current)
                    # continue not-recursively to evaluate the procedure's body
                    # in the extended environment
                    continue
                else:
                    raise ValueError("Not an operator: %s, in expression: %s" %
                                     (operator, expression))
Beispiel #15
0
            if thefile[1] == '.py' and thefile[0] != "__init__":
                try:
                    self.__parser.parseFile(path + os.sep + procfile)
                except ParseError, e:
                    LOG(e.message + ": " + procfile)
                    continue
                except NotLoadable, e:
                    LOG(e.message + ": " + procfile)
                    continue
                except:
                    LOG("Unable to read file: " + procfile, LOG_ERROR)
                    continue

                fullpath = path + os.sep + procfile
                procId = fullpath.split(procpath)[1][1:][:-3]
                theProcedure = Procedure(procId, self.__parser.properties(),
                                         fullpath)

                if self.__isDomainApplicable(theProcedure, spacecraft):
                    collection[procId] = theProcedure
                    self.__filenameToId[fullpath] = procId
                    procName = theProcedure.name()
                    id = procId + "|" + procName
                    if checkLoadable and theProcedure.isLoadable()\
                       and not id in self.__loadableProcedures:
                        self.__loadableProcedures.append(id)
                else:
                    LOG("Discarding procedure: " + procId)
            elif thefile[1] == '.pyc':
                os.remove(path + os.sep + procfile)
            elif thefile[1] == '':
                self.__processFiles(path + os.sep + thefile[0], spacecraft,
Beispiel #16
0
            if thefile[1] == '.py' and thefile[0] != "__init__":
                try:
                    self.__parser.parseFile( path + os.sep + procfile)
                except ParseError,e:
                    LOG(e.message + ": " + procfile)
                    continue
                except NotLoadable,e:
                    LOG(e.message + ": " + procfile)
                    continue
                except:
                    LOG("Unable to read file: " + procfile, LOG_ERROR)
                    continue
                
                fullpath = path + os.sep + procfile
                procId = fullpath.split( procpath )[1][1:][:-3]
                theProcedure = Procedure(procId, self.__parser.properties(), fullpath)

                if self.__isDomainApplicable(theProcedure, spacecraft):
                    collection[procId] = theProcedure
                    self.__filenameToId[fullpath] = procId
                    procName = theProcedure.name()
                    id = procId + "|" + procName
                    if checkLoadable and theProcedure.isLoadable()\
                       and not id in self.__loadableProcedures:
                        self.__loadableProcedures.append(id)
                else:
                    LOG("Discarding procedure: " + procId)
            elif thefile[1]=='.pyc':
                os.remove(path + os.sep + procfile)
            elif thefile[1]=='':
                self.__processFiles( path + os.sep + thefile[0], spacecraft, procpath, collection, checkLoadable)