AmirMardan / PyFWI

This repository is for PyFWI, a Python package for seismic FWI and reservoir monitoring (time-lapse FWI)
https://pyfwi.readthedocs.io/en/latest/
GNU General Public License v3.0
58 stars 12 forks source link

Problem with wavePropagator() #15

Closed daniel7arango closed 2 days ago

daniel7arango commented 1 month ago

Hi. I changed 'device' from 1 (GPU) to 0 (CPU) because I had another error. Then, I had this error:

RuntimeError: not all provided choices were used by choose_device. (left over: '0')


RuntimeError Traceback (most recent call last) Cell In[5], line 2 1 # Create the wave object ----> 2 W = wave.WavePropagator(inpa, src, rec_loc, model_shape, 3 n_well_rec=n_well_rec, 4 components=seisout, chpr=0) 6 # Call the forward modelling 7 d_obs = W.forward_modeling(model, show=False) # show=True can show the propagation of the wave

File ~/Documentos/PyFWI/lib/python3.10/site-packages/PyFWI/wave_propagation.py:621, in WavePropagator.init(self, inpa, src, rec_loc, model_shape, components, n_well_rec, chpr, set_env_variable) 620 def init(self, inpa, src, rec_loc, model_shape, components=0, n_well_rec=0, chpr=0, set_env_variable=True): --> 621 WavePreparation.init(self, inpa=inpa, src=src, rec_loc=rec_loc, model_shape=model_shape, components=components, 622 n_well_rec=n_well_rec, chpr=chpr, 623 set_env_variable=set_env_variable)

File ~/Documentos/PyFWI/lib/python3.10/site-packages/PyFWI/wave_propagation.py:181, in WavePreparation.init(self, inpa, src, rec_loc, model_shape, components, n_well_rec, chpr, set_env_variable) 178 os.environ['PYOPENCL_CTX'] = str(platform) + ':' + str(device) 179 os.environ['PYOPENCL_COMPILER_OUTPUT'] = '1' --> 181 self.ctx = cl.create_some_context() 182 self.queue = cl.CommandQueue(self.ctx) 184 kernel, kernel_crosswell, kernel_surface = self.kernel_caller()

File ~/Documentos/PyFWI/lib/python3.10/site-packages/pyopencl/init.py:1694, in create_some_context(interactive, answers) 1679 def create_some_context(interactive: Optional[bool] = None, 1680 answers: Optional[List[str]] = None) -> Context: 1681 """ 1682 Create a :class:Context 'somehow'. 1683 (...) 1692 :returns: an instance of :class:Context. 1693 """ -> 1694 devices = choose_devices(interactive, answers) 1696 return Context(devices)

File ~/Documentos/PyFWI/lib/python3.10/site-packages/pyopencl/init.py:1673, in choose_devices(interactive, answers) 1669 cc_print("Set the environment variable PYOPENCL_CTX='%s' to " 1670 "avoid being asked again." % ":".join(user_inputs)) 1672 if answers: -> 1673 raise RuntimeError("not all provided choices were used by " 1674 "choose_device. (left over: '%s')" % ":".join(answers)) 1676 return devices

RuntimeError: not all provided choices were used by choose_device. (left over: '0')

daniel7arango commented 1 month ago

Also tried to define inpa[] without 'device' and set_env_variable=False as in #5 but then I had this error on forward_modeling() object:

LogicError Traceback (most recent call last) Cell In[7], line 9 6 W = wave.WavePropagator(inpa, src, rec_loc, model_shape, components=seisout, chpr=20, set_env_variable=False) 8 # Call the forward modelling ----> 9 d_obs = W.forward_modeling(model, show=False) # show=True can show the propagation of the wave

File ~/Documentos/PyFWI/lib/python3.10/site-packages/PyFWI/wave_propagation.py:885, in WavePropagator.forward_modeling(self, model0, show) 883 self.pml_preparation(model['vp'].max()) 884 self.elastic_buffers(model) --> 885 seismo = self.forward_propagator(model) 886 data = acq.seismic_section(seismo, self.components, shape=self.seismo_shape) 887 return data

File ~/Documentos/PyFWI/lib/python3.10/site-packages/PyFWI/wave_propagation.py:645, in WavePropagator.forward_propagator(self, model) 639 for s in range(self.ns): 640 self.prg.MakeAllZero(self.queue, (self.tnz, self.tnx), None, 641 self.vx_b, self.vz_b, 642 self.taux_b, self.tauz_b, self.tauxz_b 643 ) --> 645 self.__kernel(s, coeff) 647 if self.acq_type == 2: 648 for par in self.seismogram:

File ~/Documentos/PyFWI/lib/python3.10/site-packages/PyFWI/wave_propagation.py:705, in WavePropagator.__kernel(self, s, coeff) 703 for t in np.arange(self.nt): 704 if t % self.dt_scale == 0: --> 705 self.injSrc(t_src, s) 706 t_src += 1 708 self.update_fwd(coeff=coeff)

File ~/Documentos/PyFWI/lib/python3.10/site-packages/PyFWI/wave_propagation.py:655, in WavePropagator.injSrc(self, t, s) 652 def injSrc(self, t, s): 653 src_kv_x, src_kv_z, src_kt_x, src_kt_z, src_kt_xz = np.float32(self.src(t)) --> 655 self.prg.injSrc(self.queue, (self.tnz, self.tnx), None, 656 self.vx_b, self.vz_b, 657 self.taux_b, self.tauz_b, self.tauxz_b, 658 self.seismogramid_vx_b, self.seismogramid_vz_b, 659 self.seismogramid_taux_b, self.seismogramid_tauz_b, self.seismogramid_tauxz_b, 660 self.dxr, 661 self.srcx[s], self.srcz[s], 662 src_kv_x, src_kv_z, 663 src_kt_x, src_kt_z, 664 t)

