Beispiel #1
0
def test_cmu_counting():

    # test CMU ACT-R Counting
    factory = cmu_factory.CmuActrFactory()
    model = factory.createModel()
    model.load("/tests/psych/count_test.lisp")

    myenv = SimpleEnvironment(name="counting")

    myexp = Experiment(model, myenv, "CMU Counting")
    myexp.start("cmu_count_test") # appends to a log file
    myexp.run(1, 50)
    myexp.stop() #closes log file
    myexp.report("ACTR")
Beispiel #2
0
def test_cmu_starcraft():

    # test CMU ACT-R Counting
    factory = cmu_factory.CmuActrFactory()
    model = factory.createModel()
    map = ['beacon_x', 'beacon_y']
    #model.perception.setObservationSpace(map)

    model.load("/tests/sc2/gym_sc2-beacons-simple.lisp")

    myenv = StarCraftEnvironment("SC2MoveToBeacon-v1")
    myexp = Experiment(model, myenv, "CMU StarCraft Beacons",map)

    model.motor.next_action = [-1, -1]

    myexp.start("cmu_beacons") # appends to a log file
    myexp.run(1, 100) #if no cycles provided, env determines end state
    myexp.stop() #closes log file
    myexp.report("ACTR")
Beispiel #3
0
def get_arch_factory(fact_name=None):

    logger.debug(f"get_arch_factory({fact_name})")
    print(f"get_factory() name: {fact_name}")

    factory = None

    lisp_actr_fact = cmu_factory.CmuActrFactory()
    python_actr_fact = ccm_factory.CcmFactory()
    soar_fact = soar_factory.SoarFactory()

    switcher = {
        'ACTR': lisp_actr_fact,
        'CCM': python_actr_fact,
        'Soar' : soar_fact
    }

    factory = switcher.get(fact_name, "Invalid arch_factory name")

    return factory
Beispiel #4
0
def test_cmu_cartpole():

    # test CMU ACT-R Counting
    factory = cmu_factory.CmuActrFactory()
    model = factory.createModel()

    model.load("/tests/gym/cartpole.lisp")

    map = ['cart_pos', 'cart_vel', 'pole_pos', 'pole_vel']
    #model.perception.setObservationSpace(map)

    myenv = GymEnvironment("CartPole-v0") #TODO: pass registered gym.env_id??

    model.motor.next_action = 0

    myexp = Experiment(model, myenv, "CMU Gym Cartpole", map)
    myexp.start("cmu_cartpole") # appends to a log file
    myexp.run(10, 195) #if no cycles provided, env determines end state
    myexp.stop() #closes log file
    myexp.report("ACTR")
Beispiel #5
0
    def do_demo(self, line=""):
        """Run the demo with multiple options."""

        psych_tests = ['Counting']
        gym_tests = ['CartPole-v0', 'MountainCar-v1', 'LunarLander-v1']  # TODO: create env registry
        sc2_tests = ['MoveToBeacon']  # TODO: replace with Gym versions

        env_list = [psych_tests, gym_tests, sc2_tests]

        #print(f"Environments Registry: {psych_envs} {gym_envs} {sc2_envs}")

        architectures = ['CMUACTR', 'CCMACTR', 'Soar', 'Nengo']  # TODO: create arch registry
        print("Architecture Registry: " + str(architectures))

        print("Starting Psych Model experiments...")



        factory_switch = {
            "CMUACTR": cmu_factory.CmuActrFactory(),
            "SOAR" : soar_factory.SoarFactory(),
            "CCMSUITE" : ccm_factory.CcmFactory()
        }

        model_switch = {
            "CMUACTR": "cmu_count_test.lisp",
            "SOAR": "soar_agent.config",
            "CCMSUITE" : ""
        }

        arch_list = ['CMUACTR', 'SOAR', 'CCMSUITE']

        for env in env_list:
#            print(f"Environment: {env}")
            for test in env:
                for arch in arch_list:
                    print(f"Running {arch} on {test} test.")
