# TODO: FIND ALTERNATIVE TO THIS PYTHONPATH HACK import os import sys # PYTHONPATH is not found when running mpiexec, # so inject it so that we can load SROMPy modules... if 'PYTHONPATH' not in os.environ: base_path = os.path.abspath('.') sys.path.insert(0, base_path) sys.path.insert(0, os.path.join(base_path, 'SROMPy')) from SROMPy.srom import SROM from SROMPy.target import BetaRandomVariable # Random variable to optimize to. random_variable = BetaRandomVariable(alpha=3., beta=2., shift=1., scale=2.5) # Run each SROM optimization 10 times to generate performance data. performance_data = [] # Get MPI information. comm = MPI.COMM_WORLD # Load previously saved scalability data if available. data_filename = os.path.join("data", "weak_scalability_data.txt") if os.path.isfile(data_filename): if comm.rank == 0: print 'Loading previously saved data set for modification:'
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import numpy as np from model import SpringMass1D from SROMPy.postprocess import Postprocessor from SROMPy.srom import SROM, FiniteDifference as FD, SROMSurrogate from SROMPy.target import SampleRandomVector, BetaRandomVariable # Random variable for spring stiffness. stiffness_random_variable = \ BetaRandomVariable(alpha=3., beta=2., shift=1., scale=2.5) # Specify spring-mass system: m = 1.5 # Deterministic mass. state0 = [0., 0.] # Initial conditions. t_grid = np.arange(0., 10., 0.1) # Time. # Initialize model, model = SpringMass1D(m, state0, t_grid) # ----------Monte Carlo------------------ # Generate stiffness input samples for Monte Carlo. num_samples = 5000 stiffness_samples = stiffness_random_variable.draw_random_sample(num_samples)