simulationSettingsDeprecationTest.py
You can view and download this file on Github: simulationSettingsDeprecationTest.py
1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2# This is an EXUDYN example
3#
4# Details: A renamed simulation setting keeps working under its old name, with a DeprecationWarning that names
5# the new one (#2588): parallel.multithreadedLLimitLoads (and ...Residuals, ...Jacobians,
6# ...MassMatrices) is parallel.multithreadedLowerLimitLoads now. Writing the old name writes the new one,
7# reading it reads the new one - also in a copy of the settings and in settings constructed on their own.
8# Every use is counted in exu.sys['deprecationUse']; with exu.special.deprecations.warnOnce = False, every
9# use also warns, not only the first one of the session (#2804, #2806).
10#
11# Author: Johannes Gerstmayr
12# Date: 2026-10-03
13#
14# 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.
15#
16#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17
18import exudyn as exu
19import copy
20import warnings
21
22testIsActive = exu.sys.get('testIsActive', False)
23
24def UseCount(name):
25 return exu.sys.get('deprecationUse', {}).get('simulationSettings', {}).get('parallel.' + name, 0)
26
27deprecations = exu.special.deprecations
28warnOnceStored = deprecations.warnOnce
29deprecations.warnOnce = False #every use warns
30errors = 0
31total = 0
32for (k, name) in enumerate(['Loads', 'Residuals', 'Jacobians', 'MassMatrices']):
33 simulationSettings = exu.SimulationSettings()
34 used = UseCount('multithreadedLLimit' + name)
35 with warnings.catch_warnings(record=True) as caught:
36 warnings.simplefilter('always')
37 setattr(simulationSettings.parallel, 'multithreadedLLimit' + name, 30 + k) #the old name
38 oldValue = getattr(simulationSettings.parallel, 'multithreadedLLimit' + name)
39 newValue = getattr(simulationSettings.parallel, 'multithreadedLowerLimit' + name)
40 warned = [str(entry.message) for entry in caught if issubclass(entry.category, DeprecationWarning)]
41 if newValue != 30 + k or oldValue != 30 + k:
42 errors += 1
43 if len(warned) != 2 or ('parallel.multithreadedLowerLimit' + name) not in warned[0]:
44 errors += 1
45 if UseCount('multithreadedLLimit' + name) != used + 2: #written and read: two uses recorded
46 errors += 1
47 total += newValue
48deprecations.warnOnce = warnOnceStored
49
50#a copy has its own values, and the old name forwards in it as well
51simulationSettings = exu.SimulationSettings()
52settingsCopy = copy.copy(simulationSettings)
53with warnings.catch_warnings():
54 warnings.simplefilter('ignore')
55 settingsCopy.parallel.multithreadedLLimitLoads = 7
56if settingsCopy.parallel.multithreadedLowerLimitLoads != 7 or simulationSettings.parallel.multithreadedLowerLimitLoads == 7:
57 errors += 1
58
59exu.Print('simulationSettingsDeprecationTest: errors', errors)
60u = total + errors
61exu.Print('solution of simulationSettingsDeprecationTest=', u)
62
63exu.sys['testResult'] = u