我们为Python模型铸造模型

acumos-model-runner的Python项目详细描述


acumos python model runner用户指南

Build Status

acumos_model_runner包安装一个命令行工具acumos_model_runner,用于运行由Acumos Python client library创建的模型。

模型运行器提供了用于调用模型方法的http api,以及用于文档的Swagger UI。有关用法的详细信息,请参见教程。

安装

您需要一个python 3.4+环境来安装acumos_model_runner。 您可以使用Anaconda (首选)或pyenv安装和 管理python环境。

acumos_model_runner包可以与pip一起安装:

$ pip install acumos_model_runner

命令行用法

usage: acumos_model_runner [-h][--host HOST][--port PORT][--workers WORKERS][--timeout TIMEOUT][--cors CORS]
                           model_dir

positional arguments:
  model_dir          Directory containing a dumped Acumos Python model

optional arguments:
  -h, --help         show this help message and exit
  --host HOST        The interface to bind to
  --port PORT        The port to bind to
  --workers WORKERS  The number of gunicorn workers to spawn
  --timeout TIMEOUT  Time to wait(seconds) before a frozen worker is
                     restarted
  --cors CORS        Enables CORS if provided. Can be a domain, comma-
                     separated list of domains, or *

acumos python模型运行程序教程

本教程演示如何将acumos python模型运行器与示例模型一起使用。

创建模型

必须首先使用Acumos Python client library定义acumos模型。为了便于说明,下面定义了一个具有确定性方法的简单模型。

# example_model.pyfromcollectionsimportCounterfromacumos.sessionimportAcumosSessionfromacumos.modelingimportModel,List,Dictdefadd(x:int,y:int)->int:'''Adds two numbers'''returnx+ydefcount(strings:List[str])->Dict[str,int]:'''Counts the occurrences of words in `strings`'''returnCounter(strings)model=Model(add=add,count=count)session=AcumosSession()session.dump(model,'example-model','.')

在以下目录中执行example_model.py将得到结果:

.├──example_model.py└──example-model

运行模型

现在可以使用acumos_model_runner命令行工具运行保存的模型。

$ acumos_model_runner example-model/
[2018-08-08 12:16:57 -0400][61113][INFO] Starting gunicorn 19.9.0
[2018-08-08 12:16:57 -0400][61113][INFO] Listening at: http://0.0.0.0:3330 (61113)[2018-08-08 12:16:57 -0400][61113][INFO] Using worker: sync
[2018-08-08 12:16:57 -0400][61151][INFO] Booting worker with pid: 61151

使用模型

模型http api可以通过其生成的swagger ui进行探索。通过导航到web浏览器中的http://localhost:3330,可以访问上面example-model的招摇用户界面。

下面是example-model的招摇用户界面的一些屏幕截图。

模型API

swagger ui列举了模型方法api,以及用于访问模型工件的api。下面,addcount方法对应的api列在methods标记下。

Model APIs

计数方法API

展开count方法的文档将显示有关如何调用api的更多信息。

Model Method

计数方法请求

swagger ui提供了一个输入表单,可用于使用示例数据尝试countapi。

Model Method Request

计数方法响应

来自countapi的响应表明一切都按预期工作!

Model Method Response

acumos python model runner发行说明

v0.2.2

  • 修复了由相对模型目录引起的模型工件资源的404错误
  • 修复了protobuf资源的错误媒体类型

v0.2.1

  • 将Swagger UI从V2升级到V3

v0.2.0

  • 模型转轮api大修
  • 通过Content-TypeAccept头添加了对application/json的支持
  • 添加了自动生成OpenAPI SpecificationSwagger UI
  • 增加了对CORS的支持

v0.1.0

acumos python model runner开发人员指南

测试

我们使用toxpytestflake8的组合来测试 acumos_model_runner。不符合PEP8的代码(E501除外)将是 被认为是失败的测试。您可以使用诸如autopep8之类的工具 按如下方式“清除”代码:

$ pip install autopep8
$ cd python-model-runner
$ autopep8 -r --in-place --ignore E501 acumos_model_runner/ testing/ examples/

直接运行tox:

$ cd python-model-runner
$ tox

您还可以指定要测试的特定毒物环境:

$ tox -e py34  # only test against Python 3.4
$ tox -e flake8  # only lint code

最后,您可以在环境中直接运行pytest (推荐的起始位置)

$ pytest
$ pytest -s   # verbose output

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java将Scanner对象作为构造函数参数传递给UserInterface类   spring未能启动bean“subtocolWebSocketHandler”;嵌套的例外是java。lang.IllegalArgumentException:没有处理程序   Java EE应用程序中后台服务的多线程Java线程(设置守护进程和优先级)?   java Pull to refresh返回列表的第一个位置   无法将comparator类转换为java。可比的   java将json从servlet传递到dojo   JavaHibernate:将子类实例转换为超类实例   java警告调用servlet类时非法反射访问   java静态变量值   java@Entity和@embeddeble之间有什么区别   java将作业配置导入公共作业配置类(注释配置)   sql公共表表达式(以values语句开头)在java中给出错误   java在ImageJ中使用ImageProcessor   java PostgreSQL executeBatch()会随着时间的推移而变慢   java在安卓中以表格形式排列sqllite表数据?   java中SVG的swing定制呈现   java删除与另一个实体映射的实体   java何时/如何添加ListView适配器,使用back按钮恢复它?(片段)   java为什么IBinder和Binder之间的类型转换不是非法的?   java在方法参数列表中使用ArrayList或List