示例#1
0
文件: gates.py 项目: oidelima/ppo
def cli():
    # Training settings
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument(
        "--batch-size",
        type=int,
        default=64,
        metavar="N",
        help="input batch size for training",
    )
    parser.add_argument("--lr",
                        type=float,
                        default=0.01,
                        metavar="LR",
                        help="learning rate ")
    parser.add_argument("--no-cuda",
                        action="store_true",
                        default=False,
                        help="disables CUDA training")
    parser.add_argument("--seed",
                        type=int,
                        default=0,
                        metavar="S",
                        help="random seed ")
    parser.add_argument(
        "--save-interval",
        type=int,
        default=100,
        metavar="N",
        help="how many batches to wait before logging training status",
    )
    parser.add_argument(
        "--log-interval",
        type=int,
        default=10,
        metavar="N",
        help="how many batches to wait before logging training status",
    )
    parser.add_argument("--log-dir",
                        default="/tmp/mnist",
                        metavar="N",
                        help="")
    parser.add_argument("--run-id", default="", metavar="N", help="")
    parser.add_argument("--load-path", type=Path)
    dataset_parser = parser.add_argument_group("dataset_args")
    dataset_parser.add_argument("--lower-level-config",
                                type=Path,
                                required=True)
    dataset_parser.add_argument("--lower-level-load-path",
                                type=Path,
                                required=True)
    ppo.control_flow.multi_step.env.build_parser(
        dataset_parser,
        default_max_while_loops=2,
        default_max_world_resamples=0,
        default_min_lines=1,
        default_max_lines=20,
        default_time_to_waste=0,
    )
    network_parser = parser.add_argument_group("network_args")
    network_parser.add_argument(
        f"--pool-type",
        choices=("avg", "max", None),
        type=lambda s: None if s == "None" else s,
    )
    network_parser.add_argument(f"--concat", action="store_true")
    network_parser.add_argument(f"--line-hidden-size", type=int, required=True)
    network_parser.add_argument(f"--lower-hidden-size",
                                type=int,
                                required=True)
    for i in range(MAX_LAYERS):
        network_parser.add_argument(f"--conv-layer{i}",
                                    dest="conv_layers",
                                    action="append",
                                    type=maybe_int)
        for mod in ("conv", "pool"):
            for component in ("kernel", "stride"):
                network_parser.add_argument(
                    f"--{mod}-{component}{i}",
                    dest=f"{mod}_{component}s",
                    action="append",
                    type=maybe_int,
                )
    main(**hierarchical_parse_args(parser))
示例#2
0
文件: env.py 项目: oidelima/ppo
    ]
    mapping = dict(w=(-1, 0),
                   s=(1, 0),
                   a=(0, -1),
                   d=(0, 1),
                   m=("mine"),
                   l=("sell"),
                   g=("goto"))
    mapping2 = {}
    for k, v in mapping.items():
        try:
            mapping2[k] = actions.index(v)
        except ValueError:
            pass

    def action_fn(string):
        action = mapping2.get(string, None)
        if action is None:
            return None
        return np.array(Action(upper=0, lower=action, delta=0, dg=0, ptr=0))

    keyboard_control.run(env, action_fn=action_fn)


if __name__ == "__main__":
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument("--seed", default=0, type=int)
    main(Env(**hierarchical_parse_args(build_parser(parser))))