Beispiel #6
0
def compare_beacons():


    task = "visual task"
    trials = 1
    steps = 195

    test_iv = "ps"
    iv_start = 0.05
    iv_end = 0.1
    iv_inc = 0.01

    prod_test_config_switch = {
        'ACTR': "/tests/gym/cartpole.lisp",
        'CCM': 'metaverse.architectures.actr_ccmsuite.cartpole_prods',
        'Soar': "/tests/cart-pole/soar_agent.config"
    }

    architectures = ['ACTR', 'CCM', 'Soar']
    architectures1 = ['ACTR']
    architectures2 = ['CCM']
    architectures3 = ['Soar']

    reporter = scribe.Reporter()
    experiments = []

    # for arch in architectures:
    #     factory = get_arch_factory(arch)
    #     model = factory.createModel()
    #     model_file = prod_test_config_switch.get(arch)
    #     model.load(model_file)
    #     #myenv = SimpleEnvironment(task)
    #     myenv = GymEnvironment("CartPole-v0")  # TODO: pass registered gym.env_id??
    #     model.motor.next_action = 0
    #     myexp = Experiment(model, myenv, task, map)
    #     # myexp.set_parameters(test_iv, iv_start, iv_end, iv_inc )
    #     myexp.start(task + "_" + arch)  # appends to a log file
    #     myexp.run(trials, steps)
    #     myexp.stop()  # closes log file
    #     outfile = myexp.report()
    #     experiments.append([arch, outfile])
    #     reporter.add_experiment(arch, outfile)

    # test CMU ACT-R Starcraft
    factory = cmu_factory.CmuActrFactory()
    model = factory.createModel()
    map = ['beacon_x', 'beacon_y']
    #model.perception.setObservationSpace(map)
    model.load("/tests/sc2/gym_sc2-beacons-simple.lisp")
    myenv = StarCraftEnvironment("SC2MoveToBeacon-v1")
    myexp = Experiment(model, myenv, "CMU StarCraft Beacons",map)
    model.motor.next_action = [-1, -1]
    myexp.start("cmu_beacons") # appends to a log file
    myexp.run(1, 100) #if no cycles provided, env determines end state
    myexp.stop() #closes log file
    outfile = myexp.report("ACTR")
    experiments.append(["ACTR", outfile])
    reporter.add_experiment("ACTR", outfile)

    # test CCM ACT-R Starcraft
    factory = ccm_factory.CcmFactory()
    model = factory.createModel()
    #model.perception = Sc2Perception()
    model.load('metaverse.architectures.actr_ccmsuite.beacon_prods')
    myenv = StarCraftEnvironment("SC2MoveToBeacon-v1")
    map = ['loc_x', 'loc_y']
    myexp = Experiment(model, myenv, "CCM StarCraft Beacons", map)
    model.motor.next_action = [-1,-1]  # TODO: change to random action space
    myexp.start("ccm_beacons") # appends to a log file
    myexp.run(1, 100) #if no cycles provided, env determines end state
    myexp.stop() #closes log file
    outfile = myexp.report("CCM") #TODO: get report type from agent factory
    experiments.append(["CCM", outfile])
    reporter.add_experiment("CCM", outfile)

    # test Soar Starcraft
    factory = soar_factory.SoarFactory()
    model = factory.createModel()
    model.load("starcraft2.soar","starcraft")
    myenv = StarCraftEnvironment("SC2MoveToBeacon-v1")
    myexp = Experiment(model, myenv, "Soar StarCraft Beacons")
    model.motor.next_action = [-1, -1]
    myexp.start("soar_beacons") # appends to a log file
    myexp.run(1, 100) #if no cycles provided, env determines end state
    myexp.stop() #closes log file
    outfile = myexp.report("Soar")
    experiments.append(["Soar", outfile])
    reporter.add_experiment("Soar", outfile)

    with open('last_beacons_experiments.yaml', 'w') as yaml_file:
        yaml.dump(experiments, yaml_file)

    reporter.gen_arch_frames()
    reporter.vision_activation_report(plot="series")
    reporter.motor_activation_report(plot="series")