File ~/Documentos/PyFWI/lib/python3.10/site-packages/pyopencl/init.py:878, in _add_functionality..kernel_call(self, queue, global_size, local_size, *args, kwargs) 872 def kernel_call(self, queue, global_size, local_size, *args, *kwargs): 873 # call can't be overridden directly, so we need this 874 # trampoline hack. 875 876 # Note: This is only used for the generic call, before 877 # kernel_set_scalar_arg_dtypes is called. --> 878 return self._enqueue(self, queue, global_size, local_size, args, kwargs)

File <pyopencl invoker for 'injSrc'>:7, in enqueue_knl_injSrc(self, queue, global_size, local_size, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, global_offset, g_times_l, allow_empty_ndrange, wait_for)

LogicError: clSetKernelArg failed: INVALID_ARG_SIZE - when processing arg#18 (1-based)

dany-97 commented 1 month ago

Hello, I had the same error using the WavePropagator class. pyopencl._cl.RuntimeError: not all provided choices were used by choose_device. (left over: '0') It doesn't work both with 0 (CPU) and 1 (GPU) selection. Python version: 3.11.4 pyopencl version: 2024.2.6

AmirMardan commented 2 weeks ago

Also tried to define inpa[] without 'device' and set_env_variable=False as in #5 but then I had this error on forward_modeling() object:

LogicError Traceback (most recent call last) Cell In[7], line 9 6 W = wave.WavePropagator(inpa, src, rec_loc, model_shape, components=seisout, chpr=20, set_env_variable=False) 8 # Call the forward modelling ----> 9 d_obs = W.forward_modeling(model, show=False) # show=True can show the propagation of the wave

File ~/Documentos/PyFWI/lib/python3.10/site-packages/PyFWI/wave_propagation.py:885, in WavePropagator.forward_modeling(self, model0, show) 883 self.pml_preparation(model['vp'].max()) 884 self.elastic_buffers(model) --> 885 seismo = self.forward_propagator(model) 886 data = acq.seismic_section(seismo, self.components, shape=self.seismo_shape) 887 return data

File ~/Documentos/PyFWI/lib/python3.10/site-packages/PyFWI/wave_propagation.py:645, in WavePropagator.forward_propagator(self, model) 639 for s in range(self.ns): 640 self.prg.MakeAllZero(self.queue, (self.tnz, self.tnx), None, 641 self.vx_b, self.vz_b, 642 self.taux_b, self.tauz_b, self.tauxz_b 643 ) --> 645 self.__kernel(s, coeff) 647 if self.acq_type == 2: 648 for par in self.seismogram:

File ~/Documentos/PyFWI/lib/python3.10/site-packages/PyFWI/wave_propagation.py:705, in WavePropagator.__kernel(self, s, coeff) 703 for t in np.arange(self.nt): 704 if t % self.dt_scale == 0: --> 705 self.injSrc(t_src, s) 706 t_src += 1 708 self.update_fwd(coeff=coeff)

File ~/Documentos/PyFWI/lib/python3.10/site-packages/PyFWI/wave_propagation.py:655, in WavePropagator.injSrc(self, t, s) 652 def injSrc(self, t, s): 653 src_kv_x, src_kv_z, src_kt_x, src_kt_z, src_kt_xz = np.float32(self.src(t)) --> 655 self.prg.injSrc(self.queue, (self.tnz, self.tnx), None, 656 self.vx_b, self.vz_b, 657 self.taux_b, self.tauz_b, self.tauxz_b, 658 self.seismogramid_vx_b, self.seismogramid_vz_b, 659 self.seismogramid_taux_b, self.seismogramid_tauz_b, self.seismogramid_tauxz_b, 660 self.dxr, 661 self.srcx[s], self.srcz[s], 662 src_kv_x, src_kv_z, 663 src_kt_x, src_kt_z, 664 t)

File ~/Documentos/PyFWI/lib/python3.10/site-packages/pyopencl/init.py:878, in _add_functionality..kernel_call(self, queue, global_size, local_size, *args, kwargs) 872 def kernel_call(self, queue, global_size, local_size, *args, kwargs): 873 # call can't be overridden directly, so we need this 874 # trampoline hack. 875 876 # Note: This is only used for the generic call*, before 877 # kernel_set_scalar_arg_dtypes is called. --> 878 return self._enqueue(self, queue, global_size, local_size, args, kwargs)

File <pyopencl invoker for 'injSrc'>:7, in enqueue_knl_injSrc(self, queue, global_size, local_size, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, global_offset, g_times_l, allow_empty_ndrange, wait_for)

LogicError: clSetKernelArg failed: INVALID_ARG_SIZE - when processing arg#18 (1-based)

Hi, Apologies for the late response. If you install the dev branch

!pip uninstall -y PyFWI
!pip install git+https://github.com/AmirMardan/PyFWI.git@dev

this LogicError shouldn't happen. I have fixed this issue in #11, but I have to do a pull request to the main branch.

AmirMardan commented 2 weeks ago

Please install the dev branch and use the WavePropagator as

W = wave.WavePropagator(inpa, src, rec_loc, model_shape, components=seisout, chpr=20, set_env_variable=False)

In this way, the package would ask you to manually enter the devices you want. You can also set the environment variable using os.environ['PYOPENCL_CTX'].