Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot create a consistent method resolution order (MRO) for bases object, mesh_tools #1187

Open
liaohaiyang1534 opened this issue Jul 12, 2023 · 5 comments

Comments

@liaohaiyang1534
Copy link

Hi,

Does anyone know how this problem should be solved?

image

image

I would appreciate it if anyone could provide some suggestions. If you need more details, please let me know.

Best
Haiyang Liao
522022290012@smail.nju.edu.cn

@danielpeter
Copy link
Contributor

thanks for pointing out! this is a python2 versus python3 issue. the current script seems to work only with python2. I'll submit a fix to cubit2specfem2d.py script in the devel version for python3 as soon as possible.

if you want to fix this in your version in the meantime, just remove the object argument in class mesh. that is, change class mesh(object,mesh_tools): to

class mesh(mesh_tools):

and this should do the trick to avoid the MRO error in python3 versions. unfortunately, you'll run into another issue with the sets class, which got replaced in python3 with set. you would need to replace all appearances of from sets import Set with

try:
    set
except NameError:
    from sets import Set as set

and use set(..) instead of Set(..).

regarding the MRO error:
in python 3, all classes inherit from object whereas in python2, this had to be done explicitly to get a new-style class. in our case with class mesh, it inherits the class mesh_tools which inherits class block_tools. for that last class definition, the object argument wasn't given explicitly, thus in python2 it was an old-style class definition. for class mesh now, the inheritance of object together with the mesh_tools class was still working. in python3, the class block_tools automatically has the inheritance to object, and so does class mesh_tools. having now the arguments ordered in this way (object, mesh_tools) the class dependency graph cannot resolve the ambiguity when to inherit from object. a quick fix for python3 is to remove the object argument in the class definition for mesh.

@liaohaiyang1534
Copy link
Author

Hi,

Thank you very much for your answer, but then I encountered another problem, it seems that there is no sets module in python3? I'm using python3.10.9

image

Best

@liaohaiyang1534
Copy link
Author

liaohaiyang1534 commented Jul 17, 2023

Hi,

Even though I've used Python 2.7 to execute the script, which should create a Cubit model and convert it to Specfem2d, the results aren't as expected. This is quite perplexing and frustrating

the code if needed:

#!/usr/bin/env python
from __future__ import print_function
import sys,os

dll_path = r"E:\coreform cubit\coreform cubit 2022.11\bin"
path = os.environ.get('PATH', '')
if dll_path not in path.split(';'):
    new_path = path + ';' + dll_path if path else dll_path
    os.environ['PATH'] = new_path

sys.path.append("E:\\coreforum cubit\\coreform cubit 2022.11\\bin")
sys.path.append("E:\\coreforum cubit\\coreform cubit 2022.11\\bin\\_cubit3.pyd")

cubit_path = r"E:\coreform cubit\coreform cubit 2022.11\bin"
python_path = os.environ.get('PYTHONPATH', '')
if cubit_path not in python_path.split(';'):
    new_python_path = python_path + ';' + cubit_path if python_path else cubit_path
    os.environ['PYTHONPATH'] = new_python_path

import cubit

pathToSpecfem = r'E:\specfem2d-master' 

if pathToSpecfem[-1] != '\\':
    pathToSpecfem = pathToSpecfem+'\\'

sys.path.append(pathToSpecfem+'utils\\cubit2specfem2d')

sys.path.insert(0, "E:/specfem2d-master/utils/cubit2specfem2d")

sys.path.append(r"E:\specfem2d-master")
sys.path.append(r"E:\specfem2d-master\utils\cubit2specfem2d")

import cubit2specfem2d
from cubit2specfem2d import mtools,block_tools,mesh_tools,mesh





cubit.cmd('reset')
cubit.cmd('create surface rectangle width 100 height 30')
cubit.cmd('surface all size 1')
cubit.cmd('mesh surface all')

profile=mesh()
profile.write("./MESH/")

the output if needed:
image

I have searched for many EXAMPLES of py scripts from specfem2d, but they all are the same. Even if they run successfully, they still cannot output the complete files needed by specfem2d.

I used to use specfem3d quite a lot. Now I want to try generating two-dimensional so I'm using specfem2d and openSWPC.

I'm simply trying to generate a simple two-dimensional layered medium, but I'm encountering too many difficulties...

@danielpeter
Copy link
Contributor

please try out the devel version of SPECFEM2D and the related script file - if this issue still persists, give more details about OS/python version/Cubit version etc. - and hopefully someone can help you out with your Windows installation.

regarding this one:

Hi,

Thank you very much for your answer, but then I encountered another problem, it seems that there is no sets module in python3? I'm using python3.10.9

image

Best

python3 recognizes the command set. your error shows that you're executing the script in a python 2 environment, which misses support for the sets module. this is likely an installation issue.

@AbolfazlKhanMo
Copy link

Hello!

Please take a look at the #1168 issue. I think this might help you.

All the best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants