Skip to main content

Azure TTI RTM Example

Sketches the updated workflow for running BP2007 TTI RTM on Azure using the new API.

import json
from dask.distributed import Client

from devitohorizon.cloud.azure import azure_vm_cluster
from devitohorizon.data import Dataset
from devitohorizon.physics import DevitoPhysics
from devitohorizon.scheduler import DaskScheduler
with open('azure_creds.json') as f:
    creds = json.load(f)
container = creds['container_name']
param_runtime = {
    'nbl': 40,
    'space_order': 16,
    'parameters': ('m',),
    'gradient': {'mute': {'type': 'datum'}},
    'model': {
        'vp': f"{container}/Vp_Model.sgy",
        'epsilon': f"{container}/Epsilon_Model.sgy",
        'delta': f"{container}/Delta_Model.sgy",
        'theta': f"{container}/Theta_Model.sgy",
    },
    'data_path': f"{container}/shots",
    'data_format': 'segy',
    'creds': creds,
}
print('Blob prefix:', param_runtime['data_path'])
# NBVAL_SKIP
cluster = azure_vm_cluster(creds, vm_size='Standard_DS3_v2', n_workers=8)
client = Client(cluster)
print('Dashboard:', client.dashboard_link)
# NBVAL_SKIP
dataset = Dataset.from_segy(param_runtime['data_path'], creds=creds)
physics = DevitoPhysics(
    nbl=param_runtime['nbl'],
    space_order=param_runtime['space_order'],
    parameters=param_runtime['parameters'],
    model=param_runtime['model'],
    gradient=param_runtime['gradient'],
    # The model needs its own credentials and container, not just paths that
    # happen to name one: they are what lets a worker open the model, and what
    # tells the run it has storage every node can reach.  Without them the
    # staged model and the compiled operators go to a local directory the
    # workers cannot see.
    creds=creds,
    container_name=container,
)
print('Shots:', len(dataset))
# NBVAL_SKIP
# Submit distributed RTM via Dask
shot_ids = [200, 400, 800, 1200]
shots = [dataset[i] for i in shot_ids]
scheduler = DaskScheduler(client)
misfit, grads = physics.objective(shots, scheduler=scheduler)
stacked = next(iter(grads.values()))
print('Average misfit:', misfit)
client.close()
cluster.close()
Back to top