Beispiel #7
0
def compare_cartpole():


    task = "visual task"
    trials = 1
    steps = 195

    test_iv = "ps"
    iv_start = 0.05
    iv_end = 0.1
    iv_inc = 0.01

    prod_test_config_switch = {
        'ACTR': "/tests/gym/cartpole.lisp",
        'CCM': 'metaverse.architectures.actr_ccmsuite.cartpole_prods',
        'Soar': "/tests/cart-pole/soar_agent.config"
    }

    architectures = ['ACTR', 'CCM', 'Soar']
    architectures1 = ['ACTR']
    architectures2 = ['CCM']
    architectures3 = ['Soar']

    reporter = scribe.Reporter()
    experiments = []

    # for arch in architectures:
    #     factory = get_arch_factory(arch)
    #     model = factory.createModel()
    #     model_file = prod_test_config_switch.get(arch)
    #     model.load(model_file)
    #     #myenv = SimpleEnvironment(task)
    #     myenv = GymEnvironment("CartPole-v0")  # TODO: pass registered gym.env_id??
    #     model.motor.next_action = 0
    #     myexp = Experiment(model, myenv, task, map)
    #     # myexp.set_parameters(test_iv, iv_start, iv_end, iv_inc )
    #     myexp.start(task + "_" + arch)  # appends to a log file
    #     myexp.run(trials, steps)
    #     myexp.stop()  # closes log file
    #     outfile = myexp.report()
    #     experiments.append([arch, outfile])
    #     reporter.add_experiment(arch, outfile)

    # test CMU ACT-R Counting
    factory = cmu_factory.CmuActrFactory()
    model = factory.createModel()
    model.load("/tests/gym/cartpole.lisp")
    map = ['cart_pos', 'cart_vel', 'pole_pos', 'pole_vel']
    myenv = GymEnvironment("CartPole-v0") #TODO: pass registered gym.env_id??
    model.motor.next_action = 0
    myexp = Experiment(model, myenv, "CMU Gym Cartpole", map)
    myexp.start("cmu_cartpole") # appends to a log file
    myexp.run(5, 195) #if no cycles provided, env determines end state
    myexp.stop() #closes log file
    outfile = myexp.report("ACTR")
    experiments.append(["ACTR", outfile])
    reporter.add_experiment("ACTR", outfile)

    # test CMU ACT-R Counting
    factory = ccm_factory.CcmFactory()
    model = factory.createModel()
    model.load('metaverse.architectures.actr_ccmsuite.cartpole_prods')
    myenv = GymEnvironment("CartPole-v0") #TODO: pass registered gym.env_id??
    map = ['cart_pos', 'cart_vel', 'pole_pos', 'pole_vel']
    myexp = Experiment(model, myenv, "CCM Gym Cartpole", map)
    model.motor.next_action = 0 #TODO: change to random action space
    myexp.start("ccm_cartpole") # appends to a log file
    myexp.run(5, 195) #if no cycles provided, env determines end state
    myexp.stop() #closes log file
    outfile = myexp.report("CCM") #TODO: get report type from agent factory
    experiments.append(["CCM", outfile])
    reporter.add_experiment("CCM", outfile)

    # test CMU ACT-R Counting
    factory = soar_factory.SoarFactory()
    model = factory.createModel()
    model.load("cart-pole.soar","cart-pole")
    myenv = GymEnvironment("CartPole-v0") #TODO: pass registered gym.env_id??
    myexp = Experiment(model, myenv, "Soar Gym Cartpole")
    model.perception.create_input_wmes
    myexp.start("soar_cartpole") # appends to a log file
    myexp.run(5, 195) #if no cycles provided, env determines end state
    myexp.stop() #closes log file
    outfile =  myexp.report("Soar")
    experiments.append(["Soar", outfile])
    reporter.add_experiment("Soar", outfile)

    with open('last_cartpole_experiments.yaml', 'w') as yaml_file:
        yaml.dump(experiments, yaml_file)

    reporter.gen_arch_frames()
    reporter.vision_activation_report(plot="series")
    reporter.motor_activation_report(plot="series")
Beispiel #8
0
    def createModel(self, factory: AbstractFactory) -> None:
        """
        The client code works with factories and products only through abstract
        types: AbstractFactory and AbstractProduct. This lets you pass any factory
        or product subclass to the client code without breaking it.
        """
        self.model = factory.createModel()

        working_memory = factory.createWorkingMemory()

        print(f"{working_memory.addWME()}")
        print(f"{working_memory.removeWME(self.model)}", end="")


#*************************** END OF EXAMPLE **************

if __name__ == "__main__":
    """
    The client code can work with any concrete factory class.
    """
    import metaverse.architectures.actr_cmu.cmuactr_factory as cmu
    import metaverse.architectures.soar.soar_factory as soar

    print("Client: Testing client code with the first factory type:")
    ClientTest.createModel(cmu.CmuActrFactory())

    print("\n")

    print("Client: Testing the same client code with the second factory type:")
    ClientTest.create_model(soar.SoarFactory())