code: def wrapper(
      nobs: int, b: int, trend: str = "c", max_memory: int = 1024
  ) -> np.ndarray:
      """
      A wrapper around the main simulation that runs it in blocks so that large
      simulations can be run without constructing very large arrays and running
      out of memory.
      """
      rng = RandomState()
      rng.seed(0)
      memory = max_memory * 2**20
      b_max_memory = memory // 8 // nobs
      b_max_memory = max(b_max_memory, 1)
      remaining = b
      results = np.zeros(b)
      now = dt.datetime.now()
      time_fmt = "{0:d}:{1:0>2d}:{2:0>2d}"
      msg = (
          "trend {0}, {1} reps remaining, "
          + "elapsed {2}, remaining {3}"
      )
      while remaining > 0:
          b_eff = min(remaining, b_max_memory)
          completed = b - remaining
          results[completed : completed + b_eff] = simulate_kpss(
              nobs, b_eff, trend=trend, rng=rng
          )
          remaining -= b_max_memory
          elapsed = (dt.datetime.now() - now).total_seconds()
          expected_remaining = max(0, remaining) * (
              elapsed / (b - remaining)
          )
  
          m, s = divmod(int(elapsed), 60)
          h, m = divmod(m, 60)
          elapsed_fmt = time_fmt.format(h, m, s)
  
          m, s = divmod(int(expected_remaining), 60)
          h, m = divmod(m, 60)
          expected_remaining_fmt = time_fmt.format(h, m, s)
  
          print(
              msg.format(
                  trend,
                  max(0, remaining),
                  elapsed_fmt,
                  expected_remaining_fmt,
              )
          )
  
      return results
  
file_path: arch/arch/unitroot/critical_values/simulation/kpss_critical_values_simulation.py
imports: import os
  from typing import Optional, cast
  import numpy
  from numpy.random import RandomState
  import pandas
  from arch.utility.timeseries import add_trend
label_desc: Use image node_id 2 for calling a global function with example usage: wrapper(nobs, b, trend, max_memory) and returns: results