SURGroup / UQpy

UQpy (Uncertainty Quantification with python) is a general purpose Python toolbox for modeling uncertainty in physical and mathematical systems.
MIT License
267 stars 75 forks source link

'type' object is not subscriptable?=> an error related with class Copula(ABC)? #187

Closed LMedinaU closed 1 year ago

LMedinaU commented 1 year ago

Hi, I'm trying to run the sdof_boucwen_prop example, from spyder 5.2.2, after installing from conda (Anaconda) using conda install -c conda-forge uqpy. When running: from UQpy.RunModel import RunModel dyn_model_prop = RunModel( model_script='utils_dynamics.py', model_object_name='sdof_boucwen_prop', ntasks=1, time_vec=np.arange(0., 40.01, 0.02), vec=False, var_names=['k', 'r0', 'delta', 'n', 'input_accel'])

I got the following:


File "C:\Users\Luis Medina\anaconda3\envs\UQ\lib\site-packages\UQpy\distributions\baseclass\Copula.py", line 7, in class Copula(ABC):

File "C:\Users\Luis Medina\anaconda3\envs\UQ\lib\site-packages\UQpy\distributions\baseclass\Copula.py", line 47, in Copula def check_marginals(marginals: list[DistributionContinuous1D]):

TypeError: 'type' object is not subscriptable


I apologize in advance if I'm doing something wrong, but I would really appreciate any suggestion to solve this. Thanks,

Luis

dimtsap commented 1 year ago

Hi Luis,

The latest UQpy version requires python >=3.9. This error usually appears when UQpy version 4 is used with older python versions. Please let me know if this fix works for you!

LMedinaU commented 1 year ago

Hi Dimitris, Thanks a lot for your prompt answer. I updated to 3.9.12, but now I got this:


File "C:\Users\Luis Medina\anaconda3\envs\UQ\lib\site-packages\UQpy\distributions\copulas__init__.py", line 1, in from UQpy.distributions.copulas.Gumbel import Gumbel

File "C:\Users\Luis Medina\anaconda3\envs\UQ\lib\site-packages\UQpy\distributions\copulas\Gumbel.py", line 5, in from beartype import beartype ModuleNotFoundError: No module named 'beartype'


Maybe, do I have to downgrade to python 3.9 ?

Thanks again

dimtsap commented 1 year ago

Try pip install beartype ==0.9.1 and this last error should disappear.

LMedinaU commented 1 year ago

Dimitris, I'm sorry to bother you again. After several attempts the following is the "best" message I got: ___- dyn_model_prop = uq.RunModel(

File @.***(UQpy.run_model.RunModel.RunModel.init) at 0x1b1b08eeca0>", line 112, in init