示例#3
0
def cli():
    # Training settings
    parser = argparse.ArgumentParser(description="PyTorch MNIST Example")
    parser.add_argument(
        "--batch-size",
        type=int,
        default=64,
        metavar="N",
        help="input batch size for training (default: 64)",
    )
    parser.add_argument("--alpha", type=float, metavar="N", required=True)
    parser.add_argument("--simple-dataset-size", type=int, metavar="N")
    parser.add_argument("--num-iterations", type=int, metavar="N")
    parser.add_argument(
        "--classifier-epochs",
        type=int,
        default=20,
        metavar="N",
        help="number of epochs to train (default: 10)",
    )
    parser.add_argument(
        "--discriminator-epochs",
        type=int,
        metavar="N",
        help="number of epochs to train (default: 10)",
    )
    parser.add_argument("--aux-coef", type=float, default=0.1, metavar="N")
    discriminator_parser = parser.add_argument_group("discriminator_args")
    discriminator_parser.add_argument(
        "--hidden-size", type=int, default=512, metavar="N"
    )
    discriminator_parser.add_argument("--num-hidden", type=int, default=1, metavar="N")
    discriminator_parser.add_argument(
        "--activation", type=lambda s: eval(f"nn.{s}"), default=nn.ReLU(), metavar="N"
    )
    classifier_optimizer_parser = parser.add_argument_group("classifier_optimizer_args")
    classifier_optimizer_parser.add_argument(
        "--classifier-lr",
        type=float,
        default=0.01,
        metavar="LR",
        help="learning rate (default: 0.01)",
    )
    classifier_optimizer_parser.add_argument(
        "--classifier-momentum",
        type=float,
        default=0.5,
        metavar="M",
        help="SGD momentum (default: 0.5)",
    )
    discriminator_optimizer_parser = parser.add_argument_group(
        "discriminator_optimizer_args"
    )
    discriminator_optimizer_parser.add_argument(
        "--discriminator-lr",
        type=float,
        default=0.01,
        metavar="LR",
        help="learning rate (default: 0.01)",
    )
    discriminator_optimizer_parser.add_argument(
        "--discriminator-momentum",
        type=float,
        default=0.5,
        metavar="M",
        help="SGD momentum (default: 0.5)",
    )
    parser.add_argument("--random-labels", action="store_true")
    parser.add_argument(
        "--no-cuda", action="store_true", default=False, help="disables CUDA training"
    )
    parser.add_argument(
        "--seed", type=int, default=1, metavar="S", help="random seed (default: 1)"
    )
    parser.add_argument(
        "--log-interval",
        type=int,
        default=10,
        metavar="N",
        help="how many batches to wait before logging training status",
    )
    parser.add_argument("--log-dir", default="/tmp/mnist", metavar="N")
    parser.add_argument("--run-id", metavar="N", default="")
    parser.add_argument("--classifier-load-path")
    parser.add_argument("--discriminator-load-path")
    main(**hierarchical_parse_args(parser))
示例#4
0
文件: main.py 项目: oidelima/ppo
    parsers.agent.add_argument("--transformer", action="store_true")
    parsers.agent.add_argument("--fuzz", action="store_true")
    parsers.agent.add_argument(
        "--critic-type",
        choices=["z", "z3", "h1", "combined", "multi-layer"],
        required=True,
    )
    parsers.agent.add_argument("--hidden2", type=int, required=True)
    parsers.agent.add_argument("--conv-hidden-size", type=int, required=True)
    parsers.agent.add_argument("--task-embed-size", type=int, required=True)
    parsers.agent.add_argument("--lower-embed-size", type=int, required=True)
    parsers.agent.add_argument("--gate-hidden-size", type=int, required=True)
    parsers.agent.add_argument("--gate-stride", type=int, required=True)
    parsers.agent.add_argument("--num-encoding-layers",
                               type=int,
                               required=True)
    parsers.agent.add_argument("--num-conv-layers", type=int, required=True)
    parsers.agent.add_argument("--num-edges", type=int, required=True)
    parsers.agent.add_argument("--gate-coef", type=float, required=True)
    parsers.agent.add_argument("--no-op-coef", type=float, required=True)
    parsers.agent.add_argument("--gate-conv-kernel-size",
                               type=int,
                               required=True)
    parsers.agent.add_argument("--kernel-size", type=int, required=True)
    parsers.agent.add_argument("--stride", type=int, required=True)
    return parser


if __name__ == "__main__":
    main(**hierarchical_parse_args(control_flow_args()))
