Inspect Stored Failure Logs

You can load all Resultbag results and select entries with entry.failure is not None. There is no result.failures attribute. This example uses the same mixed batch as the batch failure tutorial.

Use an installed package, a configured JCMsuite runtime, and a solver license:

python demos/documentation_tutorials/failure_logs/resultbag.py
"""Load all stored results, select failures, and inspect their attempt logs."""

from tempfile import TemporaryDirectory

import jcmsuite
from jcmsuite.results import Resultbag

# Use a fresh, trusted bag so previous successful cache entries cannot hide failures.
with TemporaryDirectory() as directory:
    bag = Resultbag(f"{directory}/failures.jcmrb")
    jcmsuite.solve(
        "project.jcmp",
        keys=[
            {"permittivity": "2.25"},
            {"permittivity": "intentional_solver_error"},
            {"permittivity": "3.0"},
        ],
        temporary=True,
        on_error="collect",
        resultbag=bag,
    )

    stored = bag.get_results()
    for entry in stored:
        if entry.failure is not None:
            print(entry.keys, entry.failure.message)
            # Promoted attempt-only entries need management access for detailed logs.
            for attempt in bag.management.get_attempt_logs(entry.keys):
                print(attempt)

The script creates a fresh trusted bag, runs two successful entries and one deliberate failure, then prints the stored failure and its attempt records. The temporary bag is removed when the script exits. To inspect your own bag, open its trusted file and start at stored = bag.get_results().

Retrieval Caveats

  • get_results() returns a standard result shape, not always a batch. One successful entry returns a SolveResult. Empty selections raise InvalidConfigurationError. This example stores a mixed batch, so retrieval returns a batch that you can iterate over.

  • The default selection includes unsuffixed entries. Pass the matching jcmt_pattern to retrieve entries stored under that pattern. Pass the same pattern to management log methods.

  • Stored successful results take precedence over attempt-only records with the same identity. An earlier failed attempt followed by success is not a currently failed result.

  • Final attempt-only entries are promoted to failures. Their failure message represents the final stored payload, and their entry.log is not populated. Use bag.management.get_attempt_logs(entry.keys) for detailed records. Records can contain an execution_log mapping with stdout, stderr, and return_code, in addition to exception and attempt information.

  • Errors before execution attempts begin need not have stored attempt records. Resultbag retrieval is not an inventory of every error ever raised.

  • Retrieval indices describe the selected stored entries, not necessarily the original batch positions.

  • Only open Resultbag files you trust. Resultbag loading uses Python pickle.

Project Files

project.jcmp
Project {
  InfoLevel = 3
  Electromagnetics {
    TimeHarmonic {
      Scattering {
        FieldComponents = Electric
        Accuracy {
          FiniteElementDegree = 3
          Refinement {
            MaxNumberSteps = 0
            PreRefinements = 0
          }
        }
      }
    }
  }
}
materials.jcmt
Material {
  Name = "Vacuum"
  DomainId = 1
  RelPermittivity = 1.0
}
Material {
  Name = "Rod"
  DomainId = 2
  RelPermittivity = %(permittivity)s
}
layout.jcm
Layout2D {
  UnitOfLength = 1e-6
  MeshOptions {
    MaximumSideLength = 0.1
  }
  Objects {
    Parallelogram {
      Name = "ComputationalDomain"
      DomainId = 1
      Priority = ComputationalDomain
      Width = 4
      Height = 4
      Boundary {
        Class = Transparent
      }
    }
    Circle {
      Name = "Rod"
      DomainId = 2
      Priority = 1
      Radius = 0.3
      RefineAll = 4
    }
  }
}
sources.jcm
SourceBag {
  Source {
    ElectricFieldStrength {
      PlaneWave {
        K = [1.14239732857811e7 0.0 0.0]
        Amplitude = [0 0 1]
      }
    }
  }
}