### Setup and run example 1 with SPECFEM2D path Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/specfem2d_example.ipynb Sets up and runs example 1 using the `seisflows examples setup` and `seisflows submit` commands, or the equivalent `seisflows examples run` command. Use `-r` or `--specfem2d_repo` to point to an existing SPECFEM2D repository; otherwise SeisFlows downloads and compiles it automatically. ```python # Run command with open variable to set SPECFEM2D path ! seisflows examples setup 1 -r ${PATH_TO_SPECFEM2D} ! seisflows submit # The following command is the same as above ! seisflows examples run 1 --specfem2d_repo ${PATH_TO_SPECFEM2D} ``` -------------------------------- ### Run example setup Source: https://github.com/adjtomo/seisflows/blob/main/docs/cluster_setup.rst Sets up a 2D example in an empty working directory, creating a parameter file and a SPECFEM2D working directory. ```bash cd # empty directory seisflows examples setup 2 -r ``` -------------------------------- ### Run Tape2007 example to verify SPECFEM2D installation Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Runs the Tape2007 example script and checks for the expected output image. Asserts the example ran successfully, otherwise the rest of the tutorial may fail. Displays the tail of the output log. ```python # Run the Tape2007 example to make sure SPECFEM2D is working as expected os.chdir(TAPE_2007_EXAMPLE) ! ./run_this_example.sh > output_log.txt assert(os.path.exists("OUTPUT_FILES/forward_image000004800.jpg")), \ (f"Example did not run, the remainder of this docs page will likely not work." f"Please check the following directory: {TAPE_2007_EXAMPLE}") ! tail output_log.txt ``` ```text Output: ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- D a t e : 16 - 08 - 2022 T i m e : 14:26:37 ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- see results in directory: OUTPUT_FILES/ done Tue Aug 16 02:26:37 PM AKDT 2022 ``` -------------------------------- ### Output of seisflows submit Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Log output from resuming the workflow, showing setup, iteration 01, adjoint simulations, kernel processing, and stopping at evaluate_gradient_from_kernels. ```text Output: 2022-08-16 14:36:42 (D) | setting iteration==1 from state file 2022-08-16 14:36:42 (I) | ================================================================================ SETTING UP INVERSION WORKFLOW ================================================================================ 2022-08-16 14:36:48 (D) | running setup for module 'system.Workstation' 2022-08-16 14:36:51 (D) | copying par/log file to: /home/bchow/Work/scratch/logs/sflog_002.txt 2022-08-16 14:36:51 (D) | copying par/log file to: /home/bchow/Work/scratch/logs/parameters_002.yaml 2022-08-16 14:36:51 (D) | running setup for module 'solver.Specfem2D' 2022-08-16 14:36:51 (I) | initializing 3 solver directories 2022-08-16 14:36:51 (D) | running setup for module 'preprocess.Default' 2022-08-16 14:36:52 (D) | running setup for module 'optimize.Gradient' 2022-08-16 14:36:53 (I) | re-loading optimization module from checkpoint 2022-08-16 14:36:54 (I) | re-loading optimization module from checkpoint 2022-08-16 14:36:54 (I) | //////////////////////////////////////////////////////////////////////////////// RUNNING ITERATION 01 //////////////////////////////////////////////////////////////////////////////// 2022-08-16 14:36:54 (I) | ================================================================================ RUNNING INVERSION WORKFLOW ================================================================================ 2022-08-16 14:36:54 (I) | 'evaluate_initial_misfit' has already been run, skipping 2022-08-16 14:36:54 (I) | //////////////////////////////////////////////////////////////////////////////// EVALUATING EVENT KERNELS W/ ADJOINT SIMULATIONS //////////////////////////////////////////////////////////////////////////////// 2022-08-16 14:36:54 (I) | running SPECFEM executable bin/xspecfem2D, log to 'adj_solver.log' 2022-08-16 14:37:05 (D) | renaming output event kernels: 'alpha' -> 'vp' 2022-08-16 14:37:05 (D) | renaming output event kernels: 'beta' -> 'vs' 2022-08-16 14:37:05 (I) | running SPECFEM executable bin/xspecfem2D, log to 'adj_solver.log' 2022-08-16 14:37:16 (D) | renaming output event kernels: 'alpha' -> 'vp' 2022-08-16 14:37:16 (D) | renaming output event kernels: 'beta' -> 'vs' 2022-08-16 14:37:18 (I) | running SPECFEM executable bin/xspecfem2D, log to 'adj_solver.log' 2022-08-16 14:37:29 (D) | renaming output event kernels: 'alpha' -> 'vp' 2022-08-16 14:37:29 (D) | renaming output event kernels: 'beta' -> 'vs' 2022-08-16 14:37:30 (I) | //////////////////////////////////////////////////////////////////////////////// GENERATING/PROCESSING MISFIT KERNEL //////////////////////////////////////////////////////////////////////////////// 2022-08-16 14:37:30 (I) | combining event kernels into single misfit kernel 2022-08-16 14:37:31 (I) | scaling gradient to absolute model perturbations 2022-08-16 14:37:32 (I) | stop workflow at `stop_after`: evaluate_gradient_from_kernels ``` -------------------------------- ### Change directory and list example files Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/specfem2d_example.ipynb Navigate to the example directory and list its contents to verify the setup before running commands. ```python %cd ~/sfexamples/example_3 ! ls ``` -------------------------------- ### Setup and run SPECFEM2D example 1 Source: https://github.com/adjtomo/seisflows/blob/main/docs/specfem2d_example.rst Sets up and runs the SPECFEM2D example 1. Use the -r/--specfem2d_repo flag to point to an existing SPECFEM2D repository with compiled binaries; otherwise SeisFlows downloads, configures, and compiles SPECFEM2D in the current working directory. The first two commands are equivalent to the third. ```bash # Run command with open variable to set SPECFEM2D path seisflows examples setup 1 -r ${PATH_TO_SPECFEM2D} seisflows submit # The following command is the same as above seisflows examples run 1 --specfem2d_repo ${PATH_TO_SPECFEM2D} ``` -------------------------------- ### List SPECFEM2D binaries Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Changes to the SPECFEM2D original directory and lists the bin directory contents. ```python # Check out the binary files that have been created os.chdir(SPECFEM2D_ORIGINAL) ! pwd ! ls bin/ ``` -------------------------------- ### Exit code 0 Source: https://github.com/adjtomo/seisflows/blob/main/docs/2D_example_walkthrough.rst Indicates successful execution of the parameter setup commands. ```default 0 ``` -------------------------------- ### Create parameters.yaml with seisflows setup -f Source: https://github.com/adjtomo/seisflows/blob/main/docs/2D_example_walkthrough.rst The 'setup' command creates the 'parameters.yaml' file that controls all of SeisFlows. The '-f' flag removes any existing 'parameters.yaml' file in the directory. The output shows the created file and the directory contents. ```bash # The command 'setup' creates the 'parameters.yaml' file that controls all of SeisFlows # the '-f' flag removes any exist 'parameters.yaml' file that might be in the directory os.chdir(WORKDIR) seisflows setup -f ls ``` ```default creating parameter file: parameters.yaml parameters.yaml sflog.txt specfem2d specfem2d_workdir ``` -------------------------------- ### Output of binary listing Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Shows the output of the pwd and ls commands, listing the compiled SPECFEM2D binaries. ```text Output: /home/bchow/REPOSITORIES/specfem2d xadj_seismogram xconvolve_source_timefunction xspecfem2D xcheck_quality_external_mesh xmeshfem2D xsum_kernels xcombine_sem xsmooth_sem ``` -------------------------------- ### List gradient binary files Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Lists the SPECFEM binary files in the gradient directory, showing the kernel files for vp and vs. ```python # SeisFlows3 stores all kernels and gradient information as SPECFEM binary (.bin) files ! ls scratch/eval_grad/gradient ``` ```text Output: proc000000_vp_kernel.bin proc000000_vs_kernel.bin ``` -------------------------------- ### Create parameters.yaml with seisflows setup -f Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Run the 'setup' command to create the 'parameters.yaml' file that controls all of SeisFlows. The '-f' flag removes any existing 'parameters.yaml' file in the directory. The output shows the created file and the directory contents. ```python # The command 'setup' creates the 'parameters.yaml' file that controls all of SeisFlows # the '-f' flag removes any exist 'parameters.yaml' file that might be in the directory os.chdir(WORKDIR) ! seisflows setup -f ! ls ``` ```text Output: creating parameter file: parameters.yaml parameters.yaml sflog.txt specfem2d specfem2d_workdir ``` -------------------------------- ### SeisFlows YAML parameter file for 2D inversion example Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Default parameter file for the 2D example walkthrough. Sets workflow to inversion, system to workstation, solver to specfem2d, preprocess to default, and optimize to gradient. Comments explain how to list available options with `seisflows print modules` and auto-fill with `seisflows configure`. ```yaml # ////////////////////////////////////////////////////////////////////////////// # # SeisFlows YAML Parameter File # # ////////////////////////////////////////////////////////////////////////////// # # Modules correspond to the structure of the source code, and determine # SeisFlows' behavior at runtime. Each module requires its own sub-parameters. # # .. rubric:: # - To determine available options for modules listed below, run: # > seisflows print modules # - To auto-fill with docstrings and default values (recommended), run: # > seisflows configure # - To set values as NoneType, use: null # - To set values as infinity, use: inf # # MODULES # /////// # workflow (str): The types and order of functions for running SeisFlows # system (str): Computer architecture of the system being used # solver (str): External numerical solver to use for waveform simulations # preprocess (str): Preprocessing schema for waveform data # optimize (str): Optimization algorithm for the inverse problem # ============================================================================== workflow: inversion system: workstation solver: specfem2d preprocess: default optimize: gradient # ============================================================================= # # Forward Workflow # ---------------- # Run forward solver in parallel and (optionally) calculate # data-synthetic misfit and adjoint sources. # # Parameters # ---------- # :type modules: list of module # :param modules: instantiated SeisFlows modules which should have been # generated by the function `seisflows.config.import_seisflows` with a # parameter file generated by seisflows.configure # :type data_case: str # :param data_case: How to address 'data' in the workflow, available options: # 'data': real data will be provided by the user in # `path_data/{source_name}` in the same format that the solver will # produce synthetics (controlled by `solver.format`) OR # synthetic': 'data' will be generated as synthetic seismograms using # a target model provided in `path_model_true`. If None, workflow will ``` -------------------------------- ### Create SPECFEM2D working directory and copy binaries and DATA Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Sets up an isolated SPECFEM2D working directory by copying binaries and the Tape2007 example DATA directory. Deletes any existing working directory first. Prints the working directory and its contents. ```python # Incase we've run this docs page before, delete the working directory before remaking if os.path.exists(SPECFEM2D_WORKDIR): shutil.rmtree(SPECFEM2D_WORKDIR) os.mkdir(SPECFEM2D_WORKDIR) os.chdir(SPECFEM2D_WORKDIR) # Copy the binary files incase we update the source code. These can also be symlinked. shutil.copytree(SPECFEM2D_BIN_ORIGINAL, "bin") # Copy the DATA/ directory because we will be making edits here frequently and it's useful to # retain the original files for reference. We will be running one of the example problems: Tape2007 shutil.copytree(os.path.join(TAPE_2007_EXAMPLE, "DATA"), "DATA") ! pwd ! ls ``` ```text Output: /home/bchow/Work/scratch/specfem2d_workdir bin DATA ``` -------------------------------- ### Run Example Problem 1 with seisflows examples run Source: https://github.com/adjtomo/seisflows/blob/main/docs/getting_started.rst Executes Example Problem 1, a synthetic homogeneous halfspace inversion, from an empty working directory. Automatically downloads and compiles SPECFEM2D, sets up starting and target models, and runs a 1-iteration inversion. ```bash cd # choose an empty working directory seisflows examples run 1 ``` -------------------------------- ### Load and print gradient array Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Loads the gradient array from the g_new.npz file and prints the vs_kernel array. ```python g_new = np.load("scratch/optimize/g_new.npz") print(g_new["vs_kernel"]) ``` ```text Output: [[-1.18126331e-12 2.40273470e-12 3.97045036e-11 ... 9.62017688e-11 4.21140102e-11 3.96825021e-12]] ``` -------------------------------- ### Set up SOURCE and Par_file in SPECFEM2D DATA directory Source: https://github.com/adjtomo/seisflows/blob/main/docs/2D_example_walkthrough.rst Configures the DATA directory by symlinking SOURCE_001 as the main SOURCE and copying the Par_file_Tape2007_onerec to Par_file. This mirrors the setup in run_this_example.sh and ensures edits do not affect the original files. ```bash # First we will set the correct SOURCE and STATION files. # This is the same task as shown in ./run_this_example.sh os.chdir(SPECFEM2D_DATA) # Symlink source 001 as our main source if os.path.exists("SOURCE"): os.remove("SOURCE") os.symlink("SOURCE_001", "SOURCE") # Copy the correct Par_file so that edits do not affect the original file if os.path.exists("Par_file"): os.remove("Par_file") shutil.copy("Par_file_Tape2007_onerec", "Par_file") ls ``` -------------------------------- ### Submit seisflows job Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Submits the seisflows job, which runs the line search and shows the workflow progress. ```bash ! seisflows submit ``` ```text Output: 2022-08-16 14:41:12 (D) | setting iteration==1 from state file 2022-08-16 14:41:12 (I) | ================================================================================ SETTING UP INVERSION WORKFLOW ================================================================================ 2022-08-16 14:41:18 (D) | running setup for module 'system.Workstation' 2022-08-16 14:41:21 (D) | copying par/log file to: /home/bchow/Work/scratch/logs/sflog_003.txt 2022-08-16 14:41:21 (D) | copying par/log file to: /home/bchow/Work/scratch/logs/parameters_003.yaml 2022-08-16 14:41:21 (D) | running setup for module 'solver.Specfem2D' 2022-08-16 14:41:21 (I) | initializing 3 solver directories 2022-08-16 14:41:22 (D) | running setup for module 'preprocess.Default' 2022-08-16 14:41:24 (D) | running setup for module 'optimize.Gradient' 2022-08-16 14:41:26 (I) | re-loading optimization module from checkpoint 2022-08-16 14:41:28 (I) | re-loading optimization module from checkpoint 2022-08-16 14:41:28 (I) | //////////////////////////////////////////////////////////////////////////////// RUNNING ITERATION 01 //////////////////////////////////////////////////////////////////////////////// 2022-08-16 14:41:28 (I) | ================================================================================ RUNNING INVERSION WORKFLOW ================================================================================ 2022-08-16 14:41:28 (I) | 'evaluate_initial_misfit' has already been run, skipping 2022-08-16 14:41:28 (I) | 'run_adjoint_simulations' has already been run, skipping 2022-08-16 14:41:28 (I) | 'postprocess_event_kernels' has already been run, skipping 2022-08-16 14:41:28 (I) | 'evaluate_gradient_from_kernels' has already been run, skipping 2022-08-16 14:41:28 (I) | initializing 'bracket'ing line search 2022-08-16 14:41:28 (I) | enforcing max step length safeguard 2022-08-16 14:41:28 (D) | step length(s) = 0.00E+00 2022-08-16 14:41:28 (D) | misfit val(s) = 1.28E-03 2022-08-16 14:41:28 (I) | try: first evaluation, attempt guess step length, alpha=9.08E+11 2022-08-16 14:41:28 (I) | try: applying initial step length safegaurd as alpha has exceeded maximum step length, alpha_new=1.44E+10 2022-08-16 14:41:28 (D) | overwriting initial step length, alpha_new=2.32E+09 2022-08-16 14:41:28 (I) | trial model 'm_try' parameters: 2022-08-16 14:41:28 (I) | 5800.00 <= vp <= 5800.00 2022-08-16 14:41:28 (I) | 3244.51 <= vs <= 3790.00 2022-08-16 14:41:29 (I) | LINE SEARCH STEP COUNT 01 ``` -------------------------------- ### Run Example 2 with SPECFEM2D path Source: https://github.com/adjtomo/seisflows/blob/main/docs/specfem2d_example.rst Executes the Example 2 inversion workflow. Requires the `-r` flag to provide the path to a local SPECFEM2D installation. ```bash seisflows examples run 2 -r ${PATH_TO_SPECFEM2D} ``` -------------------------------- ### List SeisFlows tasks Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Command to list the available tasks for the `stop_after` parameter. Run from the working directory. ```python os.chdir(WORKDIR) ! seisflows print tasks ``` -------------------------------- ### Output of MODEL parameter change Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Shows the output of changing the MODEL parameter from default to gll. ```text MODEL: default -> gll ``` -------------------------------- ### Prepare OUTPUT_FILES directory for SPECFEM2D Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Creates the OUTPUT_FILES directory required by SPECFEM2D before running the mesher and solver. Removes any existing directory to ensure a clean state. ```python # SPECFEM requires that we create the OUTPUT_FILES directory before running os.chdir(SPECFEM2D_WORKDIR) if os.path.exists(SPECFEM2D_OUTPUT): shutil.rmtree(SPECFEM2D_OUTPUT) os.mkdir(SPECFEM2D_OUTPUT) ! ls ``` ```text Output: bin DATA OUTPUT_FILES ``` -------------------------------- ### List SeisFlows tasks Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Lists the available SeisFlows3 workflow tasks, useful for identifying the correct function to resume from in the parameters.yaml file. ```bash ! seisflows print tasks ``` -------------------------------- ### List optimization directory contents Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Lists the files in the scratch/optimize directory, showing the 'new' and 'old' optimization vectors (e.g., m_new.npz, m_old.npz) that represent the previous and current models. ```python # We can see that we have 'new' and 'old' values for each of the optimization values, # representing the previous model (M00) and the current model (M01). ! ls scratch/optimize ``` ```text Output: alpha.txt f_new.txt f_try.txt m_new.npz output_optim.txt checkpoint.npz f_old.txt g_old.npz m_old.npz p_old.npz ``` -------------------------------- ### SeisFlows Inversion Workflow Log Output Source: https://github.com/adjtomo/seisflows/blob/main/docs/2D_example_walkthrough.rst Log output from a SeisFlows inversion workflow setup and initial misfit evaluation, showing module initialization, solver directory setup, and parameter checks. ```default 2022-08-16 14:32:48 (I) | ================================================================================ SETTING UP INVERSION WORKFLOW ================================================================================ 2022-08-16 14:32:55 (D) | running setup for module 'system.Workstation' 2022-08-16 14:32:57 (D) | copying par/log file to: /home/bchow/Work/scratch/logs/sflog_001.txt 2022-08-16 14:32:57 (D) | copying par/log file to: /home/bchow/Work/scratch/logs/parameters_001.yaml 2022-08-16 14:32:57 (D) | running setup for module 'solver.Specfem2D' 2022-08-16 14:32:57 (I) | initializing 3 solver directories 2022-08-16 14:32:57 (D) | initializing solver directory source: 001 2022-08-16 14:33:04 (D) | linking source '001' as 'mainsolver' 2022-08-16 14:33:04 (D) | initializing solver directory source: 002 2022-08-16 14:33:09 (D) | initializing solver directory source: 003 2022-08-16 14:33:16 (D) | running setup for module 'preprocess.Default' 2022-08-16 14:33:16 (D) | running setup for module 'optimize.Gradient' 2022-08-16 14:33:17 (I) | no optimization checkpoint found, assuming first run 2022-08-16 14:33:17 (I) | re-loading optimization module from checkpoint 2022-08-16 14:33:17 (I) | //////////////////////////////////////////////////////////////////////////////// RUNNING ITERATION 01 //////////////////////////////////////////////////////////////////////////////// 2022-08-16 14:33:17 (I) | ================================================================================ RUNNING INVERSION WORKFLOW ================================================================================ 2022-08-16 14:33:17 (I) | //////////////////////////////////////////////////////////////////////////////// EVALUATING MISFIT FOR INITIAL MODEL //////////////////////////////////////////////////////////////////////////////// 2022-08-16 14:33:17 (I) | checking initial model parameters 2022-08-16 14:33:17 (I) | 5800.00 <= vp <= 5800.00 2022-08-16 14:33:17 (I) | 2600.00 <= rho <= 2600.00 2022-08-16 14:33:17 (I) | 3500.00 <= vs <= 3500.00 2022-08-16 14:33:17 (I) | checking true/target model parameters 2022-08-16 14:33:17 (I) | 5900.00 <= vp <= 5900.00 2022-08-16 14:33:17 (I) | 2600.00 <= rho <= 2600.00 2022-08-16 14:33:17 (I) | 3550.00 <= vs <= 3550.00 2022-08-16 14:33:17 (I) | preparing observation data for source 001 2022-08-16 14:33:17 (I) | running forward simulation w/ target model for 001 2022-08-16 14:33:21 (I) | evaluating objective function for source 001 2022-08-16 14:33:21 (D) | running forward simulation with 'Specfem2D' 2022-08-16 14:33:25 (D) | quantifying misfit with 'Default' 2022-08-16 14:33:25 (I) | preparing observation data for source 002 2022-08-16 14:33:25 (I) | running forward simulation w/ target model for 002 2022-08-16 14:33:29 (I) | evaluating objective function for source 002 2022-08-16 14:33:29 (D) | running forward simulation with 'Specfem2D' 2022-08-16 14:33:33 (D) | quantifying misfit with 'Default' 2022-08-16 14:33:33 (I) | preparing observation data for source 003 2022-08-16 14:33:33 (I) | running forward simulation w/ target model for 003 2022-08-16 14:33:36 (I) | evaluating objective function for source 003 2022-08-16 14:33:36 (D) | running forward simulation with 'Specfem2D' 2022-08-16 14:33:40 (D) | quantifying misfit with 'Default' 2022-08-16 14:33:40 (I) | stop workflow at stop_after: evaluate_initial_misfit ``` -------------------------------- ### Output of stop_after setting Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Confirms the stop_after parameter is set to evaluate_gradient_from_kernels. ```text Output: stop_after: evaluate_initial_misfit -> evaluate_gradient_from_kernels ``` -------------------------------- ### List per-event kernel directories Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Lists the per-event kernel directories, showing that kernels are stored on a per-event basis and summed together. ```python # Kernels are stored on a per-event basis, and summed together (sum/). If smoothing was performed, # we would see both smoothed and unsmoothed versions of the misfit kernel ! ls scratch/eval_grad/kernels ``` ```text Output: 001 002 003 ``` -------------------------------- ### List gradient evaluation files Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Lists the contents of the gradient evaluation directory, showing where kernels and gradient information are stored. ```python # Gradient evaluation files are stored here, the kernels are stored separately from the gradient incase # the user wants to manually manipulate them ! ls scratch/eval_grad ``` ```text Output: gradient kernels misfit_kernel model residuals.txt ``` -------------------------------- ### Display optimization statistics file Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Cats the output_optim.txt file to show the optimization statistics, including step count, step length, gradient norms, misfit, and slope. ```python # The stats/ directory contains text files describing the optimization/line search ! cat scratch/optimize/output_optim.txt ``` ```text Output: step_count,step_length,gradient_norm_L1,gradient_norm_L2,misfit,if_restarted,slope,theta 04,2.323E+09,9.243E-05,1.049E-06,1.279E-03,0,8.263E-13,0.000E+00 ``` -------------------------------- ### List available modules with seisflows print modules Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Use the 'seisflows print modules' command to list out the available options for the modules in the parameter file. This helps determine which sub-parameters can be configured. ```python # We can use the `seisflows print modules` command to list out the available options ! seisflows print modules ``` -------------------------------- ### List SeisFlows commands with seisflows -h Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Use the help flag to display all available SeisFlows3 command line commands and their intended usages. The output shows the command list and notes that 'seisflows [command] -h' provides more detailed descriptions. ```python ! seisflows -h ``` ```text Output: usage: seisflows [-h] [-w [WORKDIR]] [-p [PARAMETER_FILE]] {setup,configure,swap,init,submit,resume,restart,clean,par,sempar,check,print,reset,debug,examples} ... ================================================================================ SeisFlows: Waveform Inversion Package ================================================================================ optional arguments: -h, --help show this help message and exit -w [WORKDIR], --workdir [WORKDIR] The SeisFlows working directory, default: cwd -p [PARAMETER_FILE], --parameter_file [PARAMETER_FILE] Parameters file, default: 'parameters.yaml' command: Available SeisFlows arguments and their intended usages setup Setup working directory from scratch configure Fill parameter file with defaults swap Swap module parameters in an existing parameter file init Initiate working environment submit Submit initial workflow to system resume Re-submit previous workflow to system restart Remove current environment and submit new workflow clean Remove files relating to an active working environment par View and edit SeisFlows parameter file sempar View and edit SPECFEM parameter file check Check state of an active environment print Print information related to an active environment reset Reset modules within an active state debug Start interactive debug environment examples Look at and run pre-configured example problems 'seisflows [command] -h' for more detailed descriptions of each command. ``` -------------------------------- ### Set Workflow to Inversion and Display Parameters Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Uses `seisflows par workflow inversion` to set the workflow to inversion and then displays the `parameters.yaml` file with `cat`. The comment notes that the SOLVER module must be changed to `specfem2d` for this example. ```python # For this example, we can use most of the default modules, however we need to # change the SOLVER module to let SeisFlows know we're using SPECFEM2D (as opposed to 3D) ! seisflows par workflow inversion ! cat parameters.yaml ``` -------------------------------- ### Example source files directory Source: https://github.com/adjtomo/seisflows/blob/main/docs/noise_inversion.rst Shows the expected location and naming of source files (FORCESOLUTION) in the SPECFEM working directory. ```bash specfem_workdir/ └── DATA/ ├── Par_file ├── FORCESOLUTION_AA_A000 ├── FORCESOLUTION_AA_A001 ├── FORCESOLUTION_BB_B000 └── ... ``` -------------------------------- ### Define SPECFEM2D and working directory paths Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Sets up the directory structure for the SPECFEM2D repository and working directory. Requires editing WORKDIR and SPECFEM2D paths. Defines paths for initial and true models. ```python # vvv USER MUST EDIT THE FOLLOWING PATHS vvv WORKDIR = "/home/bchow/Work/scratch" SPECFEM2D = "/home/bchow/REPOSITORIES/specfem2d" # where WORKDIR: points to your own working directory # and SPECFEM2D: points to an existing specfem2D repository if available (if not set as '') # ^^^ USER MUST EDIT THE FOLLOWING PATHS ^^^ # ====================================================================================================== # Distribute the necessary file structure of the SPECFEM2D repository that we will downloaded/reference SPECFEM2D_ORIGINAL = os.path.join(WORKDIR, "specfem2d") SPECFEM2D_BIN_ORIGINAL = os.path.join(SPECFEM2D_ORIGINAL, "bin") SPECFEM2D_DATA_ORIGINAL = os.path.join(SPECFEM2D_ORIGINAL, "DATA") TAPE_2007_EXAMPLE = os.path.join(SPECFEM2D_ORIGINAL, "EXAMPLES", "Tape2007") # The SPECFEM2D working directory that we will create separate from the downloaded repo SPECFEM2D_WORKDIR = os.path.join(WORKDIR, "specfem2d_workdir") SPECFEM2D_BIN = os.path.join(SPECFEM2D_WORKDIR, "bin") SPECFEM2D_DATA = os.path.join(SPECFEM2D_WORKDIR, "DATA") SPECFEM2D_OUTPUT = os.path.join(SPECFEM2D_WORKDIR, "OUTPUT_FILES") # Pre-defined locations of velocity models we will generate using the solver SPECFEM2D_MODEL_INIT = os.path.join(SPECFEM2D_WORKDIR, "OUTPUT_FILES_INIT") SPECFEM2D_MODEL_TRUE = os.path.join(SPECFEM2D_WORKDIR, "OUTPUT_FILES_TRUE") ``` -------------------------------- ### Example STATIONS file format Source: https://github.com/adjtomo/seisflows/blob/main/docs/noise_inversion.rst Shows the expected format of the STATIONS file, with columns for network, station, and coordinates. ```default A000 AA 2.43610e+05 2.78904e+05 0.0 0.0 A001 AA 3.38981e+05 1.77849e+05 0.0 0.0 B000 BB 1.64438e+05 2.94733e+05 0.0 0.0 ``` -------------------------------- ### Run Tape2007 example to verify SPECFEM2D works Source: https://github.com/adjtomo/seisflows/blob/main/docs/2D_example_walkthrough.rst Runs the Tape2007 example script and checks that the expected output image exists. If the example fails, the script asserts an error message indicating the remainder of the docs page will not work. The tail of the output log is displayed to show the successful completion. ```bash # Run the Tape2007 example to make sure SPECFEM2D is working as expected os.chdir(TAPE_2007_EXAMPLE) ./run_this_example.sh > output_log.txt assert(os.path.exists("OUTPUT_FILES/forward_image000004800.jpg")), \ (f"Example did not run, the remainder of this docs page will likely not work." f"Please check the following directory: {TAPE_2007_EXAMPLE}") tail output_log.txt ``` -------------------------------- ### Configure SeisFlows and Display First 50 Lines of parameters.yaml Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Runs `seisflows configure` to populate the parameter file with default values based on the chosen modules, then displays the first 50 lines of `parameters.yaml` with `head --lines=50`. ```python ! seisflows configure ! head --lines=50 parameters.yaml ``` -------------------------------- ### Run seisflows submit for line search Source: https://github.com/adjtomo/seisflows/blob/main/docs/2D_example_walkthrough.rst Runs the inversion workflow, which skips already-completed steps and performs a bracketing line search. The output shows the workflow setup, iteration 01, and the first line search trial. ```bash seisflows submit ``` ```default 2022-08-16 14:41:12 (D) | setting iteration==1 from state file 2022-08-16 14:41:12 (I) | ================================================================================ SETTING UP INVERSION WORKFLOW ================================================================================ 2022-08-16 14:41:18 (D) | running setup for module 'system.Workstation' 2022-08-16 14:41:21 (D) | copying par/log file to: /home/bchow/Work/scratch/logs/sflog_003.txt 2022-08-16 14:41:21 (D) | copying par/log file to: /home/bchow/Work/scratch/logs/parameters_003.yaml 2022-08-16 14:41:21 (D) | running setup for module 'solver.Specfem2D' 2022-08-16 14:41:21 (I) | initializing 3 solver directories 2022-08-16 14:41:22 (D) | running setup for module 'preprocess.Default' 2022-08-16 14:41:24 (D) | running setup for module 'optimize.Gradient' 2022-08-16 14:41:26 (I) | re-loading optimization module from checkpoint 2022-08-16 14:41:28 (I) | re-loading optimization module from checkpoint 2022-08-16 14:41:28 (I) | //////////////////////////////////////////////////////////////////////////////// RUNNING ITERATION 01 //////////////////////////////////////////////////////////////////////////////// 2022-08-16 14:41:28 (I) | ================================================================================ RUNNING INVERSION WORKFLOW ================================================================================ 2022-08-16 14:41:28 (I) | 'evaluate_initial_misfit' has already been run, skipping 2022-08-16 14:41:28 (I) | 'run_adjoint_simulations' has already been run, skipping 2022-08-16 14:41:28 (I) | 'postprocess_event_kernels' has already been run, skipping 2022-08-16 14:41:28 (I) | 'evaluate_gradient_from_kernels' has already been run, skipping 2022-08-16 14:41:28 (I) | initializing 'bracket'ing line search 2022-08-16 14:41:28 (I) | enforcing max step length safeguard 2022-08-16 14:41:28 (D) | step length(s) = 0.00E+00 2022-08-16 14:41:28 (D) | misfit val(s) = 1.28E-03 2022-08-16 14:41:28 (I) | try: first evaluation, attempt guess step length, alpha=9.08E+11 2022-08-16 14:41:28 (I) | try: applying initial step length safegaurd as alpha has exceeded maximum step length, alpha_new=1.44E+10 2022-08-16 14:41:28 (D) | overwriting initial step length, alpha_new=2.32E+09 2022-08-16 14:41:28 (I) | trial model 'm_try' parameters: 2022-08-16 14:41:28 (I) | 5800.00 <= vp <= 5800.00 2022-08-16 14:41:28 (I) | 3244.51 <= vs <= 3790.00 2022-08-16 14:41:29 (I) | LINE SEARCH STEP COUNT 01 -------------------------------------------------------------------------------- 2022-08-16 14:41:29 (I) | evaluating objective function for source 001 2022-08-16 14:41:29 (D) | running forward simulation with 'Specfem2D' 2022-08-16 14:41:33 (D) | quantifying misfit with 'Default' 2022-08-16 14:41:33 (I) | evaluating objective function for source 002 2022-08-16 14:41:33 (D) | running forward simulation with 'Specfem2D' ``` -------------------------------- ### List SPECFEM2D working directory contents Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Lists the contents of the SPECFEM2D working directory to confirm that all necessary files (bin, DATA, OUTPUT_FILES_INIT, OUTPUT_FILES_TRUE) are present before running the SeisFlows inversion. ```python # Great, we have all the necessary SPECFEM files to run our SeisFlows inversion! ! ls ``` ```text Output: bin DATA OUTPUT_FILES_INIT OUTPUT_FILES_TRUE ``` -------------------------------- ### Workflow Resume Log Output Source: https://github.com/adjtomo/seisflows/blob/main/docs/2D_example_walkthrough.rst Log output showing the workflow resuming from the stopped point, including setup, running iteration 01, and stopping at evaluate_gradient_from_kernels. ```default 2022-08-16 14:36:42 (D) | setting iteration==1 from state file 2022-08-16 14:36:42 (I) | ================================================================================ SETTING UP INVERSION WORKFLOW ================================================================================ 2022-08-16 14:36:48 (D) | running setup for module 'system.Workstation' 2022-08-16 14:36:51 (D) | copying par/log file to: /home/bchow/Work/scratch/logs/sflog_002.txt 2022-08-16 14:36:51 (D) | copying par/log file to: /home/bchow/Work/scratch/logs/parameters_002.yaml 2022-08-16 14:36:51 (D) | running setup for module 'solver.Specfem2D' 2022-08-16 14:36:51 (I) | initializing 3 solver directories 2022-08-16 14:36:51 (D) | running setup for module 'preprocess.Default' 2022-08-16 14:36:52 (D) | running setup for module 'optimize.Gradient' 2022-08-16 14:36:53 (I) | re-loading optimization module from checkpoint 2022-08-16 14:36:54 (I) | re-loading optimization module from checkpoint 2022-08-16 14:36:54 (I) | //////////////////////////////////////////////////////////////////////////////// RUNNING ITERATION 01 //////////////////////////////////////////////////////////////////////////////// 2022-08-16 14:36:54 (I) | ================================================================================ RUNNING INVERSION WORKFLOW ================================================================================ 2022-08-16 14:36:54 (I) | 'evaluate_initial_misfit' has already been run, skipping 2022-08-16 14:36:54 (I) | //////////////////////////////////////////////////////////////////////////////// EVALUATING EVENT KERNELS W/ ADJOINT SIMULATIONS //////////////////////////////////////////////////////////////////////////////// 2022-08-16 14:36:54 (I) | running SPECFEM executable bin/xspecfem2D, log to 'adj_solver.log' 2022-08-16 14:37:05 (D) | renaming output event kernels: 'alpha' -> 'vp' 2022-08-16 14:37:05 (D) | renaming output event kernels: 'beta' -> 'vs' 2022-08-16 14:37:05 (I) | running SPECFEM executable bin/xspecfem2D, log to 'adj_solver.log' 2022-08-16 14:37:16 (D) | renaming output event kernels: 'alpha' -> 'vp' 2022-08-16 14:37:16 (D) | renaming output event kernels: 'beta' -> 'vs' 2022-08-16 14:37:18 (I) | running SPECFEM executable bin/xspecfem2D, log to 'adj_solver.log' 2022-08-16 14:37:29 (D) | renaming output event kernels: 'alpha' -> 'vp' 2022-08-16 14:37:29 (D) | renaming output event kernels: 'beta' -> 'vs' 2022-08-16 14:37:30 (I) | //////////////////////////////////////////////////////////////////////////////// GENERATING/PROCESSING MISFIT KERNEL //////////////////////////////////////////////////////////////////////////////// 2022-08-16 14:37:30 (I) | combining event kernels into single misfit kernel 2022-08-16 14:37:31 (I) | scaling gradient to absolute model perturbations 2022-08-16 14:37:32 (I) | stop workflow at stop_after: evaluate_gradient_from_kernels ``` -------------------------------- ### List optimization directory contents Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Lists the contents of the optimization directory, showing new values stored for the line search, including g_new and p_new. ```python # We can see that some new values have been stored in prepartion for the line search, # including g_new (current gradient) and p_new (current search direction). These are also # stored as vector NumPy arrays (.npy files) ! ls scratch/optimize ``` ```text Output: checkpoint.npz f_new.txt g_new.npz m_new.npz ``` -------------------------------- ### Resume workflow with seisflows submit Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Uses the `seisflows submit` command to continue an active workflow, resuming from the stopped point based on the state file. ```python # We can use the `seisflows submit` command to continue an active workflow # The state file created during the first run will tell the workflow to resume from the stopped point in the workflow ! seisflows submit ``` -------------------------------- ### Result of parameter changes Source: https://github.com/adjtomo/seisflows/blob/main/docs/notebooks/2D_example_walkthrough.ipynb Output showing the result of the parameter changes, which is 0 indicating success. ```text Result: 0 ```