Commit 714ca363 authored by Jan Kiene's avatar Jan Kiene
Browse files

add reproducibility for random parts of sanitizer tests

- seed the numpy rng with CI_JOB_ID
- add command line arg for injecting a custom seed
parent 65465054
Loading
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -3,12 +3,13 @@ from scipy.spatial.transform import Rotation


FRAMES_PER_SEC = 50
MAGIC_VAL_TO_SIGNAL_EULER_ANGLES = -3


def random_trajectory(duration_sec):
    n_frames = int(FRAMES_PER_SEC * duration_sec)
    trj = np.random.random((n_frames, 4))
    trj[:, 0] = -3
    trj[:, 0] = MAGIC_VAL_TO_SIGNAL_EULER_ANGLES
    trj[:, 1] *= 180
    trj[:, 2] *= 90
    trj[:, 3] *= 180
@@ -18,7 +19,7 @@ def random_trajectory(duration_sec):
def constant_trajectory(duration_sec, yaw=0, pitch=0, roll=0):
    n_frames = int(FRAMES_PER_SEC * duration_sec)
    trj = np.empty((n_frames, 4))
    trj[:, 0] = -3
    trj[:, 0] = MAGIC_VAL_TO_SIGNAL_EULER_ANGLES
    trj[:, 1] = yaw
    trj[:, 2] = pitch
    trj[:, 3] = roll
@@ -39,4 +40,3 @@ def constant_trajectory_quat(duration_sec, w=1, x=0, y=0, z=0):
    trj[:, 2] = y
    trj[:, 3] = z
    return trj
+38 −32
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import argparse
import pathlib
import subprocess
import sys
import os
import numpy as np
import json

@@ -75,12 +76,17 @@ ARGS_FOR_OC = {
    "BINAURAL_ROOM_REVERB": BINAURAL_OUT_ARGS,
}

SEED_FOR_RANDOM = int(os.environ.get("CI_JOB_ID", 0))


def main(args):
    in_format = args.in_format
    out_formats = args.out_formats
    tests = args.tests
    run_fec = not args.skip_fec
    seed = SEED_FOR_RANDOM if args.inject_seed is None else args.inject_seed

    np.random.seed(seed)

    assert all([t in SUPPORTED_TESTS for t in tests])

@@ -92,7 +98,6 @@ def main(args):


def get_modes(in_format: str) -> list:

    in_format_for_script = in_format
    if in_format in MC_MODES:
        in_format_for_script = "MC"
@@ -134,7 +139,6 @@ def assemble_oc_dict(out_formats: list):


def get_md_file_command(in_format: str) -> list:

    cmd = list()
    if "ISM" in in_format:
        cmd.append("--ism_metadata_files")
@@ -145,8 +149,7 @@ def get_md_file_command(in_format: str) -> list:
    return cmd


def run_check(in_format: str, out_formats: list, tests: list, run_fec: bool = True):

def run_check(in_format: str, out_formats: list, tests: list, run_fec: bool):
    modes = get_modes(in_format)
    if len(modes) == 0:
        return 0
@@ -187,7 +190,7 @@ def run_check(in_format: str, out_formats: list, tests: list, run_fec: bool = Tr
    # resue decoder part of StereDmxEVS mode (it is basically a duplicate of "normal" mono run)
    if in_format == "StereoDmxEVS":
        panning = np.random.randint(-90, 91)
        cmd_no_fec += [f'-D=-non_diegetic_pan {panning}']
        cmd_no_fec += [f"-D=-non_diegetic_pan {panning}"]

    print(
        "======== Script command line WITHOUT plc: ========\n{}".format(
@@ -277,5 +280,8 @@ if __name__ == "__main__":
    parser.add_argument("out_formats", type=str, nargs="+")
    parser.add_argument("--tests", type=str, nargs="+", default=["CLANG1", "CLANG2"])
    parser.add_argument("--skip_fec", action="store_true")
    parser.add_argument(
        "--inject_seed", type=int, help="Value to use for seeding random generators"
    )

    sys.exit(main(parser.parse_args()))