Knowledge Base Administration Guide

Python Job JSON Template

The Tunnel also includes a sample Python script, which can render valid Simscope Job JSON objects, using the json builtin library.

Using a JSON library to render

You can use any programming language to generate JSON for Simscope, but you should use a proper json library, rather than just printing out text strings, as JSON objects can be deceptively tricky to render to text.

For example, quotes or newlines inside strings are not trivial to render, whereas a library handle these automatically.

See the "config" example below for a complex JSON value.

Job Template

Edit $SIMSCOPE_TUNNEL/rabbitmq/simscope-job-json.py and run with Python3.

#!/usr/bin/env python3

# Simscope RabbitMQ job JSON example template, in Python.

from datetime import datetime
import json

'''
Create an RFC-3339 timestamp
NOTE: if epoch argument is zero, this will infer a timestamp of now()

Simscope timestamps are documented here:
https://admin-docs.simscope.com/timestamps.html
'''
def timestamp_rfc3339(epoch=0):
    if epoch == 0:
        # No epoch passed in; use now instead
        local_time = datetime.now()
    else:
        local_time = datetime.fromtimestamp(epoch)

    return local_time.astimezone().isoformat()

'''
Create a Simscope job object.
'''
def make_simscope_job():
    job = {
        "jobdir":    "/home/runs/myregr/2/job-3",
        "category":  "sim",
        "build":     "vcs.2core",
        "testgroup": "smoke",
        "host":      "compute-12",
        "config":    "sim +rand +tbuf +seed=1794 LOC=4",
        "seed":      "1794",
        "cycles":    25104,
        "exit_code": 100,
    }

    if True:
        # Example for a multiline simulation command:
        command = '''
export FOO=1
cd /xyz
$FOO ./foo --arg /work/home/regr1 "bah" 99
./baz --blah
'''
        job["config"] = command

    if True:
        # Example for a fail job
        fail_message = '''|t.cpu.core0.fs7| data mismatch filling store buffer: expected=24'h16a7 actual=24'h76a7'''
        job["fail_message"] = fail_message
        job["result"] = "fail"

    else:
        # Example for a pass job
        job["result"] = "pass"

    return job

def job_json():
    job = make_simscope_job()

    # Simscope requires any 2 of these 3 timestamp fields, and it will compute the third automatically
    # > start_time, finish_time, compute_ms

    # Example1: start_time and compute milliseconds (Simscope will infer finish_time)
    if False:
        job["start_time"] = timestamp_rfc3339() # Use now
        job["compute_ms"] = 1234 # NOTE: milliseconds

    # Example2: finish_time and compute millisconds (Simscope will infer start_time)
    if False:
        job["finish_time"] = timestamp_rfc3339(1000000000) # Use a UNIX epoch timestamp
        job_seconds = 10.5
        job["compute_ms"] = int(job_seconds * 1000) # convert runtime from seconds to millisecods

    # Example3: start_time and finish_time (Simscope will infer compute_ms)
    if True:
        job["start_time"] = timestamp_rfc3339()
        job["finish_time"] = timestamp_rfc3339()

    # Print out JSON
    print(json.dumps(job, indent=4))

if __name__ == '__main__':
    job_json()

Example JSON output

Running the example script will generate JSON for a fake job failure.

# Run the sample script
> $SIMSCOPE_TUNNEL/rabbitmq/simscope-job-json.py
{
    "jobdir": "/home/runs/myregr/2/job-3",
    "category": "sim",
    "build": "vcs.2core",
    "testgroup": "smoke",
    "host": "compute-12",
    "config": "\nexport FOO=1\ncd /xyz\n$FOO ./foo --arg /work/home/regr1 \"bah\" 99\n./baz --blah
\n",
    "seed": "1794",
    "cycles": 25104,
    "exit_code": 100,
    "fail_message": "|t.cpu.core0.fs7| data mismatch filling store buffer: expected=24'h16a7 actual=24'h76a7",
    "result": "fail",
    "start_time": "2020-04-15T20:22:32.554343-05:00",
    "finish_time": "2020-04-15T20:22:32.564377-05:00"
}