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

How to write a propagator by scalar with the newest version #69

Closed
Cliveljq opened this issue Mar 29, 2024 · 3 comments
Closed

How to write a propagator by scalar with the newest version #69

Cliveljq opened this issue Mar 29, 2024 · 3 comments

Comments

@Cliveljq
Copy link

Hello, Many thanks to you and your colleagues for writing this library
I am trying to run a old code wirten by deepwave==0.0.8. However, I find it's hard to run it on gpu. So, I want to rewrite it with the newest deepwave. This is very difficult, I can not find the old version of deepwave usage documentation, I do not know the new and old directly what the difference.

The code with deepwave==0.0.8 are:

prop=deepwave. scalar.Propagator({'vp': model}, dx, pml_width,
order, survey_pad)
r_amps=prop(s_amps, x_s, x_r, dt)

I changed the code to(With 0.0.20, all data is to. device='cuda:0'):

r_amps = deepwave.scalar(model_init, dx,dt, s_amps, x_s, x_r,order,pml_width, survey_pad)

But the code reported an error:

Traceback (most recent call last):
File "D:\anaconda3\envs\demo3\lib\site-packages\deepwave\scalar.py", line 375, in scalar
setup_propagator([v], 'scalar', grid_spacing, dt,
File "D:\anaconda3\envs\demo3\lib\site-packages\deepwave\common.py", line 58, in setup_propagator
check_inputs(source_amplitudes, source_locations, receiver_locations,
File "D:\anaconda3\envs\demo3\lib\site-packages\deepwave\common.py", line 255, in check_inputs
raise RuntimeError("Expected source_amplitudes.shape[0] == "
RuntimeError: Expected source_amplitudes.shape[0] == source_locations.shape[0].

Could you please help me and give me the correct version?

@ar4
Copy link
Owner

ar4 commented Mar 29, 2024

Hello again.

I am sorry to hear that you are finding the translation difficult. The wrapper code that I provided in my reply in the previous Issue might help - even if you don't use the wrapper itself, it could be a guide to demonstrate how to change your code.

For the call that you asked about, try this:

r_amps = deepwave.scalar(
    model_init, dx, dt,
    source_amplitudes=s_amps.movedim(0, -1),
    source_locations=(x_s/dx).long(),
    receiver_locations=(x_r/dx).long(),
    accuracy=order,
    pml_width=pml_width[:4],
    survey_pad=survey_pad
)[-1].movedim(-1, 0)

Note that the source and receiver locations should now be provided in units of cells rather than units of distance, so the code above divides the source and receiver locations by dx before passing them to Deepwave. The other main change is that the time dimension is now the last one instead of the first one. The code above therefore moves the time dimension of the source amplitudes from the first to the last, and moves the time dimension of the output receiver data from the last back to the first so that it will be the same as the output from the old version of Deepwave.

You can find the usage documentation for v0.0.8 of the propagator here.

Please let me know if it still doesn't work.

@Cliveljq
Copy link
Author

Ohhh!Now, the code is running on GPU, which speed is 20 times than cpu. Thank you very much for your patience and guidance. I will reading these two documents carefully and try to distinct these two versions. Your library help me a lot on Full Wave Reversion. Hope you have a good life.

@ar4
Copy link
Owner

ar4 commented Mar 30, 2024

That is good news. I hope that you continue to find Deepwave useful.

@ar4 ar4 closed this as completed Mar 30, 2024
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

2 participants