Skip to main content

Introduction

Documentation Status Licence

PyUPPAAL is a research tool that helps you do most things that you can do with UPPAAL GUI. Basic coding flow is:

  1. load a .xml model, just like you open a model in UPPAAL GUI;
  2. set the query, just like you edit the queries in UPPAAL GUI;
  3. verify a model with the query and options (e.g., shortest path), just like you click the "Verify" button in UPPAAL GUI.

In addition to the above functions, you can also

Demos are provided to help understand how PyUPPAAL can contribute to scientific research:

  1. Demo - PipeNet (find_all_patterns)
  2. Demo - Pedestrian (find_all_patterns)
  3. Demo - Fault Diagnosis (fault_diagnosability, fault_identification)
  4. Demo - Scripted Model Construction (pyuppaal.nta)
  5. Demo - Trace Parser (pyuppaal.SimTrace)

Quickstart

1. Installation

pip install pyuppaal

2. Before Coding

Remember to set the verifyta_path in your first line of code.

pyuppaal.set_verifyta_path("your/path/to/verifyta.exe")

3. Verify a Model

Lets take the following model P1 with query A[] not deadlock as the example. You can download this file via [this_link].

import pyuppaal as pyu

VERIFYTA_PATH = "uppaal\\uppaal64-4.1.26\\bin-Windows\\verifyta.exe"
# set verifyta path
pyu.set_verifyta_path(VERIFYTA_PATH)

demo_path = 'demo.xml'

# verify and return the terminal result
terminal_res = pyu.Verifyta().verify(demo_path)
print(terminal_res)

# another method
umod = pyu.UModel(demo_path)
umod_res = umod.verify()

assert terminal_res == umod_res
Writing example trace to demo-1.xtr
Options for the verification:
  Generating shortest trace
  Search order is breadth first
  Using conservative space optimisation
  Seed is 1705043788
  State space representation uses minimal constraint systems

Verifying formula 1 at /nta/queries/query[1]/formula
 -- Formula is satisfied.

You can also edit the model and get all possible patterns that satisfy the query.

The red line is pattern1, and the green line is pattern2.

# save as a new file because find_all_patterns will modify the file
umod = umod.save_as('demo_new.xml')
# set the queries of the xml model.
umod.queries ='E<> P1.pass'

print("broadcast channels: ", umod.broadcast_chan)
print("queries: ", umod.queries)
# get one trace
print('\n', umod.easy_verify())
# find all patterns
all_patterns = umod.find_all_patterns()
for i, pattern in enumerate(all_patterns):
    print(f'pattern{i+1}: ', pattern.untime_pattern)
broadcast channels:  ['b', 'a', 'd', 'c']
queries:  ['E<> P1.pass']

 State [0]: ['P1.start']
global_variables [0]: None
Clock_constraints [0]: [t(0) - P1.t ≤ 0; P1.t - t(0) ≤ 10; ]
transitions [0]: a: P1 -> []; P1.start -> P1._id2; 
-----------------------------------
State [1]: ['P1._id2']
global_variables [1]: None
Clock_constraints [1]: [t(0) - P1.t ≤ -10; ]
transitions [1]: b: P1 -> []; P1._id2 -> P1.pass; 
-----------------------------------
State [2]: ['P1.pass']
global_variables [2]: None
Clock_constraints [2]: [t(0) - P1.t ≤ -10; ]

pattern1:  ['a', 'b']
pattern2:  ['c', 'd']

4. Verify with Multi-threads

import pyuppaal as pyu
import time
import multiprocessing.dummy as mp

VERIFYTA_PATH = "uppaal\\uppaal64-4.1.26\\bin-Windows\\verifyta.exe"
# set verifyta path
pyu.set_verifyta_path(VERIFYTA_PATH)

model_path_list = ['demo.xml', 'demo_new.xml'] * 100
trace_path_list = ['demo_trace.xtr', 'demo_new_grace.xtr'] * 100
# for loop
t0 = time.time()
for model, trace in zip(model_path_list, trace_path_list):
    pyu.Verifyta().verify(model_path=model, trace_path=trace)
print(f'Verify with for loop, time usage {time.time() - t0}')

# multi-threads
t0 = time.time()
# pyu.Verifytaeasy_verify(model_path=model_path_list, trace_path=trace_path_list, num_threads=20)
p = mp.Pool()
p.starmap(pyu.Verifyta().verify, zip(model_path_list, trace_path_list))
print(f'Verify with multi-threads, time usage {time.time() - t0}')
Verify with for loop, time usage 9.287375211715698
Verify with multi-threads, time usage 1.6694567203521729

5. Get Communication Graph

For models with multiple processes, you can use umod.get_communication_graph() method to visualize the sturcture of the model.

An example communication graph of a complex model in Demo_PipeNet is shown below:

Metadata

Release files for pyuppaal 1.2.0

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

Source distribution (sdist)

Source distribution for pyuppaal 1.2.0
File Size Uploaded
pyuppaal-1.2.0.tar.gz 1.4 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyuppaal 1.2.0
File Interpreter ABI Platform
pyuppaal-1.2.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 1.8 MB

Release files / pyuppaal-1.2.0.tar.gz

Download URL pyuppaal-1.2.0.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
639b696f536806e02a06616da6f0cf5b13919705835ad2047329c87dd97cc367
BLAKE2b-256 checksum
How to use checksums
9eb70b95eb2ca20567df4c5ce2075d588478c9ec47ef289f107daf71eec5ff4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.13

Release files / pyuppaal-1.2.0-py2.py3-none-any.whl

Download URL pyuppaal-1.2.0-py2.py3-none-any.whl
Size 313.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
781cb169f92bf69b80bb6c078e6368e840ea6c7dd41b6ac4a4dbbc66be8cc8e8
BLAKE2b-256 checksum
How to use checksums
177d3055f13fdc863f176d4310504ac521307d744111a2117c997e8825e6310c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.13

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.1.14

1 release file

0.1.13

1 release file

0.1.12

1 release file

0.0.5

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