Skip to content

Instantly share code, notes, and snippets.

View madagra's full-sized avatar

Mario Dagrada madagra

View GitHub Profile
final_loss = \
# average over all the colocation points
de_loss_vec.pow(2).mean() + \
# simply square the boundary contribution which is a single value
boundary_loss ** 2
de_loss_vec = dfdt(nn, t) - R * t * (1 - t)
T_0 = 0
F_0 = 1
boundary = torch.Tensor([T_0])
boundary.requires_grad = True
boundary_loss = f(nn, boundary) - F0
import torch
def f(nn: NNApproximator, x: torch.Tensor) -> torch.Tensor:
"""Compute the value of the approximate solution from the NN model"""
return nn(x)
def df(nn: NNApproximator, x: torch.Tensor = None, order: int = 1) -> torch.Tensor:
"""Compute neural network derivative with respect to the input feature(s) using PyTorch autograd engine"""
df_value = f(nn, x)
from torch import nn
class NNApproximator(nn.Module):
def __init__(
self,
num_inputs: int = 1,
num_outputs: int = 1,
num_hidden: int = 1,
dim_hidden: int = 1,
act: nn.Module = nn.Tanh(),
resource "aws_iam_policy" "snapshot_passrole_policy" {
name = "snapshot_passrole_policy"
path = "/"
description = "Allow role to assume the snapshot role to create OpenSearch snapshots"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
module "lambda" {
source = "terraform-aws-modules/lambda/aws"
function_name = "lambda-es-backup"
description = "OpenSearch domain snapshot backup"
handler = "es_snapshot_handler.lambda_handler"
runtime = "python3.9"
attach_policy = true
data "aws_iam_policy_document" "es_role_policy" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["es.amazonaws.com"]
}
}
}
import os
from datetime import datetime
from uuid import uuid4
import boto3
import requests
from requests_aws4auth import AWS4Auth
# configuration
resource "aws_cloudwatch_event_rule" "cron_schedule" {
name = "es_backup_lambda_cron_schedule"
description = "Daily execution"
schedule_expression = "rate(1 day)"
}