-
Notifications
You must be signed in to change notification settings - Fork 240
/
constants.py
130 lines (100 loc) · 3.18 KB
/
constants.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"""
Various objects to be used as constants.
"""
import os
from enum import IntEnum
import numpy as np
INF_BOUND = 1.0E30
# This is the dtype we use for index arrays. Petsc by default uses 32 bit ints
if os.environ.get('OPENMDAO_USE_BIG_INTS'):
INT_DTYPE = np.dtype(np.int64)
else:
INT_DTYPE = np.dtype(np.int32)
class _SetupStatus(IntEnum):
"""
Class used to define different states of the setup status.
Attributes
----------
PRE_SETUP : int
Newly initialized problem or newly added model.
POST_CONFIGURE : int
Configure has been called.
POST_SETUP : int
The `setup` method has been called, but vectors not initialized.
POST_FINAL_SETUP : int
The `final_setup` has been run, everything ready to run.
"""
PRE_SETUP = 0
POST_CONFIGURE = 1
POST_SETUP = 2
POST_FINAL_SETUP = 3
class _ReprClass(object):
"""
Class for defining objects with a simple constant string __repr__.
This is useful for constants used in arg lists when you want them to appear in
automatically generated source documentation as a certain string instead of python's
default representation.
"""
def __init__(self, repr_string):
"""
Inititialize the __repr__ string.
Parameters
----------
repr_string : str
The string to be returned by __repr__
"""
self._repr_string = repr_string
def __repr__(self):
"""
Return our _repr_string.
Returns
-------
str
Whatever string we were initialized with.
"""
return self._repr_string
def __eq__(self, other):
"""
Return True if other equals self.
Parameters
----------
other : object
The object we're being compared to.
Returns
-------
bool
True if self and other are equal, else False.
"""
return isinstance(other, _ReprClass) and self._repr_string == other._repr_string
def __hash__(self):
return hash(self._repr_string)
def __copy__(self):
"""
Return self instead of a copy.
This ensures that 'is' and 'is not' comparisons to copies of this object don't break.
Returns
-------
_ReprClass instance
Return self instead of a copy.
"""
return self
def __deepcopy__(self, memo):
"""
Return self instead of a copy.
This ensures that 'is' and 'is not' comparisons to deep copies of this object don't break.
Parameters
----------
memo : dict
Keeps track of already copied objects.
Returns
-------
_ReprClass instance
Return self instead of a copy.
"""
memo[id(self)] = self
return self
# unique object to check if default is given (when None is an allowed value)
_UNDEFINED = _ReprClass("UNDEFINED")
# Use this as a special value to be able to tell if the caller set a value for the optional
# out_stream argument. We run into problems running testflo if we use a default of sys.stdout.
_DEFAULT_OUT_STREAM = _ReprClass("DEFAULT_OUT_STREAM")