Tutorial suggestion: external codes / developing off SimPEG

I think this is the best place for this. I am looking for information on where to start implementing some modeling that doesn’t fit into the FEM/FVM framework SimPEG is generally built around. For instance, I think the response of a dipole in a 1D layered model using recursion relations could be of practical value (see below for two different implementations). This specific problem wouldn’t require a 3D mesh, but just sources, receivers, and a list of layer thicknesses and conductivities. Another thing I could see being valuable to implement are method of moment approaches for modeling things like thin conductive sheets, or steel casings.


The above is my personal motivation, but a larger topic can best be summed up as “how can I leverage what’s in SimPEG, but bring/implement my own codes?” I think a tutorial on this topic would be quite useful to help users know where to begin transferring to a more dev type role. I did a quick brainstorm on topics that could be useful for such a tutorial.

  1. Where user-code fits into the SimPEG ecosystem (both in the “big picture” view of SimPEG and on the user’s system)

  2. Building user-code that leverages SimPEG’s framework. I personally would like this to not just be a walkthrough of an existing modeling code. Maybe something simple like smoothing data injected at a source and measure at receivers. Or filling a mesh with random data and taking a derivative.

  3. Plugging into a user-code (python, C, etc.) that was not originally developed with SimPEG in mind. Maybe the code takes in a binary file and outputs a binary file or something. I think this is mostly just mapping SimPEG data types to whatever the user-code is expecting, so it’s maybe not as useful as I first thought. If the user-code has specific functions (in C) that the user wants to leverage with SimPEG instead, then maybe this could talk about how python can be used as a glue between languages?

  4. Plugging into a user-code (python, C, etc.) that was developed with SimPEG in mind (or can be edited such that it plays nice). I think for python this is a repeat of 2, but for C or other languages, some work is required.

  5. The importance of testing code and how to implement.

  6. The importance of committing your code back to the community with proper documentation.

  7. When to commit something into SimPEG vs. when to commit it in geoana. I haven’t explored geoana too extensively, but I understand everything in there can be used for modeling/inversion in SimPEG?

Thoughts? Did I miss anything?

that is very important for me. Can i find the code of < [The electromagnetic response of a horizontal electric dipole buried in a…]> in the SimPEG?

Thanks for starting off this conversation @ckohnke! With the simulation refactor of SimPEG, this should now be much simpler to implement. The basic setup would be to

  1. inherit the BaseSimulation
  2. define what your Invertible properties and mappings are. e.g. if we want to invert for resistivity (or instead provide rho_map = maps.ExpMap(mesh) to invert for log-resistivity), then you would define:
    from SimPEG import props
    rho, rho_map, rho_deriv = props.Invertible(
        "Electrical Resistivity (Ohm m)"
  3. define a dpred(self, m=model, f=None) method for generating data (f=fields if you have a fields object that is solved for seperately. We use this in the EM codes for example.
  4. define a Jvec(self, m=model, v=vector, f=None) method for computing the sensitivity times a vector (note, if you don’t have an explicit expression for this, we could use a finite difference approach - there is some scratch code for this – this might be a nice utility to bring over to SimPEG)
  5. define a Jtvec(self, m=model, v=vector, f=None) method for computing the adjoint times a vector

The LinearSimulation in SimPEG is a nice template for setting this up.

As for your and @subenyu’s request for dipole solutions over a 1D earth – connecting empymod with SimPEG would achieve this. @prisae and I started working on this a while back. This code will be slightly out of date, but the general idea is in place. If you are interested in reviving this, I can give a few more explicit pointers as to what would need to change in this code to update it (BaseProblem --> BaseSimulation is the main change)

Thank you very very much for you help and I will try it.




On 2/8/2020 01:33,Lindsey Heagy via SimPEG Community Chatsimpeg@discoursemail.com wrote:

Hi @ckohnke!

As @lheagy said, everything related to the two publications you posted or

could be done with empymod (https://empymod.github.io).

@lheagy and I planned to tightly integrate empymod into SimPEG since a while, and one day we will get there! If this is something that you would like to help out and have a go at it we both would be willing to give you a hand.