Please make sure that you have access to a UQCloud endpoint.
To do so, navigate to the "Profile" section and below the section "UQCloud access", note the endpoint URL and your personal access Token.
Those are necessary for UQ[py]Lab to successfully perform UQ computations on the cloud.
To install the package in your local Python environment, execute the following command:
xxxxxxxxxx
pip install uqpylab
Notes:
The following minimal example can be used to quickly test UQ[py]Lab after installation.
Create a new python script, say draw_samples.py and add the following contents:
xxxxxxxxxx
from uqpylab import sessions
myToken = 'your token here' # The user's token to access the UQCloud API
UQCloud_instance = 'https://XXXX.uq-cloud.io' # The UQCloud instance to use
# Start the session
mySession = sessions.cloud(host=UQCloud_instance, token=myToken)
# (Optional) Get a convenient handle to the command line interface
uq = mySession.cli
# Reset the session
mySession.reset()
# Specify the options for a bivariate normal random vector
InputOpts = {
'Marginals': [
{
'Type': 'Gaussian',
'Parameters': [0,1]
},
{
'Type': 'Gaussian',
'Parameters': [0,1]
}
]
}
# Create the bivariate normal random vector
myInput = uq.createInput(InputOpts)
# Draw 10 samples from the bivariate normal distribution
theSamples = uq.getSample(myInput, 10)
Notice that in the quick start example one has to explicitly specify the UQCloud endpoint URL and their token in order to gain access to the UQCloud API. You can follow the steps below to store your credentials locally and simplify the UQCloud session starting process in your python scripts.
Start an interactive python session
xxxxxxxxxx
python -i
Import sessions
from the uqpylab
package:
xxxxxxxxxx
from uqpylab import sessions
Start a new UQCloud session using the standard procedure:
xxxxxxxxxx
mySession = sessions.cloud(host="the instance URL", token="your token")
Make sure that your session has successfully started, i.e. your credentials are correct. Then execute the following command to store your credentials locally:
xxxxxxxxxx
mySession.save_config()
You are all set! From now on, you can start a new UQCloud session in any of your scripts by simply executing:
xxxxxxxxxx
mySession = sessions.cloud()
Your credentials will be stored within a directory in your user's home that depends on your operating system. The actual path that they are stored is reported after calling the save_config()
function.
Some users may experience the following error when they try to start a new session:
xxxxxxxxxx
URLError: verify failed: certificate has expired (_ssl.c:1123)
The underlying cause is rather operating system related and this error is typically appearing and disappearing as the operating system updates. The following workaround can be used to bypass this error:
xxxxxxxxxx
from uqpylab import sessions
myToken = 'your token here' # The user's token to access the UQCloud API
UQCloud_instance = 'https://XXXX.uq-cloud.io' # The UQCloud instance to use
# Start the session
mySession = sessions.cloud(host=UQCloud_instance, token=myToken, strict_ssl=False)
Notice that the difference compared to the standard way of starting a new session is that we set the flag strict_ssl
to False
. This will bypass the SSL certificate validation steps that are taking place during connection. This is done by disabling the host's SSL certificate check while using the urllib.request library, which is handling all calls to the UQCloud API.
Note: Please make sure that you understand the potential risks of resorting to this workaround before using it!