Skip to content

Commit 13ea879

Browse files
tomolearydc-luo
andauthored
Optimization Under Uncertainty (#18)
* test for branch * test for branch * existing unit tests pass, we need new ones ofcourse * fixed an initialization specification that was breaking a unit test * working on adding control jacobian sampling capabilities * parameter dimension needs to be set in all cases * parameter rank instead of rank * working on the pull request a bit more, a little bit more work needed then some stress testing * error tests not implemented yet for control problems, this is a more laborious and orthogonal effort. it will be made into an issue. * nevermind I modified all of the error tests to accomodate control variable. Have not tested it yet * adding mass and stiffness matrix saving method * asci character issue * directory name already known etc * thanks dc for spotting the error * stiffness and mass matrices need to get the mesh constructor communicator * mass and stiffness matrices should only be computed on rank 0 * updating the active subspace to have custom naming, now gonna loop around AS batch size * also just changing the naming convention for AS to always include the size * updating kle projector * typo in accessing collective * adding meanJTJ wrapper to compute AS from sample data * removing wild imports, should temporarily fix the NullCollective issue for KLE specifically * removed np.int from collective, which is deprecated from newer numpy versions. Same as int. * changed wildcard hippylib imports * trying to remove wild imports in as projector class * param list in in hp * removed path modifications from cMinimization * infinite loop * another infinite loop. thanks for catching bassel * addressing DCs comments --------- Co-authored-by: dcluo <dc.luo@outlook.com>
1 parent 4d23366 commit 13ea879

17 files changed

+912
-363
lines changed

hippyflow/collectives/collective.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def allReduce(self, v, op):
8787
self._allReduce_array(v_array, op)
8888
return v_array[0]
8989

90-
elif type(v) in [int, np.int, np.int32]:
90+
elif type(v) in [int, np.int32]:
9191
v_array = np.array([v], dtype=np.int32)
9292
self._allReduce_array(v_array, op)
9393
return v_array[0]
@@ -126,7 +126,7 @@ def bcast(self, v, root = 0):
126126
broadcasted lives.
127127
"""
128128

129-
if type(v) in [float, np.float64,int, np.int, np.int32]:
129+
if type(v) in [float, np.float64, int, np.int32]:
130130
v_array = np.array([v])
131131
self.comm.Bcast(v_array,root = root)
132132
return v_array[0]

hippyflow/modeling/KLEProjector.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
import dolfin as dl
1515
import numpy as np
1616
import os
17-
from hippylib import *
1817
from mpi4py import MPI
1918
import time
2019

20+
import hippylib as hp
21+
22+
from ..collectives.collective import NullCollective
2123
from ..collectives.collectiveOperator import CollectiveOperator
2224
from ..collectives.comm_utils import checkMeshConsistentPartitioning
2325
from .jacobian import *
@@ -30,16 +32,14 @@ def KLEParameterList():
3032
This function implements the parameter list for the KLE object
3133
"""
3234
parameters = {}
33-
parameters['sample_per_process'] = [100, 'Number of samples per process']
3435
parameters['error_test_samples'] = [50, 'Number of samples for error test']
35-
parameters['rank'] = [128, 'Rank of subspace']
36-
parameters['oversampling'] = [10, 'Oversampling parameter for randomized algorithms']
37-
parameters['verbose'] = [True, 'Boolean for printing']
38-
36+
parameters['rank'] = [128, 'Rank of subspace']
37+
parameters['oversampling'] = [10, 'Oversampling parameter for randomized algorithms']
38+
parameters['verbose'] = [True, 'Boolean for printing']
3939
parameters['output_directory'] = [None,'output directory for saving arrays and plots']
4040
parameters['plot_label_suffix'] = ['', 'suffix for plot label']
4141

42-
return ParameterList(parameters)
42+
return hp.ParameterList(parameters)
4343

4444
class MRinvM:
4545
"""
@@ -106,10 +106,10 @@ def random_input_projector(self):
106106
"""
107107
m_KLE = dl.Vector(self.mesh_constructor_comm)
108108
self.prior.M.init_vector(m_KLE,0)
109-
Omega = MultiVector(m_KLE,self.parameters['rank'] + self.parameters['oversampling'])
109+
Omega = hp.MultiVector(m_KLE,self.parameters['rank'] + self.parameters['oversampling'])
110110

111111
if self.collective.rank() == 0:
112-
parRandom.normal(1.,Omega)
112+
hp.parRandom.normal(1.,Omega)
113113
Omega.orthogonalize()
114114
else:
115115
Omega.zero()
@@ -133,22 +133,22 @@ def construct_input_subspace(self,M_orthogonal = True):
133133

134134
m_KLE = dl.Vector(self.mesh_constructor_comm)
135135
KLE_Operator.init_vector(m_KLE,0)
136-
Omega = MultiVector(m_KLE,self.parameters['rank'] + self.parameters['oversampling'])
136+
Omega = hp.MultiVector(m_KLE,self.parameters['rank'] + self.parameters['oversampling'])
137137

138138
if self.collective.rank() == 0:
139-
parRandom.normal(1.,Omega)
139+
hp.parRandom.normal(1.,Omega)
140140
else:
141141
Omega.zero()
142142

143143
self.collective.bcast(Omega,root = 0)
144144

145145
if M_orthogonal:
146-
self.d_KLE, self.V_KLE = doublePassG(KLE_Operator,\
146+
self.d_KLE, self.V_KLE = hp.doublePassG(KLE_Operator,\
147147
self.prior.M, self.prior.Msolver, Omega,self.parameters['rank'],s=1)
148148
self.M_orthogonal = True
149149
else:
150-
RsolverOperator = Solver2Operator(self.prior.Rsolver)
151-
self.d_KLE, self.V_KLE = doublePass(RsolverOperator, Omega,self.parameters['rank'],s=1)
150+
RsolverOperator = hp.Solver2Operator(self.prior.Rsolver)
151+
self.d_KLE, self.V_KLE = hp.doublePass(RsolverOperator, Omega,self.parameters['rank'],s=1)
152152
self.M_orthogonal = False
153153

154154
self._subspace_construction_time = time.time() - t0
@@ -202,15 +202,15 @@ def test_errors(self, ranks = [None],cut_off = 1e-12):
202202
projection_vector = dl.Vector(self.mesh_constructor_comm)
203203
self.prior.init_vector(projection_vector,0)
204204

205-
LocalParameters = MultiVector(projection_vector,self.parameters['error_test_samples'])
205+
LocalParameters = hp.MultiVector(projection_vector,self.parameters['error_test_samples'])
206206
LocalParameters.zero()
207207
# Generate samples
208208
for i in range(self.parameters['error_test_samples']):
209209
t0 = time.time()
210-
parRandom.normal(1,self.noise)
210+
hp.parRandom.normal(1,self.noise)
211211
self.prior.sample(self.noise,LocalParameters[i])
212212

213-
LocalErrors = MultiVector(projection_vector,self.parameters['error_test_samples'])
213+
LocalErrors = hp.MultiVector(projection_vector,self.parameters['error_test_samples'])
214214

215215

216216
for rank_index,rank in enumerate(ranks):
@@ -227,7 +227,7 @@ def test_errors(self, ranks = [None],cut_off = 1e-12):
227227
if self.M_orthogonal:
228228
InputProjectorOperator = PriorPreconditionedProjector(V_KLE,self.prior.M, input_init_vector_lambda)
229229
else:
230-
InputProjectorOperator = LowRankOperator(np.ones_like(d_KLE),V_KLE, input_init_vector_lambda)
230+
InputProjectorOperator = hp.LowRankOperator(np.ones_like(d_KLE),V_KLE, input_init_vector_lambda)
231231

232232
rel_errors = np.zeros(LocalErrors.nvec())
233233
for i in range(LocalErrors.nvec()):

0 commit comments

Comments
 (0)