Skip to content

Instantly share code, notes, and snippets.

View madagra's full-sized avatar

Mario Dagrada madagra

View GitHub Profile
module "acm" {
source = "terraform-aws-modules/acm/aws"
domain_name = var.domain_name
zone_id = aws_route53_zone.this.zone_id
wait_for_validation = true
tags = {
resource "aws_lb_target_group" "pypi_tg" {
name = "pypi-tg"
port = 8080
protocol = "HTTP"
vpc_id = var.vpc_id
}
resource "aws_lb_target_group_attachment" "pypi_tg_attachment" {
target_group_arn = aws_lb_target_group.pypi_tg[0].arn
target_id = aws_instance.pypi.id
resource "aws_cloudwatch_event_rule" "cron_schedule" {
name = "es_backup_lambda_cron_schedule"
description = "Daily execution"
schedule_expression = "rate(1 day)"
}
import os
from datetime import datetime
from uuid import uuid4
import boto3
import requests
from requests_aws4auth import AWS4Auth
# configuration
data "aws_iam_policy_document" "es_role_policy" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["es.amazonaws.com"]
}
}
}
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
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": [
{
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(),
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)
T_0 = 0
F_0 = 1
boundary = torch.Tensor([T_0])
boundary.requires_grad = True
boundary_loss = f(nn, boundary) - F0