[framework] debuging
debug 工具
本打算使用 pdb 逐步运行
python -m pdb actor.py --config examples/ppo/cartpole_actor.yaml
然而,pdb 并不支持多线程,而且效率贼低。因此换用 vscode,支持多线程而且效率超高!
只需编写 launch.json 即可!
"stopOnEntry": true
程序运行时自动在第一条语句停下"args": ["--config", "examples/ppo/pong_actor.yaml"]
指定参数"env": {"CUDA_VISIBLE_DEVICES":"0,1"}
指定 gpu
{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "Python: Current File","type": "python","request": "launch","program": "${file}","console": "integratedTerminal","stopOnEntry": true,"env": {"CUDA_VISIBLE_DEVICES":"0,1"},"args": ["--config", "examples/ppo/pong_actor.yaml"]}]
}
相关库
argparse
https://docs.python.org/3.7/library/argparse.html
一般是 type
表示 --config
后面输入的类型
store_true
表示 --use_gpu
后面不需要输入,默认是 False。
from argparse import ArgumentParserparser = ArgumentParser()
parser.add_argument('--config', type=str, default=None, help='The YAML configuration file')
parser.add_argument('--use_gpu', action='store_true', help='Use GPU to sample every action')def main():args, unknown_args = parser.parse_known_args()print(args.config)print(args.use_gpu)if __name__ == '__main__':main()
输入命令
python help.py --config "test" --use_gpu
pickle
实现了用于序列化和反序列化Python对象结构的二进制协议。可以序列化自定义对象。
pickle.dump(obj, file, [protocol])
序列化对象
pickle.load(file)
反序列化对象
typing
- 类型检查,防止运行时出现参数和返回值类型不符合。
- 作为开发文档附加说明,方便使用者调用时传入和返回参数类型。
- 该模块加入后并不会影响程序的运行,不会报正式的错误,只有提醒。
注意:typing模块只有在python3.5以上的版本中才可以使用,pycharm目前支持typing检查
from typing import List, Tuple, Dict
def add(a:int, string:str, f:float, b:bool) -> Tuple[List, Tuple, Dict, bool]:list1 = list(range(a))tup = (string, string, string)d = {"a":f}bl = breturn list1, tup, d,bl
print(add(5,"hhhh", 2.3, False))
# 结果:([0, 1, 2, 3, 4], ('hhhh', 'hhhh', 'hhhh'), {'a': 2.3}, False)
zmq
- 创建和销毁套接字:zmq_socket(), zmq_close()
- 配置和读取套接字选项:zmq_setsockopt(), zmq_getsockopt()
- 为套接字建立连接:zmq_bind(), zmq_connect()
- 发送和接收消息:zmq_send(), zmq_recv()
设置非阻塞 socket.recv(flags=zmq.NOBLOCK)。zmq.ZMQError
可以替换为 zmq.Again
。
import zmq
import timecontext = zmq.Context()
receiver = context.socket(zmq.PULL)
receiver.connect("tcp://localhost:5557")
subscriber = context.socket(zmq.SUB)
subscriber.connect("tcp://localhost:5556")
subscriber.setsockopt(zmq.SUBSCRIBE, b"10001")while True:while True:try:msg = receiver.recv(zmq.NOBLOCK)except zmq.ZMQError:breakwhile True:try:msg = subscriber.recv(zmq.NOBLOCK)except zmq.ZMQError:breaktime.sleep(1)
PUB-SUB
- 使用 SUB 设置一个订阅时,必须使用
zmq_setsockopt()
对消息进行过滤。setsockopt 的详细解释,可参考http://api.zeromq.org/3-2:zmq-setsockopt。 - PUB 和 SUB 谁 bind 谁 connect 并无严格要求(虽本质并无区别),但仍建议 PUB 使用 bind,SUB 使用 connect
- 也就是如果 push 的 send 不能 send 出去,就会出现一直阻塞的情况,而 pull 的 recv 也是会一直等待数据的到达,否则无法执行后面的函数。https://blog.csdn.net/weixin_42066185/article/details/103015332
REQ(client)-REP(server)
- 客户端必要先发送消息,在接收消息;服务端必须先进行接收客户端发送过来的消息,再发送应答给客户端。
- 服务端和客户端谁先启动,效果都是一样的。
- 服务端在收到消息之前,会一直阻塞,等待客户端连上来。
- 客户端使用 connect,服务端使用 bind。
multiprocessing
https://docs.python.org/3.7/library/multiprocessing.html
Process
用于创建进程模块
Array & Value
不同的 Python 进程之间创建共享的内存区域。Value 是共享值(单个数值),Array 是共享数组。
m = Array('i',3)
表示开辟 3 个空间,且均为整型 i
,其实就是一个列表
m = Array('i',[1,2,3,4,5])
表示开辟 5 个空间,同时存入列表中的元素
Condition
进程同步互斥
import multiprocessing,timedef A(cond):name=multiprocessing.current_process().nameprint(f"starting,{name}")with cond:print("%s is done and next is ready"%name)cond.notify_all()def B(cond):name=multiprocessing.current_process().nameprint(f"starting{name}")with cond:cond.wait()print("%s running..."%name)cond=multiprocessing.Condition()
m=multiprocessing.Process(target=A,args=(cond,))
n=[multiprocessing.Process(target=B,name="Process2[%d]"%i,args=(cond,)) for i in range(1,3)]
for i in n:i.start()time.sleep(2)m.start()
m.join()
for i in n:i.join()
from itertools import count
从 10 开始无限循环
for i in count(10):
// 10 11 12 13 ...
from pyarrow import serialize
测试记录
我认为框架的核心是
sizeof(data)learntime\frac{sizeof(data)}{learntime}learntimesizeof(data)
及单位时间内训练的数据量大小,该值越大,速度越快。
actor | pool | batch | send_fps | wait_time | sample_time | learn_time | all_time | learn_rate |
---|---|---|---|---|---|---|---|---|
60 | 60* | 60* | 560~580 | 0.1~0.3 | 1.8 | 1.5 | 3.5 | 3.3e4 |
60 | 90* | 60* | 400~430 | 1e-5 | 3.2 | 1.5 | 4.7 | 2.6e4 |
40 | 40* | 40* | 590~610 | 1.26 | 0.87 | 1.37 | 3.5 | 2.4e4 |
20 | 20* | 20* | 620 | 2 | 0.26 | 1 | 3.2 | 1.2e4 |
20 | 30* | 20* | 620 | 1.8 | 0.48 | 1 | 3.2 | 1.2e4 |
20 | 40* | 20* | 620 | 1.6 | 0.56 | 1 | 3.2 | 1.2e4 |
20 | 50* | 20* | 620 | 1.6 | 0.64 | 1 | 3.2 | 1.2e4 |
20 | 60* | 20* | 620 | 1.25 | 0.75 | 1 | 3.2 | 1.2e4 |
20 | 70* | 20* | 620 | 1.25 | 0.82 | 1 | 3.2 | 1.2e4 |
20 | 80* | 20* | 620 | 1.25 | 0.93 | 1 | 3.2 | 1.2e4 |
20 | 90* | 20* | 620 | 1.25 | 1 | 1 | 3.2 | 1.2e4 |
40 | 40* | 40* | 620 | 1.25 | 0.87 | 1.37 | 3.2 | 1.2e4 |
40 | 50* | 40* | 620 | 1.25 | 1.32 | 1.37 | 3.2 | 1.2e4 |
40 | 60* | 40* | 620 | 1.25 | 1.51 | 1.37 | 3.2 | 1.2e4 |
40 | 70* | 40* | 620 | 1.25 | 1.73 | 1.37 | 3.2 | 1.2e4 |
40 | 80* | 40* | 620 | 1.25 | 1.90 | 1.37 | 3.2 | 1.2e4 |
40 | 90* | 40* | 620 | 1.25 | 2.12 | 1.37 | 3.2 | 1.2e4 |
60 | 60* | 60* | 620 | 1.25 | 1.80 | 1.37 | 3.2 | 1.2e4 |
60 | 70* | 60* | 620 | 1.25 | 2.56 | 1.37 | 3.2 | 1.2e4 |
60 | 80* | 60* | 620 | 1.25 | 2.80 | 1.37 | 3.2 | 1.2e4 |
60 | 90* | 60* | 620 | 1.25 | 3.3 | 1.37 | 3.2 | 1.2e4 |
[framework] debuging相关推荐
- Tengine Framework基础
Tengine Framework基础 最受开发者喜爱的边缘AI计算框架 Tengine是OPEN AI LAB推出的自主知识产权的边缘AI计算框架,致力于解决AIoT产业链碎片化问题,加速AI产业化 ...
- EF-Entity Framework 相关技术点收集贴
不定期.偶尔.添加更新 在网络上看到或者自己开发过程中碰到的EF-Entity Framework相关技术点 本文地址:http://www.cnblogs.com/vnii/archive/2012 ...
- Qt Installer Framework实战
Qt Installer Framework是Qt发布的安装程序支持框架,只需要简单的配置就可以生成安装文件,同时可以通过javascript脚本来定制安装过程. 目录结构 config packag ...
- 在虚拟机中 windows 2003 装.net framework 3.5 出现问题.
错误信息: [11/27/09,08:52:50] Microsoft .NET Framework 2.0a: [2] Error: Installation failed for componen ...
- .Net Framework 3.0 概述
Microsoft .NET Framework 3.0, the managed programming model for Microsoft® Windows®, includes the .N ...
- MIS开发中.net Framework的打印功能
Microsoft .net Framework的打印功能都以组件的方式提供,为程序员提供了很大的方便,但是这几个组件的使用还是很复杂的,有必要解释一下. 打印操作通常包括以下四个功能 1 打印设置 ...
- python导入matplotlib出错_解决导入matplotlib的RuntimeError: Python is not installed as a framework....
import matplotlib.pyplot as plt 报错: RuntimeError: Python is not installed as a framework. The Mac OS ...
- ios Standard Framework和Umbrella Framework
Standard Framework:标准库,通过引用对应的header文件而不是引用master header 文件来引用类(也可以通过引用Master Header file来引用需要使用的类), ...
- ios .framework动态库重签名
真机上运行.framework时,如果报 dyld'dyld_fatal_error:dyld: Library not loaded: @rpath/XX.framework/XXReference ...
最新文章
- c++学习笔记内联函数,函数重载,默认参数
- 感知器调参之梯度下降法
- 文巾解题 面试题 01.01. 判定字符是否唯一
- 开头和结尾标记 在不同系统_文本标记的宝藏平台——Docusky
- 数字类型的不正确转换漏洞
- .net core 正则表达式 获取 等号后面的值_Python3 正则表达式
- Linux 离奇磁盘爆满,如何解决? | 原力计划
- 微信小程序(2)--下拉刷新和上拉加载更多
- 解决自定义UITableViewCell在浏览中出现数据行重复的问题
- 机器学习基础(八)——感知机(iterative optimization)
- oracle xsql 详解(一)
- 聊聊调度框架,K8S、Mesos、Swarm 一个都不能少
- Windows环境下安装python+tensorflow
- 两个摄像头合成一路_64个高空抛物摄像头安装到位 同德社区居民双手点赞
- 低频量化之可转债埋伏配债、埋伏埋伏配债和配债选股策略
- python12306抢票_Python 版 12306 抢票神器
- 计算机专业专业导论论文题目,计算机专业导论论文.doc
- 红米4x android7.0,效率太惊人 红米Note 4X也迎来Android 7.0升级
- 基于Xilinx Kintex-7 FPGA K7 XC7K325T PCIeX8 四路光纤卡226
- 手机实现远程开机功能
热门文章
- linux centos7.9中安装docker的3种方式-图解
- 创建django项目,8月版本
- python 缺省参数_week04_python函数缺省值
- python怎么取出数字,如何在python中取数字的第n个数字
- 路由器下一跳地址怎么判断_路由器的功能及工作原理
- Numpy高级操作大全!!!
- NumPy进阶教程——超详细
- 使用FFTW的fftw_plan_dft_c2r_1d()由于未归一化结果错误的解决方案
- PostgreSQL Pattern Matching
- MQTT.fx客户端MQTT接入阿里云物联网平台,登录、订阅、发布消息