UM-Bridge with QMCPy
Using QMCPy to evaluate the UM-Bridge Cantilever Beam Function and approximate the expectation with respect to a uniform random variable.
Imports
import umbridge
import qmcpy as qp
Start Docker Container
See the UM-Bridge Documentation for image options.
!docker run --name muqbp -d -it -p 4243:4243 linusseelinger/benchmark-muq-beam-propagation:latest
7a3e14da277ea399631bc006a890e5217fb7b7b425fcb2c811a8fa2c77a1a68a
Problem Setup
Initialize a QMCPy sampler and distribution.
sampler = qp.DigitalNetB2(dimension=3,seed=7) # DISCRETE DISTRIBUTION
distribution = qp.Uniform(sampler,lower_bound=1,upper_bound=1.05) # TRUE MEASURE
Initialize a UM-Bridge model and wrap it into a QMCPy compatible Integrand
model = umbridge.HTTPModel('http://localhost:4243','forward')
umbridge_config = {"d": sampler.d}
integrand = qp.UMBridgeWrapper(distribution,model,umbridge_config,parallel=False) # INTEGRAND
Model Evaluation
x = sampler(16) # same as sampler.gen_samples(16)
y = integrand.f(x)
print(y.shape)
print(type(y))
print(y.dtype)
(16, 31)
<class 'numpy.ndarray'>
float64
Automatically Approximate the Expectation
qmc_stop_crit = qp.CubQMCNetG(integrand,abs_tol=2.5e-2) # QMC STOPPING CRITERION
solution,data = qmc_stop_crit.integrate()
print(data)
LDTransformData (AccumulateData Object)
solution [ 0. 3.855 14.69 ... 898.921 935.383 971.884]
comb_bound_low [ 0. 3.854 14.688 ... 898.901 935.363 971.863]
comb_bound_high [ 0. 3.855 14.691 ... 898.941 935.404 971.906]
comb_flags [ True True True ... True True True]
n_total 2^(11)
n [1024. 1024. 1024. ... 2048. 2048. 2048.]
time_integrate 7.534
CubQMCNetG (StoppingCriterion Object)
abs_tol 0.025
rel_tol 0
n_init 2^(10)
n_max 2^(35)
UMBridgeWrapper (Integrand Object)
Uniform (TrueMeasure Object)
lower_bound 1
upper_bound 1.050
DigitalNetB2 (DiscreteDistribution Object)
d 3
dvec [0 1 2]
randomize LMS_DS
graycode 0
entropy 7
spawn_key ()
from matplotlib import pyplot
pyplot.style.use('../qmcpy.mplstyle')
fig,ax = pyplot.subplots(figsize=(6,3))
ax.plot(solution,'-o')
ax.set_xlim([0,len(solution)-1]); ax.set_xlabel(r'$x$')
ax.set_ylim([1000,-10]); ax.set_ylabel(r'$u(x)$');

Parallel Evaluation
QMCPy can automatically multi-threaded requests to the model by setting
parallel=p
where p
is the number of processors used by
multiprocessing.pool.ThreadPool.
Setting parallel=True
is equivalent to setting
paralle=os.cpu_count()
.
import os
print('Available CPUs: %d'%os.cpu_count())
Available CPUs: 12
integrand = qp.UMBridgeWrapper(distribution,model,umbridge_config,parallel=8)
solution,data = qp.CubQMCNetG(integrand,abs_tol=2.5e-2).integrate()
data
LDTransformData (AccumulateData Object)
solution [ 0. 3.855 14.69 ... 898.921 935.383 971.884]
comb_bound_low [ 0. 3.854 14.688 ... 898.901 935.363 971.863]
comb_bound_high [ 0. 3.855 14.691 ... 898.941 935.404 971.906]
comb_flags [ True True True ... True True True]
n_total 2^(11)
n [1024. 1024. 1024. ... 2048. 2048. 2048.]
time_integrate 3.198
CubQMCNetG (StoppingCriterion Object)
abs_tol 0.025
rel_tol 0
n_init 2^(10)
n_max 2^(35)
UMBridgeWrapper (Integrand Object)
Uniform (TrueMeasure Object)
lower_bound 1
upper_bound 1.050
DigitalNetB2 (DiscreteDistribution Object)
d 3
dvec [0 1 2]
randomize LMS_DS
graycode 0
entropy 7
spawn_key ()
Shut Down Docker Image
!docker rm -f muqbp
IOStream.flush timed out
muqbp