Package: acumos-model-runner
Acumos Python Model Runner User GuideTheacumos_model_runnerpackage installs a command line toolacumos_model_runnerfor running models created by theAcumos Python client library.The model runner provides an HTTP API for invoking model methods, as well as aSwagger UIfor documentation. See the tutorial for more information on usage.InstallationYou will need a Python 3.4+ environment in order to installacumos_model_runner.
You can useAnaconda(preferred) orpyenvto install and
manage Python environments.Theacumos_model_runnerpackage can be installed with pip:$pipinstallacumos_model_runnerCommand Line Usageusage:acumos_model_runner[-h][--hostHOST][--portPORT][--workersWORKERS][--timeoutTIMEOUT][--corsCORS]model_dirpositionalarguments:model_dirDirectorycontainingadumpedAcumosPythonmodeloptionalarguments:-h,--helpshowthishelpmessageandexit--hostHOSTTheinterfacetobindto--portPORTTheporttobindto--workersWORKERSThenumberofgunicornworkerstospawn--timeoutTIMEOUTTimetowait(seconds)beforeafrozenworkerisrestarted--corsCORSEnablesCORSifprovided.Canbeadomain,comma-separatedlistofdomains,or*Acumos Python Model Runner TutorialThis tutorial demonstrates how to use the Acumos Python model runner with an example model.Creating A ModelAn Acumos model must first be defined using theAcumos Python client library. For illustrative purposes, a simple model with deterministic methods is defined below.# 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','.')Executingexample_model.pyresults in the following directory:.├──example_model.py└──example-modelRunning A ModelNow theacumos_model_runnercommand line tool can be used to run the saved model.$acumos_model_runnerexample-model/[2018-08-0812:16:57-0400][61113][INFO]Startinggunicorn19.9.0[2018-08-0812:16:57-0400][61113][INFO]Listeningat:http://0.0.0.0:3330(61113)[2018-08-0812:16:57-0400][61113][INFO]Usingworker:sync[2018-08-0812:16:57-0400][61151][INFO]Bootingworkerwithpid:61151Using A ModelThe model HTTP API can be explored via its generated Swagger UI. The Swagger UI ofexample-modelabove can be accessed by navigating tohttp://localhost:3330in your web browser.Below are some screenshots of the Swagger UI forexample-model.Model APIsThe Swagger UI enumerates model method APIs, as well as APIs for accessing model artifacts. Below, the APIs corresponding to theaddandcountmethods are listed under themethodstag.Count Method APIExpanding the documentation for thecountmethod reveals more information on how to invoke the API.Count Method RequestThe Swagger UI provides an input form that can be used to try out thecountAPI with sample data.Count Method ResponseThe response from thecountAPI shows that everything is working as expected!Acumos Python Model Runner Release Notesv0.2.25, 04 June 2020Fix backward compatibility issue with old modelsACUMOS-4164v0.2.24, 15 May 2020Fix OpenAPI spec generation for empty inputsACUMOS-4010Allow the model runner to use raw data typesACUMOS-3956Receive the licence profile from the running micro-serviceACUMOS-3161v0.2.3, 23 January 2020larkparser lark-parser<0.8.0 pinning to prevent errorFixing issue with using 0.6.0 model metadata schema - works with model metadata versions <0.6.0 and 0.6.0python removing 3.4 supportv0.2.2Fixed 404 bug for model artifact resources caused by relative model directoryFixed incorrect media type for protobuf resourcev0.2.1Upgraded Swagger UI from v2 to v3v0.2.0Overhaul of model runner APIAdded support forapplication/jsonviaContent-TypeandAcceptheadersAdded automatic generation ofOpenAPI SpecificationandSwagger UIAdded support for CORSv0.1.0Model runner implementation split off fromAcumos Python clientprojectAcumos Python Model Runner Developer GuideTestingWe use a combination oftox,pytest, andflake8to testacumos_model_runner. Code which is not PEP8 compliant (aside from E501) will be
considered a failing test. You can use tools likeautopep8to
“clean” your code as follows:$pipinstallautopep8$cdpython-model-runner$autopep8-r--in-place--ignoreE501acumos_model_runner/testing/examples/Run tox directly:$cdpython-model-runner$toxYou can also specify certain tox environments to test:$tox-epy34# only test against Python 3.4$tox-eflake8# only lint codeAnd finally, you can run pytest directly in your environment(recommended starting place):$pytest$pytest-s# verbose output