示例#5
0
文件: env.py 项目: oidelima/ppo
    p.add_argument("--reject-while-prob", type=float, required=True)
    p.add_argument(
        "--max-world-resamples",
        type=int,
        required=default_max_world_resamples is None,
        default=default_max_world_resamples,
    )
    p.add_argument(
        "--max-while-loops",
        type=int,
        required=default_max_while_loops is None,
        default=default_max_while_loops,
    )
    p.add_argument("--world-size", type=int, required=True)
    p.add_argument("--term-on",
                   nargs="+",
                   choices=[Env.sell, Env.mine, Env.goto],
                   required=True)


if __name__ == "__main__":
    import argparse

    parser = argparse.ArgumentParser()
    build_parser(parser)
    parser.add_argument("--seed", default=0, type=int)
    ppo.control_flow.env.main(
        Env(rank=0,
            lower_level="train-alone",
            **hierarchical_parse_args(parser)))
示例#6
0
def cli():
    # Training settings
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument(
        "--batch-size",
        type=int,
        default=64,
        metavar="N",
        help="input batch size for training",
    )
    parser.add_argument("--lr",
                        type=float,
                        default=0.01,
                        metavar="LR",
                        help="learning rate ")
    parser.add_argument("--no-cuda",
                        action="store_true",
                        default=False,
                        help="disables CUDA training")
    parser.add_argument("--seed",
                        type=int,
                        default=0,
                        metavar="S",
                        help="random seed ")
    parser.add_argument(
        "--save-interval",
        type=int,
        default=100,
        metavar="N",
        help="how many batches to wait before logging training status",
    )
    parser.add_argument(
        "--log-interval",
        type=int,
        default=10,
        metavar="N",
        help="how many batches to wait before logging training status",
    )
    parser.add_argument("--curriculum-threshold",
                        type=float,
                        default=5e-4,
                        help=" ")
    parser.add_argument("--aux-coef", type=float, default=0.01, help=" ")
    parser.add_argument("--max-curriculum", type=int, default=5)
    parser.add_argument("--log-dir",
                        default="/tmp/mnist",
                        metavar="N",
                        help="")
    parser.add_argument("--run-id", default="", metavar="N", help="")
    parser.add_argument("--baseline", action="store_true")
    four_rooms_parser = parser.add_argument_group("four_rooms_args")
    # four_rooms_parser.add_argument("--room-size", type=int, default=128)
    four_rooms_parser.add_argument("--distance",
                                   type=float,
                                   default=8,
                                   help="")
    four_rooms_parser.add_argument("--len-dataset", type=int, help="")
    baseline_parser = parser.add_argument_group("baseline_args")
    baseline_parser.add_argument("--hidden-size", type=int, default=64)
    deep_hierarchical_parser = parser.add_argument_group(
        "deep_hierarchical_args")
    deep_hierarchical_parser.add_argument("--arity", type=int, default=2)
    deep_hierarchical_parser.add_argument("--num-gru-layers",
                                          type=int,
                                          default=2)
    main(**hierarchical_parse_args(parser))
示例#7
0
            # if self.sim.model.joint_names[self.viewer.active_joint] == 'l_proximal_joint':
            #     if action[self.sim.model.get_]
            print('delta =', self.viewer.delta)
            print('action =', action)

        s, r, t, i = self.step(action * action_scale)
        return t


def main(env_args):
    env = ControlHSREnv(**env_args)
    done = False

    action = np.zeros(space_to_size(env.action_space))
    action[0] = 1

    while True:
        if done:
            env.reset()
        done = env.control_agent()


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    wrapper_parser = parser.add_argument_group('wrapper_args')
    env_parser = parser.add_argument_group('env_args')
    hsr.util.add_env_args(env_parser)
    hsr.util.add_wrapper_args(wrapper_parser)
    args = hierarchical_parse_args(parser)
    main_ = hsr.util.env_wrapper(main)(**args)