Skip to content

Add a resource estimation

Add a resource estimation to your method so the platform provides appropriate resources for your method run. This is where you declare how much memory you will need and how your method (mesher/solver) scales with number of processors.

Prerequisites

  • Method with either:
  • A configurationSchema that has at least one field, or
  • At least one input in dataInterface.
  • SimKit CLI installed (see installation).

Example: a mesher that runs only on single processor

resourceEstimation {
    val nCellsEstimate = configValueModel.boundingBoxVolume / pow(configValueModel.cellSize, 3)
    val memoryInKbPerCell = 1.asValueModel()
    val oneProcMemoryInMb = nCellsEstimate * memoryInKbPerCell / 1000.asValueModel()
    val oneProcTimeInSecs = 42.0 * nCellsEstimate * log(nCellsEstimate, 10)

    return MethodResourceEstimationValueModel(
        oneProcessorEstimation =
            OneProcessorEstimationValueModel(
                memoryInMebibytes = oneProcMemoryInMb,
                storageInMebibytes = 3 * oneProcMemoryInMb,
                timeInSeconds = oneProcTimeInSecs,
            ),
    )
}

Memory estimate is based on the estimated number of cells and kb per cell. Storage estimate is three times bigger than memory estimate. Time estimate is based on an assumption of a O(n log(n)) algorithm.

Example: a solver that runs in parallel

resourceEstimation {
    val meshDataSize = dataSizeValueModel("mesh")

    val oneProcMemory = ceil(meshDataSize * 1.2)
    val oneProcTimeInSecs = meshDataSize / 60

    // Memory slowly increases to 2x at 192 cores
    val memoryAndStorageScaling =
        scaling(
            1 to 1.0,
            192 to 2.0,
        )

    // Speed up is perfectly linear until 96 cores, then almost flatlines
    val speedUp =
        scaling(
            1 to 1.0,
            96 to 96.0,
            192 to 100.0,
        )

    return MethodResourceEstimationValueModel(
        oneProcessorEstimation =
            OneProcessorEstimationValueModel(
                memoryInMebibytes = oneProcMemory,
                storageInMebibytes = oneProcMemory * 10,
                timeInSeconds = oneProcTimeInSecs,
                timeInSecondsByArch =
                    ConstantValueList(
                        TimeByArchValueModel(cpuArch = "AMD64".asValueModel(), timeInSeconds = oneProcTimeInSecs),
                        TimeByArchValueModel(cpuArch = "ARM".asValueModel(), timeInSeconds = oneProcTimeInSecs / 2),
                    ),
            ),
        scalingEstimation =
            ScalingEstimationValueModel(
                speedUp = speedUp,
                memory = memoryAndStorageScaling,
                storage = memoryAndStorageScaling,
            ),
    )
}

Baseline memory and time estimate for a single processor are based on the input mesh size. Time estimate on the ARM architecture is half of the baseline time estimate for the AMD64 architecture. Memory requirements grow from baseline on 1 processor to 2x the baseline on 192 processors. Speed up is perfectly linear until 96 processors (i.e. 96x speed-up for 96 processors), and then almost flatlines from 96 to 192 processors.

Build and verify

simkit component build
simkit component register <pkg>.method.json

The resource estimation is bundled into the component's JSON envelope (in the package field, alongside the schema and other metadata); the registry stores it; the platform consults it before provisioning the virtual machine.

Cross-references