(testmodels-simulationsettingsdeprecationtest)= # simulationSettingsDeprecationTest.py You can view and download this file on Github: [simulationSettingsDeprecationTest.py](https://github.com/jgerstmayr/EXUDYN/tree/master/python/TestModels/simulationSettingsDeprecationTest.py) ```{code-block} python :linenos: #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # This is an EXUDYN example # # Details: A renamed simulation setting keeps working under its old name, with a DeprecationWarning that names # the new one (#2588): parallel.multithreadedLLimitLoads (and ...Residuals, ...Jacobians, # ...MassMatrices) is parallel.multithreadedLowerLimitLoads now. Writing the old name writes the new one, # reading it reads the new one - also in a copy of the settings and in settings constructed on their own. # Every use is counted in exu.sys['deprecationUse']; with exu.special.deprecations.warnOnce = False, every # use also warns, not only the first one of the session (#2804, #2806). # # Author: Johannes Gerstmayr # Date: 2026-10-03 # # Copyright:This file is part of Exudyn. Exudyn is free software. You can redistribute it and/or modify it under the terms of the Exudyn license. See 'LICENSE.txt' for more details. # #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ import exudyn as exu import copy import warnings testIsActive = exu.sys.get('testIsActive', False) def UseCount(name): return exu.sys.get('deprecationUse', {}).get('simulationSettings', {}).get('parallel.' + name, 0) deprecations = exu.special.deprecations warnOnceStored = deprecations.warnOnce deprecations.warnOnce = False #every use warns errors = 0 total = 0 for (k, name) in enumerate(['Loads', 'Residuals', 'Jacobians', 'MassMatrices']): simulationSettings = exu.SimulationSettings() used = UseCount('multithreadedLLimit' + name) with warnings.catch_warnings(record=True) as caught: warnings.simplefilter('always') setattr(simulationSettings.parallel, 'multithreadedLLimit' + name, 30 + k) #the old name oldValue = getattr(simulationSettings.parallel, 'multithreadedLLimit' + name) newValue = getattr(simulationSettings.parallel, 'multithreadedLowerLimit' + name) warned = [str(entry.message) for entry in caught if issubclass(entry.category, DeprecationWarning)] if newValue != 30 + k or oldValue != 30 + k: errors += 1 if len(warned) != 2 or ('parallel.multithreadedLowerLimit' + name) not in warned[0]: errors += 1 if UseCount('multithreadedLLimit' + name) != used + 2: #written and read: two uses recorded errors += 1 total += newValue deprecations.warnOnce = warnOnceStored #a copy has its own values, and the old name forwards in it as well simulationSettings = exu.SimulationSettings() settingsCopy = copy.copy(simulationSettings) with warnings.catch_warnings(): warnings.simplefilter('ignore') settingsCopy.parallel.multithreadedLLimitLoads = 7 if settingsCopy.parallel.multithreadedLowerLimitLoads != 7 or simulationSettings.parallel.multithreadedLowerLimitLoads == 7: errors += 1 exu.Print('simulationSettingsDeprecationTest: errors', errors) u = total + errors exu.Print('solution of simulationSettingsDeprecationTest=', u) exu.sys['testResult'] = u ```