ar4 / deepwave

Wave propagation modules for PyTorch.
MIT License
218 stars 47 forks source link

How can I get the file called scalar2d_gpu_iso_4_float and scalar2d_gpu_iso_4_float.cp38-win_amd64 #68

Closed Cliveljq closed 8 months ago

Cliveljq commented 8 months ago

Sorry for disturbing. My projected is based on deepwave==0.0.8. However, when it was run on GPU, files called scalar2d_gpu_iso_4_float and scalar2d_gpu_iso_4_float.cp38-win_amd64 are lacked. How can I get them? (Actually, I also need _scalar1d_gpu_iso_4_float.cp38-win_amd64, _scalar3d_gpu_iso_4_float.cp38-winamd64, scalar1d_gpu_iso_4_float and scalar3d_gpu_iso_4float)

ar4 commented 8 months ago

Hello, and thank you for writing. It is not at all a disturbance, and I am sorry that Deepwave caused a problem for you.

The files that you refer to are ones that should be created when you install Deepwave. They are the result of compiling Deepwave's CUDA code that implements the propagators on the GPU. From the filenames, it looks like you are trying to run it on Windows. Installing that old version of Deepwave on Windows can unfortunately be difficult. Does it work when you try to run on the CPU instead? Would it be possible for you to switch your project to use the latest version of Deepwave? If it is helpful, here is a wrapper that you can use to translate old-style calls to Deepwave's scalar propagator into calls to the new version of Deepwave:

import torch
import deepwave

class Propagator():

    def __init__(self, model, dx, pml_width=None, survey_pad=None, vpmax=None):
        """Wrapper to call Deepwave's scalar propagator

        Args:
            model: A dictionary containing a 'vp' key whose value is a
                [ny, nx] shape Float Tensor containing the velocity model.
            dx: A float or list of floats containing cell spacing in each
                dimension.
            pml_width: An int or list of ints specifying number of cells to use
                for the PML. This will be added to the beginning and end of each
                propagating dimension. If provided as a list, it should be of
                length 6, with each sequential group of two integer elements
                referring to the beginning and end PML width for a dimension.
                The last two entries are ignored. Optional, default 20.
            survey_pad: A float or None, or list of such with 2 elements for each
                dimension, specifying the padding (in units of dx) to add.
                In each dimension, the survey (wave propagation) area for each
                batch of shots will be from the left-most source/receiver minus
                the left survey_pad, to the right-most source/receiver plus the
                right survey pad, over all shots in the batch, or to the edges of
                the model, whichever comes first. If a list, it specifies the
                left and right survey_pad in each dimension. If None, the survey
                area will continue to the edges of the model. If a float, that
                value will be used on the left and right of each dimension.
                Optional, default None.
            vpmax: A float specifying the velocity to use when calculating the
                internal time step size using the CFL condition.
                Optional, default None which will use the maximum in the
                provided model.
        """
        if 'vp' not in model:
            raise RuntimeError("model should contain a 'vp' key")

        if not isinstance(model['vp'], torch.Tensor):
            raise RuntimeError("model should be a Tensor")

        if not model['vp'].ndim == 2:
            raise RuntimeError("model should have two dimensions")

        if isinstance(pml_width, list):
            pml_width = pml_width[:4]

        self.vp = model['vp']
        self.dx = dx
        self.pml_width = pml_width
        self.survey_pad = survey_pad
        self.vpmax = vpmax

    def __call__(self, source_amplitudes, source_locations, receiver_locations,
                 dt):
        if isinstance(self.dx, list):
            source_locations[..., 0] /= self.dx[0]
            source_locations[..., 1] /= self.dx[1]
            receiver_locations[..., 0] /= self.dx[0]
            receiver_locations[..., 1] /= self.dx[1]
        else:
            source_locations /= self.dx
            receiver_locations /= self.dx
        return deepwave.scalar(self.vp,
                               self.dx,
                               dt,
                               source_amplitudes=source_amplitudes.movedim(
                                   0, -1),
                               source_locations=source_locations.long(),
                               receiver_locations=receiver_locations.long(),
                               pml_width=self.pml_width,
                               survey_pad=self.survey_pad,
                               max_vel=self.vpmax)[-1].movedim(-1, 0)

Please let me know if you need help using it. There are ways of doing it (such as putting this wrapper into a subdirectory of your project called deepwave/scalar) that can result in the change requiring very little work, but you might decide that another approach is a better fit for your project.

If that is not possible, please let me know so that we can try to find an alternative.

Cliveljq commented 8 months ago

THANKS A LOT!Actually, I have realized that the project should be transfered to the new version deepwave. I will keep working on that. Wish you have a good life.

ar4 commented 8 months ago

I am glad to hear that updating it is possible. I think the newer version is a noticeable improvement, so updating will be worth the effort. I will close this Issue now, but please feel free to reopen it or to create a new one if you need any more help.