{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a4eb5426",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:47:06.735402Z",
     "iopub.status.busy": "2026-10-02T14:47:06.735187Z",
     "iopub.status.idle": "2026-10-02T14:47:06.740494Z",
     "shell.execute_reply": "2026-10-02T14:47:06.739648Z"
    },
    "papermill": {
     "duration": 0.008072,
     "end_time": "2026-10-02T14:47:06.741235+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:47:06.733163+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "active-ipynb",
     "remove-output"
    ]
   },
   "outputs": [],
   "source": [
    "try:\n",
    "    from openmdao.utils.notebook_utils import notebook_mode  # noqa: F401\n",
    "except ImportError:\n",
    "    !python -m pip install openmdao[notebooks]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "442c4335",
   "metadata": {
    "papermill": {
     "duration": 0.000869,
     "end_time": "2026-10-02T14:47:06.743380+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:47:06.742511+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# Determining How Many Times a System was Executed\n",
    "\n",
    "All OpenMDAO `Systems` have a set of local counters that keep track of how many times they have\n",
    "been executed.\n",
    "\n",
    "**iter_count**\n",
    "\n",
    "    Counts the number of times this system has called _solve_nonlinear. This also\n",
    "    corresponds to the number of times that the system's outputs are recorded if a recorder\n",
    "    is present.\n",
    "\n",
    "**iter_count_apply**\n",
    "\n",
    "    Counts the number of times the system has called _apply_nonlinear. For ExplicitComponent,\n",
    "    calls to apply_nonlinear also call compute, so number of executions can be found by adding\n",
    "    this and iter_count together. Recorders do no record calls to _apply_nonlinear.\n",
    "\n",
    "**iter_count_without_approx**\n",
    "\n",
    "    Counts the number of times the system has iterated but excludes any that occur during\n",
    "    approximation of derivatives.\n",
    "\n",
    "When you have an `ExplicitComponent`, the number stored in iter_count may not match the total\n",
    "number of times that the \"compute\" function has been called.  This is because compute is also\n",
    "called whenever '_apply_nonlinear' is called to compute the norm of the current residual. For\n",
    "an explicit equation, the residual is defined as the difference in the value of the outputs\n",
    "before and after execution, and an additional execution is required to compute this.\n",
    "\n",
    "The correct execution count for an ExplicitComponent can always be obtained by adding iter_count\n",
    "and iter_count_apply.\n",
    "\n",
    "The recorder iteration coordinate will always match the iter_count because calls to apply_nonlinear\n",
    "are not recorded.\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.14"
  },
  "papermill": {
   "default_parameters": {},
   "duration": 0.808628,
   "end_time": "2026-10-02T14:47:06.931073+00:00",
   "environment_variables": {},
   "exception": null,
   "input_path": "/home/runner/work/OpenMDAO/OpenMDAO/openmdao/docs/openmdao_book/theory_manual/iter_count.ipynb",
   "output_path": "/home/runner/work/OpenMDAO/OpenMDAO/openmdao/docs/_executed_book/theory_manual/iter_count.ipynb",
   "parameters": {},
   "start_time": "2026-10-02T14:47:06.122445+00:00",
   "version": "2.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}