Coverage for moptipy / api / logging.py: 100%
85 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-24 08:49 +0000
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-24 08:49 +0000
1"""Shared constants and functions for dealing with logs."""
3from typing import Final
5#: the file suffix to be used for log files
6FILE_SUFFIX: Final[str] = ".txt"
8#: the key for the exception type
9KEY_EXCEPTION_TYPE: Final[str] = "exceptionType"
10#: the key for the exception value
11KEY_EXCEPTION_VALUE: Final[str] = "exceptionValue"
12#: the key for the exception stack trace
13KEY_EXCEPTION_STACK_TRACE: Final[str] = "exceptionStackTrace"
15#: the key for algorithms
16KEY_ALGORITHM: Final[str] = "algorithm"
17#: the key for the instance
18KEY_INSTANCE: Final[str] = "instance"
20#: the common name prefix of all error sections
21ERROR_SECTION_PREFIX: Final[str] = "ERROR_"
22#: the section indicating an error during the algorithm run
23SECTION_ERROR_IN_RUN: Final[str] = f"{ERROR_SECTION_PREFIX}IN_RUN"
24#: the section indicating an error that occurred in the context of the
25#: process. this may be an error in the algorithm or, more likely, in the
26#: processing of the result.
27SECTION_ERROR_IN_CONTEXT: Final[str] = f"{ERROR_SECTION_PREFIX}IN_CONTEXT"
28#: the section indicating an invalid candidate solution
29SECTION_ERROR_INVALID_Y: Final[str] = f"{ERROR_SECTION_PREFIX}INVALID_Y"
30#: the section indicating a mismatch of the computed and registered best f
31SECTION_ERROR_BEST_F: Final[str] = f"{ERROR_SECTION_PREFIX}BEST_F_MISMATCH"
32#: the section indicating an invalid point in the search space
33SECTION_ERROR_INVALID_X: Final[str] = f"{ERROR_SECTION_PREFIX}INVALID_X"
34#: the section indicating that the time measurement has an error
35SECTION_ERROR_TIMING: Final[str] = f"{ERROR_SECTION_PREFIX}TIMING"
36#: the section indicating an error caught during log writing
37SECTION_ERROR_IN_LOG: Final[str] = f"{ERROR_SECTION_PREFIX}IN_LOG"
39#: the progress csv section
40SECTION_PROGRESS: Final[str] = "PROGRESS"
41#: the FEs column for the progress CSV
42PROGRESS_FES: Final[str] = "fes"
43#: the time millis column for the progress CSV
44PROGRESS_TIME_MILLIS: Final[str] = "timeMS"
45#: the current objective value column for the progress CSV
46PROGRESS_CURRENT_F: Final[str] = "f"
48#: the end state
49SECTION_FINAL_STATE: Final[str] = "STATE"
50#: the total number of consumed FEs
51KEY_TOTAL_FES: Final[str] = "totalFEs"
52#: the total number of consumed milliseconds
53KEY_TOTAL_TIME_MILLIS: Final[str] = "totalTimeMillis"
54#: the best encountered objective value
55KEY_BEST_F: Final[str] = "bestF"
56#: the vector of objective values of the best solution
57KEY_BEST_FS: Final[str] = "bestFs"
58#: the number of archived non-dominated solutions
59KEY_ARCHIVE_SIZE: Final[str] = "archiveSize"
60#: the FE when the best objective value was reached
61KEY_LAST_IMPROVEMENT_FE: Final[str] = "lastImprovementFE"
62#: the time in milliseconds when the best objective value was reached
63KEY_LAST_IMPROVEMENT_TIME_MILLIS: Final[str] = "lastImprovementTimeMillis"
65#: the archive section prefix
66PREFIX_SECTION_ARCHIVE: Final[str] = "ARCHIVE_"
67#: the archive quality section suffix
68SECTION_ARCHIVE_QUALITY: Final[str] = f"{PREFIX_SECTION_ARCHIVE}QUALITIES"
69#: the scalarized objective value column of the archive if without numeric
70#: suffix, the result of the ith objective function if with numeric suffix
71KEY_ARCHIVE_F: Final[str] = PROGRESS_CURRENT_F
73#: the archive X section suffix
74SUFFIX_SECTION_ARCHIVE_X: Final[str] = "_X"
75#: the archive Y section suffix
76SUFFIX_SECTION_ARCHIVE_Y: Final[str] = "_Y"
78#: the setup section
79SECTION_SETUP: Final[str] = "SETUP"
80#: the default log key for names of objects
81KEY_NAME: Final[str] = "name"
82#: the class of an object
83KEY_CLASS: Final[str] = "class"
84#: the inner class of an object
85KEY_INNER_CLASS: Final[str] = "innerClass"
86#: the default log key for the lower bound of objective function values
87KEY_F_LOWER_BOUND: Final[str] = "lowerBound"
88#: the default log key for the upper bound of objective function values
89KEY_F_UPPER_BOUND: Final[str] = "upperBound"
90#: the maximum FEs of a black-box process
91KEY_MAX_FES: Final[str] = "maxFEs"
92#: the maximum runtime in milliseconds of a black-box process
93KEY_MAX_TIME_MILLIS: Final[str] = "maxTimeMillis"
94#: the goal objective value of a black-box process
95KEY_GOAL_F: Final[str] = "goalF"
96#: the random seed
97KEY_RAND_SEED: Final[str] = "randSeed"
98#: the random generator type
99KEY_RAND_GENERATOR_TYPE: Final[str] = "randGenType"
100#: the type of the bit generator used by the random generator
101KEY_RAND_BIT_GENERATOR_TYPE: Final[str] = "randBitGenType"
102#: the number of decision variables
103KEY_SPACE_NUM_VARS: Final[str] = "nvars"
104#: the maximum archive size (after pruning)
105KEY_ARCHIVE_MAX_SIZE: Final[str] = "archiveMaxSize"
106#: the pruning limit of the archive size
107KEY_ARCHIVE_PRUNE_LIMIT: Final[str] = "archivePruneLimit"
109#: the scope of the process parameters
110SCOPE_PROCESS: Final[str] = "p"
111#: the scope of the solution space
112SCOPE_SOLUTION_SPACE: Final[str] = "y"
113#: the scope of the search space
114SCOPE_SEARCH_SPACE: Final[str] = "x"
115#: the scope of the objective function
116SCOPE_OBJECTIVE_FUNCTION: Final[str] = "f"
117#: the scope of the encoding
118SCOPE_ENCODING: Final[str] = "g"
119#: the scope of the optimization algorithm
120SCOPE_ALGORITHM: Final[str] = "a"
121#: the scope of the multi-objective archive pruner
122SCOPE_PRUNER: Final[str] = "ap"
123#: the scope of the nullary search operator
124SCOPE_OP0: Final[str] = "op0"
125#: the scope of the unary search operator
126SCOPE_OP1: Final[str] = "op1"
127#: the scope of the binary search operator
128SCOPE_OP2: Final[str] = "op2"
130#: the automatically generated system info section
131SECTION_SYS_INFO: Final[str] = "SYS_INFO"
132#: information about the current session
133SCOPE_SESSION: Final[str] = "session"
134#: the time when the session was started
135KEY_SESSION_START: Final[str] = "start"
136#: the node on which the session is running
137KEY_NODE_NAME: Final[str] = "node"
138#: the affinity of the process to logical CPUs
139KEY_CPU_AFFINITY: Final[str] = "cpuAffinity"
140#: the pid of the process
141KEY_PROCESS_ID: Final[str] = "processId"
142#: the command line of the process
143KEY_COMMAND_LINE: Final[str] = "commandLine"
144#: the working directory of the process
145KEY_WORKING_DIRECTORY: Final[str] = "workingDirectory"
146#: the ip address of the node on which the session is running
147KEY_NODE_IP: Final[str] = "ipAddress"
148#: the versions scope in the sys-info section
149SCOPE_VERSIONS: Final[str] = "version"
150#: the hardware scope in the sys-info section
151SCOPE_HARDWARE: Final[str] = "hardware"
152#: the number of physical CPUs
153KEY_HW_N_PHYSICAL_CPUS: Final[str] = "nPhysicalCpus"
154#: the number of logical CPUs
155KEY_HW_N_LOGICAL_CPUS: Final[str] = "nLogicalCpus"
156#: the clock speed of the CPUs
157KEY_HW_CPU_MHZ: Final[str] = "cpuMhz"
158#: the key for the byte order
159KEY_HW_BYTE_ORDER: Final[str] = "byteOrder"
160#: the key for the machine
161KEY_HW_MACHINE: Final[str] = "machine"
162#: the key for the cpu name
163KEY_HW_CPU_NAME: Final[str] = "cpu"
164#: the key for the memory size
165KEY_HW_MEM_SIZE: Final[str] = "memSize"
166#: the operating system in the sys-info section
167SCOPE_OS: Final[str] = "os"
168#: the operating system name
169KEY_OS_NAME: Final[str] = "name"
170#: the operating system version
171KEY_OS_VERSION: Final[str] = "version"
172#: the operating system release
173KEY_OS_RELEASE: Final[str] = "release"
174#: the python scope in the sys-info section
175SCOPE_PYTHON: Final[str] = "python"
176#: the python version
177KEY_PYTHON_VERSION: Final[str] = "version"
178#: the python implementation
179KEY_PYTHON_IMPLEMENTATION: Final[str] = "implementation"
181#: the resulting point in the solution space
182SECTION_RESULT_Y: Final[str] = "RESULT_Y"
183#: the resulting point in the search space
184SECTION_RESULT_X: Final[str] = "RESULT_X"
186#: all the section titles combined in one set
187# noinspection PyDefaultArgument
188# pylint: disable=[C3002]
189_ALL_SECTIONS: Final[set[str]] = (lambda g=globals(): { # type: ignore # noqa
190 g[k] for k in g if k.startswith("SECTION_")})() # type: ignore