pinnicle.utils

pinnicle.utils.backends_specified module

pinnicle.utils.backends_specified.jacobian(output_var, input_var, i, j, val=0)

Compute jacobian using deepxde

pinnicle.utils.backends_specified.jacobian_jax(output_var, input_var, i, j, val=0)[source]

Compute jacobian using deepxde This is a hack for now to take the first entry from the tuple returned by jax

pinnicle.utils.backends_specified.jacobian_tf(output_var, input_var, i, j, val=0)[source]

Compute jacobian using deepxde

pinnicle.utils.backends_specified.matmul(A, B)
pinnicle.utils.backends_specified.matmul_jax(A, B)[source]
pinnicle.utils.backends_specified.matmul_tf(A, B)[source]
pinnicle.utils.backends_specified.slice_column(variable, i)

slice the column i:i+1 of variable, tensorflow version

pinnicle.utils.backends_specified.slice_column_jax(variable, i)[source]

slice the column i:i+1 of variable, jax version currently jax output returns tuple (variable, function)

pinnicle.utils.backends_specified.slice_column_tf(variable, i)[source]

slice the column i:i+1 of variable, tensorflow version

pinnicle.utils.backends_specified.slice_function_jax(variable, x, i)[source]

slice the column i:i+1 of function, jax version currently jax output returns tuple (variable, function)

pinnicle.utils.data_misfit module

pinnicle.utils.data_misfit.get(identifier)[source]

Retrieves a loss function.

Parameters:

identifier – A loss identifier. String name of a loss function, or a loss function.

Returns:

A loss function.

pinnicle.utils.data_misfit.loss_dict_jax()[source]
pinnicle.utils.data_misfit.loss_dict_pytorch()[source]
pinnicle.utils.data_misfit.loss_dict_tf()[source]
pinnicle.utils.data_misfit.mean_squared_log_error_jax(y_true, y_pred)[source]

use jax/numpy function to compute mean squared log error

pinnicle.utils.data_misfit.mean_squared_log_error_pytorch(y_true, y_pred)[source]

use jax/numpy function to compute mean squared log error

pinnicle.utils.data_misfit.mean_squared_log_error_tf(y_true, y_pred)[source]

use tensorflow function to compute mean squared log error

pinnicle.utils.data_misfit.surface_log_vel_misfit_jax(v_true, v_pred)[source]

Compute SurfaceLogVelMisfit: This function is for jax

pinnicle.utils.data_misfit.surface_log_vel_misfit_pytorch(v_true, v_pred)[source]

Compute SurfaceLogVelMisfit: This function is for pytorch backend

pinnicle.utils.data_misfit.surface_log_vel_misfit_tf(v_true, v_pred)[source]

Compute SurfaceLogVelMisfit: This function is for tensorflow backend

pinnicle.utils.helper module

members:

undoc-members:

show-inheritance:

pinnicle.utils.history module

class pinnicle.utils.history.History(loss_history, names)[source]

Bases: object

class of the training history, based on deepxde LossHistory only need steps and loss_train

load(path, filename='history.json')[source]

load training history from folder or path

plot(path, figname='history.png', cols=4)[source]

plot the history

save(path, filename='history.json')[source]

save training history

pinnicle.utils.plotting module

pinnicle.utils.plotting.cmap_Rignot()[source]

colormap from ISSM

pinnicle.utils.plotting.diffplot(pinn, feature, feat_title=None, mdata='ISSM', sim='mae', figsize=(15, 4), cmap='jet', scale=1, clim=None, cbar_bins=10, elements=None)[source]
pinnicle.utils.plotting.plot_data(X, Y, im_data, axs=None, vranges={}, **kwargs)[source]

plot all the data in im_data

Parameters:
  • X (np.array) – x-coordinates of the 2D plot

  • Y (np.array) – y-coordinates of the 2D plot

  • im_data (dict) – Dict of data for the 2D plot, each element has the same size as X and Y

  • axs (array of AxesSubplot) – axes to plot each data, if not given, then generate a subplot according to the size of data_names

  • vranges (dict) – range of the data

Returns:

axes of the subplots

Return type:

axs (array of AxesSubplot)

pinnicle.utils.plotting.plot_dict_data(X_dict, data_dict, axs=None, vranges={}, resolution=200, **kwargs)[source]

plot the data in data_dict, with coordinates in X_dict

Parameters:
  • X_dict (dict) – Dict of the coordinates, with keys ‘x’, ‘y’

  • data_dict (dict) – Dict of data

  • axs (array of AxesSubplot) – axes to plot each data, if not given, then generate a subplot according to the size of data_names

  • vranges (dict) – range of the data

  • resolution (int) – number of pixels in horizontal and vertical direction

Returns:

x-coordinates of the 2D plot Y (np.array): y-coordinates of the 2D plot im_data (dict): Dict of data for the 2D plot, each element has the same size as X and Y axs (array of AxesSubplot): axes of the subplots

Return type:

X (np.array)

pinnicle.utils.plotting.plot_nn(pinn, data_names=None, X_mask=None, axs=None, vranges={}, resolution=200, **kwargs)[source]

plot the prediction of the nerual network in pinn, according to the data_names

Parameters:
  • pinn (class PINN) – The PINN model

  • data_names (list) – List of data names

  • X_mask (np.array) – xy-coordinates of the ice mask

  • axs (array of AxesSubplot) – axes to plot each data, if not given, then generate a subplot according to the size of data_names

  • vranges (dict) – range of the data

  • resolution (int) – number of pixels in horizontal and vertical direction

Returns:

x-coordinates of the 2D plot Y (np.array): y-coordinates of the 2D plot im_data (dict): Dict of data for the 2D plot, each element has the same size as X and Y axs (array of AxesSubplot): axes of the subplots

Return type:

X (np.array)

pinnicle.utils.plotting.plot_solutions(pinn, path='', filename='2Dsolution.png', X_ref=None, sol_ref=None, cols=None, resolution=200, absvariable=[], default_time=None, **kwargs)[source]

plot model predictions

Parameters:
  • path (Path, str) – Path to save the figures

  • filename (str) – name to save the figures, if set to None, then the figure will not be saved

  • X_ref (dict) – Coordinates of the reference solutions, if None, then just plot the predicted solutions

  • u_ref (dict) – Reference solutions, if None, then just plot the predicted solutions

  • cols (int) – Number of columns of subplot

  • resolution (int) – Number of grid points per row/column for plotting

  • absvariable (list) – Names of variables in the predictions that will need to take abs() before comparison

pinnicle.utils.plotting.plot_tracks(pinn, feature, filepath=None, x_name_map='x', y_name_map='y', feat_name_map=None, gdata=None, mdata='ISSM', elements=None, scale=1, cmap='jet', figsize=(10, 8), clim=None, cbar_bins=10)[source]

plotting (sparse) ground truth data on top of prediction

pinnicle.utils.plotting.resplot(pinn, mdata='ISSM', figsize=None, cmap='RdBu', cbar_bins=10, cbar_limits=[-5000.0, 5000.0], elements=None)[source]

plotting the pde residuals

pinnicle.utils.plotting.tripcolor_residuals(pinn, cmap='RdBu', colorbar_bins=10, cbar_limits=[-5000.0, 5000.0])[source]

plot pde residuals with ISSM triangulation

pinnicle.utils.plotting.tripcolor_similarity(pinn, feature_name, feat_title=None, mdata='ISSM', sim='MAE', cmap='jet', scale=1, colorbar_bins=10, elements=None)[source]

tripcolor similarity, plot with ISSM triangulation