Skip to main content

Command-line tool for running a single mastapy script in multiple APIs and comparing results.

Project description

SMT


uv Ruff License: MIT Python

mastapy-cli-regression is a command-line plugin for mastapy.

A preview of the regression plugin on the command line.

To install this plugin, run the following:

pip install mastapy[cli-regression]

This plugin is designed to be used on the command-line via the mastapy package using the following syntax:

python -m mastapy regression ...

Features

  • Compare results between different versions of the MASTA API and automatically identify regressions.
  • Completely automated and parallelized virtual environment creation, installation and script execution for each specified version of the MASTA API.
  • Fully customisable comparisons; choose your own tolerances, group values together and decide how you want them to be compared.
  • Supports loading legacy mastapy packages using modern Python versions.
  • Export results to an Excel workbook for further analysis.

Release Information

This is the initial release of the package.

Pre-Requisites

Note that these pre-requisites are only required for launching the plugin from the command-line.

  • mastapy>=15.1.3
  • An internet connection

Usage

Before starting, prepare a Python script for the plugin to execute. This must be a self-contained script (i.e. does not rely on @mastapy.masta_property) that can be executed from the command-line.

There are two steps to using this plugin. Before executing your script, you must modify it to export a comparison structure, mastapy_cli_regression.Comparer, which the plugin will read to run your regression tests. The following is an example script demonstrating a modified script.

from mastapy import Examples

# Import the Comparer from the regression package.
from mastapy_cli_regression import Comparer


def main() -> None:
    design = Examples.Components.SIMPLE_HOUSING_FULL_MESH.load()

    # Create a new Comparer object. We will add values to this for regression testing.
    comparer = Comparer()

    for load_case in design.static_loads:
        # For each load case, create a new group. Any values added to the comparer while
        # indented inside the `with` statement will get added to the group. his will
        # help organise our results.
        with comparer.group("Load Case: " + load_case.name):
            system_deflection = load_case.system_deflection
            system_deflection.perform_analysis()

            gear_sets = design.all_parts_of_type_cylindrical_gear_set()
            mesh_groups = (gear_set.cylindrical_meshes for gear_set in gear_sets)
            meshes = (mesh for group in mesh_groups for mesh in group)

            for mesh in meshes:
                sd = system_deflection.results_for_cylindrical_gear_mesh(
                    mesh
                ).cast_to.cylindrical_gear_mesh_system_deflection_with_ltca_results
                altca_results = sd.advanced_ltca_results

                # Once we have results, we can add them to our comparison
                # structure. We must also decide how we want to configure
                # our tolerances for the regression tests. We have opted for a
                # relative tolerance, but other options are available.
                comparer.add(
                    "Total Misalignment",
                    sd.misalignment_data.total_equivalent_misalignment_for_rating,
                    relative_tolerance=0.0000001,
                )

                flank_rating = altca_results.rating.cylindrical_mesh_single_flank_rating
                flank_rating = flank_rating.gear_single_flank_ratings

                # Add values for the gear bending stress.
                comparer.add(
                    "Root Stress 0",
                    flank_rating[0].tooth_root_stress,
                    relative_tolerance=0.0000001,
                )
                comparer.add(
                    "Root Stress 1",
                    flank_rating[1].tooth_root_stress,
                    relative_tolerance=0.0000001,
                )

                # Add values for the gear contact stress.
                comparer.add(
                    "Contact Stress 0",
                    flank_rating[0].calculated_contact_stress,
                    relative_tolerance=0.0000001,
                )
                comparer.add(
                    "Contact Stress 1",
                    flank_rating[1].calculated_contact_stress,
                    relative_tolerance=0.0000001,
                )

    # Once we are done, we must call `comparer.collect`. This will output our
    # comparison structure for the regression plugin to read!
    comparer.collect()


if __name__ == "__main__":
    main()

Once the script has been modified to output a comparison structure, we are ready to launch it using the plugin. This is done from the command line.

For instance, to compare results between MASTA 14.0 and MASTA 15.0 and export results to Excel, assuming both versions of MASTA are installed in the default location, we could run:

python -m mastapy regression "path/to/script.py" 14.0 15.0 --export-excel

This will execute your script in both versions of the API and automatically compile test results, then export them to Excel. Alternatively, you can provide paths to your MASTA installations:

python -m mastapy regression "path/to/script.py" "path/to/MASTA 14.0" "path/to/MASTA 15.0" --export-excel

To view the full list of features, run:

python -m mastapy regression --help

Troubleshooting

Version differences

If you are attempting to compare different major versions of the API (e.g. comparing 14.0 and 15.0), changes in the API might cause your script to work in one API but not the other. To work around this, you can import __api_version__ from mastapy and branch on it:

from mastapy import __api_version__

if __api_version__ == "14.0.0":
    # Run code for MASTA 14.0
    ...
else:
    # Run code for MASTA 15.0
    ...

You may also need to use different versions of Python, depending on what each version of mastapy supports. This can be configured in your launch command using @VERSION syntax (or @PATH if you have a path to the Python executable):

python -m mastapy regression "path/to/script.py" 14.0@3.10 15.0

This will launch MASTA 14.0 using Python 3.10. You must have the corresponding version of Python installed.

Package Installation

This plugin automatically creates virtual environments, then downloads and installs packages into them. Internally, pip is used for all package management. If you require SSL certification, you can optionally use the --truststore flag to install it into your virtual environments:

python -m mastapy regression --truststore ...

Everything else must be configured using pip.ini or environment variables.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mastapy_cli_regression-0.1.0b1.post1.tar.gz (257.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mastapy_cli_regression-0.1.0b1.post1-py3-none-any.whl (269.0 kB view details)

Uploaded Python 3

File details

Details for the file mastapy_cli_regression-0.1.0b1.post1.tar.gz.

File metadata

  • Download URL: mastapy_cli_regression-0.1.0b1.post1.tar.gz
  • Upload date:
  • Size: 257.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mastapy_cli_regression-0.1.0b1.post1.tar.gz
Algorithm Hash digest
SHA256 2dd9ae49a8a8e567d3b641baca30d7ac9ca0cfbe71b1fbe2fc25a0378c175702
MD5 97a862a03f721661b360cbb8b8e60d66
BLAKE2b-256 3661b6bca19d0c0c6140cd1665d76c28fa514407c5703a55f465690a897f0638

See more details on using hashes here.

File details

Details for the file mastapy_cli_regression-0.1.0b1.post1-py3-none-any.whl.

File metadata

  • Download URL: mastapy_cli_regression-0.1.0b1.post1-py3-none-any.whl
  • Upload date:
  • Size: 269.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mastapy_cli_regression-0.1.0b1.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 01c5a647c8fcce358ea021a56b499fcec25de315f52bf77ccc53c9e42c38a0d2
MD5 3a1e8e96cc8893dc40f94b598e379019
BLAKE2b-256 40b8648c753d53b26b6ac95314166c9fa31f1b8d42fa42f3d234e22920d1e04c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page