-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add QMCPy L2-Sea client for tutorial
- Loading branch information
1 parent
9797602
commit c5e0573
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import argparse | ||
import qmcpy as qp | ||
from qmcpy.integrand.um_bridge_wrapper import UMBridgeWrapper | ||
import numpy as np | ||
import umbridge | ||
|
||
# Read URL from command line argument | ||
parser = argparse.ArgumentParser(description='QMCPy with UM-Bridge model demo.') | ||
parser.add_argument('url', metavar='url', type=str, | ||
help='the URL at which the model is running, for example http://localhost:4242') | ||
args = parser.parse_args() | ||
print(f"Connecting to host URL {args.url}") | ||
|
||
# Wrap a given model and fix its last parameters to 0 | ||
class TwoInputModel: | ||
def __init__(self, model): | ||
self.model = model | ||
|
||
def get_input_sizes(self, config={}): | ||
return [2] | ||
|
||
def get_output_sizes(self, config={}): | ||
return self.model.get_output_sizes() | ||
|
||
def __call__(self, theta, config={}): | ||
return self.model([[theta[0][0], theta[0][1], 0,0,0,0,0,0,0,0,0,0,0,0,0,0]], config) | ||
|
||
def supports_evaluate(self): | ||
return True | ||
|
||
|
||
# Set up umbridge model and model config | ||
l2sea_model = umbridge.HTTPModel(args.url, "forward") | ||
l2sea_fixed_design_params = TwoInputModel(l2sea_model) | ||
config = {"fidelity": 7} | ||
|
||
# Get input dimension from model | ||
d = l2sea_fixed_design_params.get_input_sizes(config)[0] | ||
|
||
# Froud [0.25,0.41] | ||
# Draft [-6.6, -5.7] | ||
# Choose a distribution to sample via QMC | ||
dnb2 = qp.DigitalNetB2(d) | ||
gauss_sobol = qp.Uniform(dnb2, lower_bound=[0.25,-6.6], upper_bound=[0.41,-5.7]) | ||
|
||
integrand = UMBridgeWrapper(gauss_sobol, l2sea_fixed_design_params, config, parallel=False) | ||
|
||
qmc_sobol_algorithm = qp.CubQMCSobolG(integrand, abs_tol=1e-1) | ||
solution,data = qmc_sobol_algorithm.integrate() | ||
print(data) |