forked from simpeg/simpeg
-
Notifications
You must be signed in to change notification settings - Fork 2
GEOPY-2799 #136
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
Closed
Closed
GEOPY-2799 #136
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
57a2f23
Set RHS to same as A matrix
domfournier 6eecc1c
Repair instantiation of Wires with tuple of int
domfournier 89c6ac1
Add dask method for getjtjdiag for mvi pde
domfournier 092f610
Review distance weights comps
domfournier 2a2e8dd
Fix dtype everywhere Ainv is called
domfournier 1962419
Minor clean ups
domfournier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| from dask import array, compute, delayed | ||
| import numpy as np | ||
| from ....potential_fields.magnetics import Simulation3DDifferential as Sim | ||
| from ....utils import sdiag, mkvc | ||
|
|
||
|
|
||
| def distance_weights(locations, cell_centers, cell_volumes, exponent=3, threshold=1e-2): | ||
| distance_weights = np.zeros(len(cell_centers)) | ||
| for loc in locations: | ||
| distance = np.linalg.norm(cell_centers - loc, axis=1) | ||
| distance_weights += cell_volumes**2.0 * (distance + threshold) ** ( | ||
| -2 * exponent | ||
| ) | ||
|
|
||
| return distance_weights | ||
|
|
||
|
|
||
| def dask_getJtJdiag(self, m, W=None, f=None): | ||
| """ | ||
| Return the diagonal of JtJ | ||
| """ | ||
|
|
||
| self.model = m | ||
|
|
||
| self.model = m | ||
| if W is None: | ||
| W = np.ones(self.Jmatrix.shape[0]) | ||
| else: | ||
| W = W.diagonal() | ||
|
|
||
| client, worker = self._get_client_worker() | ||
|
|
||
| n_threads = self.n_threads(client=client, worker=worker) | ||
|
|
||
| chunks = np.array_split(self.survey.receiver_locations, n_threads) | ||
| cell_centers = self.mesh.cell_centers.copy() | ||
| cell_volumes = self.mesh.cell_volumes.copy() | ||
|
|
||
| if client: | ||
| cell_centers = client.scatter(cell_centers, workers=worker) | ||
| cell_volumes = client.scatter(cell_volumes, workers=worker) | ||
| else: | ||
| delayed_distance_weights = delayed(distance_weights) | ||
|
|
||
| futures = [] | ||
| for block in chunks: | ||
| if client: | ||
| futures.append( | ||
| client.submit( | ||
| distance_weights, | ||
| block, | ||
| cell_centers, | ||
| cell_volumes, | ||
| workers=worker, | ||
| ) | ||
| ) | ||
| else: | ||
| futures.append( | ||
| array.from_delayed( | ||
| delayed_distance_weights( | ||
| block, | ||
| cell_centers, | ||
| cell_volumes, | ||
| ), | ||
| dtype=np.float32, | ||
| shape=( | ||
| len(block), | ||
| len(cell_centers), | ||
| ), | ||
| ) | ||
| ) | ||
|
|
||
| if client: | ||
| diag = client.gather(futures) | ||
| else: | ||
| diag = compute(futures) | ||
|
|
||
| diag = np.tile(np.vstack(diag).sum(axis=0), 3) | ||
| return mkvc((sdiag(np.sqrt(diag)) @ self.remDeriv).power(2).sum(axis=0)) | ||
|
|
||
|
|
||
| Sim.getJtJdiag = dask_getJtJdiag | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The delayed
distance_weights(...)returns a 1D array of lengthlen(cell_centers), butfrom_delayeddeclares a 2D shape(len(block), len(cell_centers)). Also,dask.compute(futures)returns a tuple (with one element when passing a single list), sonp.vstack(diag)will not behave as intended. Use a 1D declared shape and ensure you compute/gather a list of arrays (e.g.,compute(*futures)or index the tuple result) before stacking.