Skip to main content

Simpl Modelservice

Python Library to implement Simulations, built on Crossbar.io and Django.

Build Status

Installation

Django 2.2

$ pip install simpl-modelservice

Django 1.11

$ pip install "simpl-modelservice<0.8.0"

Setup development environment

$ git clone git@github.com:simplworld/simpl-modelservice.git
$ cd simpl-modelservice
$ mkvirtualenv simpl-modelservice
$ pip install -r dev-requirements.txt
$ pip install -e .

Run tests

$ python runtests.py

Development versioning

Install bumpversion:

$ pip install bumpversion

Then, to release a new version, increment the version number with:

$ bumpversion patch

Then push to the repo:

$ git push && git push --tags

View current WAMP subscriptions and registrations

Point your browser to http://localhost:8080/monitor and open your javascript console

How to run a modelservice as two separate processes

It's sometimes useful to run crossbar and your own model code as separate processes. By default, run_modelservice runs crossbar configured to kick off the sub-process run_guest. You can change this by doing these 3 simple steps:

  1. Get a copy of the currently in use crossbar configuration by running ./manage.py run_modelservice --print-config. This will print the generated configuration file and then run normally. Simply cut-n-paste the configuration which will be a large JSON blob just before the usual Crossbar log messages.

  2. Edit the configuration to remove the entire {"type": "guest", ...} stanza, saved to a file.

  3. Run each piece separately. If we saved our configuration into config.json in the current directly this would look like:

     ./manage.py run_modelservice --config=./config.json --loglevel info --settings=simpl-calc.settings
    

    for the crossbar service and then:

     HOSTNAME=localhost PORT=8080 ./manage.py run_guest --settings=simpl-calc.settings
    

    for the modelservice itself.

Environment variables

  • GUEST_LOGLEVEL adjust guest process logging, defaults to info
  • CROSSBAR_LOGLEVEL adjust crossbar process logging, defaults to info

Profiling

Writing tasks

The profiler will run any method that starts with profile_ one or more times against a different number of workers.

Keep in mind that, unlike unit tests, profile tasks are not isolated.

Measuring

The modelservice.utils.instruments contains classes for measuring execution times. Check the module's docstrings for details.

Collecting results

You can collect the result of the task by calling the .publish_stat() method:

    async def profile_random(self):
        with Timer() as timer:
            some_value = random.random()
        self.publish_stat('<unique stat name>', timer.elapsed, fmt='Average result was {stats.mean:.3f}')

The fmt string will receive an instruments.StatAggregator instance called stats. This object will collect the value from all workers that ran the task and will provide the following properties:

  • .min: The lowest collected value
  • .max: The highest collected value
  • .total: The sum of the collected values
  • .count: The number of collected values

Additionally, functions from the statistics module are aliased as properties (ie: .mean, .stdev, etc.).

Running the profiler anonymously

  1. Run the simpl-games-api server.
  2. From a model service directory, run its server.
  3. From the same model service directory, call profile.sh. You can use profile.sh -h for a list of options.

Some example anonymous profiling tasks are defined in modelservice/profiles. These tasks are run unless you use the -m option to specify a different module path.

To run from a model service directory when logged into an AWS instance, call aws_profile.sh. You can use aws_profile.sh -h for a list of options.

Running the profiler with users

You can have workers that publish and call on WAMP as specific users. Using the .call() or .publish() methods, it can call or publish as the user associated with that worker.

You have the profiler spawn workers as specific users by passing a file with their emails using the -u option.

You will also need to use the -m option to specify your task's module path (e.g my_task_module_path).

Assuming you have a file called myusers.txt with the following content:

s1@mysim.edu
s2@mysim.edu
s3@mysim.edu

You can then call:

$ profile.sh -m my_task_module_path -u myusers.txt

This will spawn 3 workers, each one set up to .call and .publish as one of those users.

To run from a model service directory when logged into an AWS instance, call:

$ aws_profile.sh -m my_task_module_path -u myusers.txt

Both profile.sh and aws_profile.sh invoke the profile management command.

Copyright © 2018 The Wharton School,  The University of Pennsylvania 

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Release files for simpl-modelservice 0.10.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simpl-modelservice 0.10.1
File Size Uploaded
simpl-modelservice-0.10.1.tar.gz 144.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simpl-modelservice 0.10.1
File Interpreter ABI Platform
simpl_modelservice-0.10.1-py3-none-any.whl Python 3 none any Details

Total release size: 304.2 kB

Release files / simpl-modelservice-0.10.1.tar.gz

Download URL simpl-modelservice-0.10.1.tar.gz
Size 144.2 kB
Tags Source
SHA-256 checksum
How to use checksums
53ba93c44b49457461aa55ef4fe4e79587f895df0a6eb04aff3541b7bd8d5eb3
BLAKE2b-256 checksum
How to use checksums
de6fd3ea34063bbf29c1ba058bc1a3b4c36fa1bcb760db5382545af95e88ef55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.6.5

Release files / simpl_modelservice-0.10.1-py3-none-any.whl

Download URL simpl_modelservice-0.10.1-py3-none-any.whl
Size 160.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b197e1c9518b54ab336eaedda8d7da58a902e7fb078f8ba78ad3cf0684b6d9a7
BLAKE2b-256 checksum
How to use checksums
eb87ed08acf762991c7845d66dd544b04a901036800171cb00e27f01f83986cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.6.5

Release history Release notifications | RSS feed

This release

0.10.1 This release

2 release files

0.10.0

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.0

2 release files

0.7.15

2 release files

0.7.13

2 release files

0.7.12

2 release files

0.7.10

2 release files

0.7.9

2 release files

0.7.7

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page