TypeError: init() got an unexpected keyword argument 'modelscript' ____- This is the simple script I am trying to run at my env created with conda ( uqpy 4.0.3, Spyder 5.2.2, Python 3.9.12, beartype 0.10.4 (I couldn't install a previous version using Anaconda)):

import numpy as np import matplotlib.pyplot as plt import UQpy as uq from utils_dynamics import *

dyn_model_prop = uq.RunModel( model_script='utils_dynamics.py', model_object_name='sdof_boucwen_prop', ntasks=1, time_vec=np.arange(0., 40.01, 0.02), vec=False, var_names=['k', 'r0', 'delta', 'n', 'input_accel'])


Thanks for any suggestion about it to move forward.

Regards, Luis

On Tue, Aug 9, 2022 at 1:55 AM Dimitris Tsapetis @.***> wrote:

Try pip install beartype ==0.9.1 and this last error should disappear.

— Reply to this email directly, view it on GitHub https://github.com/SURGroup/UQpy/issues/187#issuecomment-1208946588, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWTJL4SNFLTT6YQX37QAKPLVYHXDJANCNFSM556QGDCA . You are receiving this because you authored the thread.Message ID: @.***>

dimtsap commented 1 year ago

A new release is published that will fix this issue. I will let you know as soon it is available on conda-forge.

LMedinaU commented 1 year ago

Thanks a lot.👍

El mar., 9 de agosto de 2022 11:50, Dimitris Tsapetis < @.***> escribió:

A new release is published that will fix this issue. I will let you know as soon it is available on conda-forge.

— Reply to this email directly, view it on GitHub https://github.com/SURGroup/UQpy/issues/187#issuecomment-1209565733, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWTJL4XP3P353PSL3JJRX7LVYJ447ANCNFSM556QGDCA . You are receiving this because you authored the thread.Message ID: @.***>

dimtsap commented 1 year ago

The latest conda-forge release (4.0.4) includes with all required dependencies, including beartype. You can download it using the following command:

conda install -c conda-forge uqpy=4.0.4

Please let me know if this works for you!

LMedinaU commented 1 year ago

Hi Dimitris, Thank you again for your answer. I installed latest conda-forge, as you suggested, and it seems to be working. But I had to modify my script to get same results showed in the example given in Dynamics.ipynb . The issue, I guess, is in arguments requested by the RunModel function that I am using are not the same required by the RunModel function in Dynamics.ipynb , is this possible?

I would like to use the same function RunModel that is invoked in the example Dynamics.ipynb, but I couldn't. In fact, I had to edit the sdof_boucwen_prop function in order to require only samples as argument. Therefore, for my modified sdof_boucwen_prop function time vector is not an argument . Here is my "solution", although it isn´t like me:


import numpy as np import matplotlib.pyplot as plt from utils_dynamics import * from UQpy.run_model.model_execution.PythonModel import PythonModel from UQpy.run_model.RunModel import RunModel

_, accel = read_elcentro(scale=0.1)

samples = [[np.array(1.0).reshape((-1,)), np.array(2.5).reshape((-1,)), np.array(0.9).reshape((-1,)), np.array(3.).reshape((-1,)), accel], ] m = PythonModel(model_script='utils_dynamics.py', model_object_name='sdof_boucwen_prop',var_names=['k', 'r0', 'delta', 'n', 'input_accel'])

dyn_model_prop = RunModel (model=m, ntasks=1) # Seems that for this RunModel function the arguments are different from the RunModel used in Dynamics.ipynb . Is that correct? dyn_model_prop.run(samples) qoi = dyn_model_prop.qoi_list[0] [1. 2.5 0.9 3. ] [ 0.5991 0.1857 0.68 ... -0.1808 -0.5598 -0.7639] #same result that Dynamics.ipynb . The edited sdof_boucwen_prop function only asks for samples as argument.


I will try to find if I can get this result but using the same, or similar, script given in Dynamics.ipynb, which I think is neater than my script. Thanks for your attention.

Luis.

On Wed, Aug 10, 2022 at 3:23 AM Dimitris Tsapetis @.***> wrote:

The latest conda-forge release (4.0.4) includes with all required dependencies, including beartype. You can download it using the following command:

conda install -c conda-forge uqpy=4.0.4

Please let me know if this works for you!

— Reply to this email directly, view it on GitHub https://github.com/SURGroup/UQpy/issues/187#issuecomment-1210267228, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWTJL4USM7VA2264INXKZY3VYNKGNANCNFSM556QGDCA . You are receiving this because you authored the thread.Message ID: @.***>

dimtsap commented 1 year ago

@LMedinaU if I understand correctly you are refering to the Dynamics.ipynb example that exists in https://github.com/SURGroup/UQpy_paper/tree/master/Section2_RunModel/Section2.2_DynamicsExample of the UQpy paper.

This example was created with a previous version of UQpy (3.0.0). The current version (4.0.0) has undergone a major refactoring and backwards compatibility is broken in many UQpy functions to allow for extensibilty and in the case of RunModel execution in HPC environments.

If you want to execute this example in the previous UQpy version, we accomodate this option using Binder. (https://mybinder.org/v2/gh/SURGroup/UQpy_paper/master)

I will close this issue, as the main error you initially had seems to be resolved. I encourage you to have a look at the current documentation of RunModel (https://uqpyproject.readthedocs.io/en/latest/auto_examples/RunModel/python_example.html)

In case you still face any issues with the conversion from the previous version, I suggest we start a discussion on how to perform that here. (https://github.com/SURGroup/UQpy/discussions)

LMedinaU commented 1 year ago

Thanks @dimtsap