Inspect Mixed Batch Failures

Run this example with an installed package, configured JCMsuite runtime, and solver license:

python demos/documentation_tutorials/failure_logs/batch.py

The first and last permittivities are valid. The middle value deliberately produces an invalid material input. temporary=True gives each entry an isolated working directory. on_error="collect" continues after the failed entry; the default "raise" stops at the first error.

"""Inspect a mixed batch without stopping at the first failure."""

import jcmsuite

batch = jcmsuite.solve(
    "project.jcmp",
    keys=[
        {"permittivity": "2.25"},
        {"permittivity": "intentional_solver_error"},
        {"permittivity": "3.0"},
    ],
    temporary=True,
    on_error="collect",
)
print("Successful entries:", batch.success_indices)
print("Failed entries:", batch.failure_indices)
for entry in batch:
    if entry.failure is not None:
        print(entry.index, entry.keys, entry.failure.message)
        if entry.log is not None:
            print(entry.log.stdout)
            print(entry.log.stderr)
        else:
            print("No execution log was captured")

A successful run reports success indices (0, 2) and failure indices (1,). Every entry has a singular failure attribute, not failures. Test it against None before reading its message. An entry’s log can be absent, for example when execution did not start. Keep the guard even when the example captures a log.

Continue with stored failure logs to inspect failures after Resultbag retrieval.

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]
      }
    }
  }
}