Open acse-yw11823 opened 5 months ago
The package is archived and I think it only supported Intel macos and Python 3.7, which was never ported to ARM macs.
Many thanks for the reply. My current version of pyrhon is :
(firedrake) (base) yw11823@IC-FVFL80FW1WGC demos % python --version
Python 3.11.9
And I will go through the links now.
Hello, I did what I could do so far and also asked my professor. I am currently using the Mac Apple M1. Should I download the SeismicMesh file following the link https://pypi.org/project/SeismicMesh/3.6.2/#files and install through it again? Or there is no way I can use this package on my laptop :(
The package is archived, which means no one can update it or even open an issue. If you want to resurrect it, you'll likely need to fork it and maintain your own copy. Unless you are willing to do that, you'll probably want to look around for a maintained library instead.
I think the problem you are initially facing is that homebrew on Apple Silicon installs to /opt/homebrew
instead of /usr/local
, and it doesn't know to look there. You might be able to progress farther if you set:
export LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/lib
export INCLUDE_PATH=$INCLUDE_PATH:/opt/homebrew/include
Edit: it's not respecting those variables; even on an Intel Mac it needs /usr/local/lib
and it's not present.
But no promises for abandonware!
Also, I recommend using a non-Conda Python if you are not installing with conda, especially if you are building packages from source. Conda's packages are compiled with it's own compiler stack, and it's really only designed to be used with Conda-build in a controlled environment (like the one conda-forge uses). You can get Python from official installers, homebrew, etc. But so far, that's not your problem (and it probably is fine most of the time).
I was able to get it to build on 3.12 (on Intel, no idea if it works) by cloning it, and adding the following hard coded paths to setup.cfg
:
[build_ext]
include-dirs = /usr/local/include
library-dirs = /usr/local/lib
(You'll want to replace /usr/local
with /opt/homebrew
on your machine, I'm not using Apple Silicon as my daily driver yet). With brew install gmp cgal
first, it built with pip install -v .
.
If you want to fork and maintain, a better solution would be to switch to scikit-build-core; there's already a CMakeLists, you'd just need to update that, and CMake would find the libraries for you. I can start that if you are interested, but I can't maintain long-term. ;)
Many thanks!!!! Will hae a look now
Thanks a lot!!!!! It works by using this method!!! I do appreciate your time! thanksss
I was able to get it to build on 3.12 (on Intel, no idea if it works) by cloning it, and adding the following hard coded paths to
setup.cfg
:[build_ext] include-dirs = /usr/local/include library-dirs = /usr/local/lib
(You'll want to replace
/usr/local
with/opt/homebrew
on your machine, I'm not using Apple Silicon as my daily driver yet). Withbrew install gmp cgal
first, it built withpip install -v .
.If you want to fork and maintain, a better solution would be to switch to scikit-build-core; there's already a CMakeLists, you'd just need to update that, and CMake would find the libraries for you. I can start that if you are interested, but I can't maintain long-term. ;)
I've tried making a scikit-build-core version, would you like to try:
pip install -v git+https://github.com/henryiii/SeismicMesh
? Changes: https://github.com/henryiii/SeismicMesh/commit/a9482b057346b9b38e7e5c2e5db76ec08bfe7cab
Oops, forgot pybind11. Added.
Hello, this might be a bit random but I have a ROL-related error when I running the seismic imaging model. This is my code:
from firedrake import *
import numpy as np
import finat
from ROL.firedrake_vector import FiredrakeVector as FeVector
import ROL
from mpi4py import MPI
import spyro
# import gc
outdir = "fwi_p5/"
model = {}
model["opts"] = {
"method": "KMV", # either CG or KMV
"quadrature": "KMV", # Equi or KMV
"degree": 5, # p order
"dimension": 2, # dimension
"regularization": True, # regularization is on?
"gamma": 1.0e-6, # regularization parameter
}
model["parallelism"] = {
"type": "spatial",
}
model["mesh"] = {
"Lz": 3.5, # depth in km - always positive
"Lx": 17.0, # width in km - always positive
"Ly": 0.0, # thickness in km - always positive
"meshfile": "/Users/yw11823/ACSE/irp/spyro/paper/FWI_2D_DATA/meshes/marmousi_exact.msh",
"initmodel": "/Users/yw11823/ACSE/irp/spyro/paper/FWI_2D_DATA/velocity_models/marmousi_exact.hdf5",
"truemodel": "not_used.hdf5",
}
model["BCs"] = {
"status": True, # True or false
"outer_bc": "non-reflective", # None or non-reflective (outer boundary condition)
"damping_type": "polynomial", # polynomial, hyperbolic, shifted_hyperbolic
"exponent": 2, # damping layer has a exponent variation
"cmax": 4.5, # maximum acoustic wave velocity in PML - km/s
"R": 1e-6, # theoretical reflection coefficient
"lz": 0.9, # thickness of the PML in the z-direction (km) - always positive
"lx": 0.9, # thickness of the PML in the x-direction (km) - always positive
"ly": 0.0, # thickness of the PML in the y-direction (km) - always positive
}
model["acquisition"] = {
"source_type": "Ricker",
"num_sources": 40,
"source_pos": spyro.create_transect((-0.01, 1.0), (-0.01, 15.0), 40),
"frequency": 5.0,
"delay": 1.0,
"num_receivers": 500,
"receiver_locations": spyro.create_transect((-0.10, 0.1), (-0.10, 17.0), 500),
}
model["timeaxis"] = {
"t0": 0.0, # Initial time for event
"tf": 6.00, # Final time for event
"dt": 0.001,
"amplitude": 1, # the Ricker has an amplitude of 1.
"nspool": 1000, # how frequently to output solution to pvds
"fspool": 10, # how frequently to save solution to RAM
}
comm = spyro.utils.mpi_init(model)
# if comm.comm.rank == 0 and comm.ensemble_comm.rank == 0:
# fil = open("FUNCTIONAL_FWI_P5.txt", "w")
mesh, V = spyro.io.read_mesh(model, comm)
vp = spyro.io.interpolate(model, mesh, V, guess=True)
if comm.ensemble_comm.rank == 0:
File("guess_velocity.pvd", comm=comm.comm).write(vp)
sources = spyro.Sources(model, mesh, V, comm)
receivers = spyro.Receivers(model, mesh, V, comm)
wavelet = spyro.full_ricker_wavelet(
dt=model["timeaxis"]["dt"],
tf=model["timeaxis"]["tf"],
freq=model["acquisition"]["frequency"],
)
if comm.ensemble_comm.rank == 0:
control_file = File(outdir + "control.pvd", comm=comm.comm)
grad_file = File(outdir + "grad.pvd", comm=comm.comm)
quad_rule = finat.quadrature.make_quadrature(
V.finat_element.cell, V.ufl_element().degree(), "KMV"
)
dxlump = dx(scheme=quad_rule)
water = np.where(vp.dat.data[:] < 1.51)
class L2Inner(object):
def __init__(self):
self.A = assemble(
TrialFunction(V) * TestFunction(V) * dxlump, mat_type="matfree"
)
self.Ap = as_backend_type(self.A).mat()
def eval(self, _u, _v):
upet = as_backend_type(_u).vec()
vpet = as_backend_type(_v).vec()
A_u = self.Ap.createVecLeft()
self.Ap.mult(upet, A_u)
return vpet.dot(A_u)
kount = 0
def regularize_gradient(vp, dJ, gamma):
"""Tikhonov regularization"""
m_u = TrialFunction(V)
m_v = TestFunction(V)
mgrad = m_u * m_v * dx(scheme=qr_x)
ffG = dot(grad(vp), grad(m_v)) * dx(scheme=qr_x)
G = mgrad - ffG
lhsG, rhsG = lhs(G), rhs(G)
gradreg = Function(V)
grad_prob = LinearVariationalProblem(lhsG, rhsG, gradreg)
grad_solver = LinearVariationalSolver(
grad_prob,
solver_parameters={
"ksp_type": "preonly",
"pc_type": "jacobi",
"mat_type": "matfree",
},
)
grad_solver.solve()
dJ += gamma * gradreg
return dJ
class Objective(ROL.Objective):
def __init__(self, inner_product):
ROL.Objective.__init__(self)
self.inner_product = inner_product
self.p_guess = None
self.misfit = 0.0
self.p_exact_recv = spyro.io.load_shots(model, comm)
def value(self, x, tol):
"""Compute the functional"""
J_total = np.zeros((1))
self.p_guess, p_guess_recv = spyro.solvers.forward(
model,
mesh,
comm,
vp,
sources,
wavelet,
receivers,
)
self.misfit = spyro.utils.evaluate_misfit(
model, p_guess_recv, self.p_exact_recv
)
J_total[0] += spyro.utils.compute_functional(model, self.misfit, velocity=vp)
J_total = COMM_WORLD.allreduce(J_total, op=MPI.SUM)
J_total[0] /= comm.ensemble_comm.size
if comm.comm.size > 1:
J_total[0] /= comm.comm.size
return J_total[0]
def gradient(self, g, x, tol):
"""Compute the gradient of the functional"""
dJ = Function(V, name="gradient")
dJ_local = spyro.solvers.gradient(
model,
mesh,
comm,
vp,
receivers,
self.p_guess,
self.misfit,
)
if comm.ensemble_comm.size > 1:
comm.allreduce(dJ_local, dJ)
else:
dJ = dJ_local
dJ /= comm.ensemble_comm.size
if comm.comm.size > 1:
dJ /= comm.comm.size
# regularize the gradient if asked.
if model["opts"]["regularization"]:
gamma = model["opts"]["gamma"]
dJ = regularize_gradient(vp, dJ, gamma)
# mask the water layer
dJ.dat.data[water] = 0.0
# Visualize
if comm.ensemble_comm.rank == 0:
grad_file.write(dJ)
g.scale(0)
g.vec += dJ
def update(self, x, flag, iteration):
vp.assign(Function(V, x.vec, name="velocity"))
# If iteration reduces functional, save it.
if iteration >= 0:
if comm.ensemble_comm.rank == 0:
control_file.write(vp)
paramsDict = {
"General": {"Secant": {"Type": "Limited-Memory BFGS", "Maximum Storage": 10}},
"Step": {
"Type": "Augmented Lagrangian",
"Augmented Lagrangian": {
"Subproblem Step Type": "Line Search",
"Subproblem Iteration Limit": 5.0,
},
"Line Search": {"Descent Method": {"Type": "Quasi-Newton Step"}},
},
"Status Test": {
"Gradient Tolerance": 1e-16,
"Iteration Limit": 100,
"Step Tolerance": 1.0e-16,
},
}
params = ROL.ParameterList(paramsDict, "Parameters")
inner_product = L2Inner()
obj = Objective(inner_product)
u = Function(V, name="velocity").assign(vp)
opt = FeVector(u.vector(), inner_product)
# Add control bounds to the problem (uses more RAM)
xlo = Function(V)
xlo.interpolate(Constant(1.0))
x_lo = FeVector(xlo.vector(), inner_product)
xup = Function(V)
xup.interpolate(Constant(5.0))
x_up = FeVector(xup.vector(), inner_product)
bnd = ROL.Bounds(x_lo, x_up, 1.0)
# Set up the line search
algo = ROL.Algorithm("Line Search", params)
algo.run(opt, obj, bnd)
if comm.ensemble_comm.rank == 0:
File("res.pvd", comm=comm.comm).write(obj.vp)
# fil.close()
And this is my error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[44], [line 238](vscode-notebook-cell:?execution_count=44&line=238)
[235](vscode-notebook-cell:?execution_count=44&line=235) bnd = ROL.Bounds(x_lo, x_up, 1.0)
[237](vscode-notebook-cell:?execution_count=44&line=237) # Set up the line search
--> [238](vscode-notebook-cell:?execution_count=44&line=238) algo = ROL.Algorithm("Line Search", params)
[240](vscode-notebook-cell:?execution_count=44&line=240) algo.run(opt, obj, bnd)
[242](vscode-notebook-cell:?execution_count=44&line=242) if comm.ensemble_comm.rank == 0:
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
1. _ROL.Algorithm(arg0: ROL::Step<double>, arg1: _ROL.StatusTest)
Invoked with: 'Line Search', <_ROL.ParameterList object at 0x17f3fc2f0>
I tried to solve it but no idea for now. By any chance, you might be familiar with this error. If you are not familiar that would be fine. I posted the discussion on PYROL GitHub but it seems like no one is there :(
Many thanks
Don’t know much about it, but from the pybind11 generated error message, the arguments here are wrong: ROL.Algorithm("Line Search", params)
. The first argument has to be a “Step” instance, but you passed a string. Second one has to be a ParameterList, which I’m guessing it might be.
Problem description
Hello, I am using the following to install the SeismicMesh but I meet the error, tried 3 hours to solve it now, pls help me code
error:
and I installed gmp where :
and I edited the terminal where