Skip to content

Instantly share code, notes, and snippets.

@disouzam
Created June 28, 2026 16:15
Show Gist options
  • Select an option

  • Save disouzam/405961aaec30e406d57be0ff62759660 to your computer and use it in GitHub Desktop.

Select an option

Save disouzam/405961aaec30e406d57be0ff62759660 to your computer and use it in GitHub Desktop.
Scripts to run and monitor Cosmic Ray execution (being built for pycalphad)
#!/bin/bash
# This script checks the status of mutation testing at a configurable interval (default: 90 seconds).
interval_seconds="${1:-90}"
if ! [[ "$interval_seconds" =~ ^[0-9]+$ ]] || [[ "$interval_seconds" -le 0 ]]; then
echo "Usage: $0 [interval_seconds]"
exit 1
fi
prev_complete=""
stopped_at=""
current_interval="$interval_seconds"
while true; do
raw_output="$(bash mutation_testing/Local_distributor/reports.sh 2>&1)"
status_output="$(echo "$raw_output" | tail -n 4)"
echo -e "\n$status_output"
current_complete="$(echo "$status_output" | grep -E '^complete:' | sed -E 's/^complete:[[:space:]]*([0-9]+).*/\1/')"
if [[ -n "$prev_complete" && -n "$current_complete" && "$current_complete" == "$prev_complete" ]]; then
if [[ -z "$stopped_at" ]]; then
stopped_at="$(date '+%Y-%m-%d %H:%M:%S')"
fi
printf '\a'
current_interval=$((current_interval / 2))
if [[ "$current_interval" -lt 1 ]]; then
current_interval=1
fi
echo -e "\e[31mReducing interval to \e[0m${current_interval}s \e[33m(stopped at: ${stopped_at})\e[0m"
else
stopped_at=""
current_interval="$interval_seconds"
fi
prev_complete="$current_complete"
for ((i=current_interval; i>0; i--)); do
printf "\rNext check in %3ds..." "$i"
sleep 1
done
echo
done
[cosmic-ray]
module-path = "pycalphad"
timeout = 30.0
excluded-modules = []
test-command = "uv run python -m pytest tests"
[cosmic-ray.distributor]
name = "local"
[cosmic-ray]
module-path = "pycalphad"
timeout = 90
excluded-modules = []
test-command = "uv run python run_pytest_and_capture.py -x --template=html1/index.html --report=report.html -s tests"
[cosmic-ray.distributor]
name = "local"
[cosmic-ray.filters.operators-filter]
exclude-operators = [
# Based on https://github.com/sixty-north/cosmic-ray/issues/593#issuecomment-4253359387
# you would think this one would be good, but it mostly ends up changing
# initial variable values, which rarely matter all that much as they
# get immediately overwritten later.
"core/NumberReplacer",
# there are effectively duplicates of a few real core ones:
# 1. core/ReplaceComparisonOperator_Gt_Lt
# 2. core/ReplaceComparisonOperator_Lt_Gt
# 3. core/ReplaceComparisonOperator_NotEq_Eq
# 4. core/ReplaceComparisonOperator_Eq_NotEq
"core/ReplaceComparisonOperator_Gte_LtE",
"core/ReplaceComparisonOperator_Gte_NotEq",
"core/ReplaceComparisonOperator_Gte_Eq",
"core/ReplaceComparisonOperator_Gte_Is",
"core/ReplaceComparisonOperator_Gte_IsNot",
"core/ReplaceComparisonOperator_Gt_GtE",
"core/ReplaceComparisonOperator_Gt_LtE",
"core/ReplaceComparisonOperator_Gt_NotEq",
"core/ReplaceComparisonOperator_Gt_Eq",
"core/ReplaceComparisonOperator_Gt_Is",
"core/ReplaceComparisonOperator_Gt_IsNot",
"core/ReplaceComparisonOperator_Lt_LtE",
"core/ReplaceComparisonOperator_Lt_NotEq",
"core/ReplaceComparisonOperator_Lt_Eq",
"core/ReplaceComparisonOperator_Lt_Is",
"core/ReplaceComparisonOperator_Lt_IsNot",
"core/ReplaceComparisonOperator_Lte_LtE",
"core/ReplaceComparisonOperator_Lte_NotEq",
"core/ReplaceComparisonOperator_Lte_Eq",
"core/ReplaceComparisonOperator_Lte_Is",
"core/ReplaceComparisonOperator_Lte_IsNot",
"core/ReplaceComparisonOperator_NotEq_Is",
"core/ReplaceComparisonOperator_NotEq_IsNot",
"core/ReplaceComparisonOperator_NotEq_GtE",
"core/ReplaceComparisonOperator_NotEq_Gt",
"core/ReplaceComparisonOperator_NotEq_LtE",
"core/ReplaceComparisonOperator_NotEq_Lt",
"core/ReplaceComparisonOperator_Eq_GtE",
"core/ReplaceComparisonOperator_Eq_Gt",
"core/ReplaceComparisonOperator_Eq_IsNot",
"core/ReplaceComparisonOperator_Eq_Lt",
"core/ReplaceComparisonOperator_Eq_LtE",
"core/ReplaceComparisonOperator_Eq_Is",
# these are basically duplicate of a few real core ones too
# basically just rely on changing sub/add/mul/div
"core/ReplaceBinaryOperator_.*_BitXor",
"core/ReplaceBinaryOperator_.*_BitAnd",
"core/ReplaceBinaryOperator_.*_BitOr",
"core/ReplaceBinaryOperator_.*_LShift",
"core/ReplaceBinaryOperator_.*_RShift",
"core/ReplaceBinaryOperator_.*_Pow",
"core/ReplaceBinaryOperator_.*_Mod",
"core/ReplaceBinaryOperator_.*_FloorDiv"
]
#!/usr/bin/env bash
start_time=$(date +%s)
uv run python -m pytest tests --template=html1/index.html --report=baseline-test-report.html -s
end_time=$(date +%s)
elapsed=$((end_time - start_time))
echo "Execution time: ${elapsed} seconds"
#!/bin/bash
# Initialization
force_argument=$1
mutation_testing_dir="mutation_testing"
directory="${mutation_testing_dir}/Local_distributor"
database_path="${directory}/cosmic_ray.sqlite"
config_path="${directory}/cosmic_ray.toml"
if [ -n "$force_argument" ] && [ "$force_argument" != "--force" ]; then
echo "Usage: $0 [--force]"
exit 1
fi
if [ -f "$database_path" ] && [ "$force_argument" != "--force" ]; then
echo "Database \"$database_path\" already exists. Use --force to overwrite."
exit 1
fi
echo -e "\nInitializing database for local distributor...\n"
if [ -n "$force_argument" ] && [ "$force_argument" == "--force" ]; then
uv run cosmic-ray init "$config_path" "$database_path" --force
else
uv run cosmic-ray init "$config_path" "$database_path"
fi
# Baseline execution
echo -e "\nRunning baseline execution...\n"
uv run cosmic-ray --verbosity=CRITICAL baseline "$config_path"
#!/bin/bash
# From pycalphad root's folder, run this command:
directory="mutation_testing/Local_distributor"
uv run cosmic-ray --verbosity=DEBUG exec ${directory}/cosmic_ray.toml ${directory}/cosmic_ray.sqlite
#!/bin/bash
NUM_WORKERS="$1"
if ! [[ "$NUM_WORKERS" =~ ^[1-9][0-9]*$ ]]; then
echo "Usage: $0 <num_workers>"
exit 1
fi
rm -rf worker*
for i in $(seq 1 "$NUM_WORKERS"); do
worker_dir="worker${i}"
mkdir "$worker_dir"
find . -type f \
! -path "./.devcontainer/*" \
! -path "./.git/*" \
! -path "./.github/*" \
! -path "./.pytest_cache/*" \
! -path "./.venv/*" \
! -path "./.vscode/*" \
! -path "./__pycache__/*" \
! -path "./*/__pycache__/*" \
! -path "./automation/*" \
! -path "./docs/*" \
! -path "./examples/*" \
! -path "./mutation_testing/*" \
! -path "./pycalphad.egg-info/*" \
! -path "./tests/reports/*" \
! -path "./worker*/*" \
-exec cp -v --parents {} "$worker_dir"/ \;
pushd "$worker_dir"
git add .
sed -i 's|\.\./cosmic-ray|../../cosmic-ray|g' pyproject.toml
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_PYCALPHAD=0.11.2 uv sync
port=$((9000 + i))
launch_script="launch-worker-${i}.sh"
echo "uv run cosmic-ray --verbosity DEBUG http-worker --port $port" >> $launch_script
echo "popd" >> $launch_script
popd
done
#!/bin/bash
directory="mutation_testing/Local_distributor"
uv run cr-report ${directory}/cosmic_ray.sqlite
echo $(date)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment