Skip to content

Instantly share code, notes, and snippets.

View rish-16's full-sized avatar
🤖
backpropagating through memories

Rishabh Anand rish-16

🤖
backpropagating through memories
View GitHub Profile
import qiskit as qk
# Load saved account from memory
qk.IBMQ.load_accounts()
n = 3
q = qk.QuantumRegister(n)
c = qk.ClassicalRegister(n)
circ = qk.QuantumCircuit(q, c)
@rish-16
rish-16 / ma2108_note1.md
Created August 30, 2022 04:00
MA2108 Note 1

MA2108 Note 1

Definitions

  1. A set is an unordered collection of unique elements. Examples are natural numbers, integers, rational numbers, and real numbers
  2. Cartesian product of $A$ and $B$ is $A \times B = \lbrace(a, b) : a \in A, b \in B\rbrace$
  3. A function from set $A$ to set $B$ is a rule of correspondence that assigns each element $x \in A$ to uniquely determined element $f(x) \in B$
  4. Set $A$ is called the domain of $f$
  5. Set $B$ is the codomain of $f$
  6. The set $f(A) = \lbrace(x) : x \in A\rbrace$ is called the range of $f$
  7. Althought $D(f) = A$, we only have $R(f) \subseteq B$
@rish-16
rish-16 / WCT_Intro_Writing.md
Last active May 29, 2022 22:13
Notes from UWC2101AC on writing comprehensive introductions

Essay Writing

  1. Effective Thesis
  2. Parenthetical Citation
  3. Essay Structure
  4. Editing Tips
  5. Peer Editing

Effective Thesis

  • Tells a reader how you will interpret the significance of the subject matter under discussion. Such a statement is a debatable, overarching claim organising an essay
@rish-16
rish-16 / cs4243.py
Last active March 29, 2022 06:16
CS4243 PyTorch Snippets
import torch
import torch.nn as nn
import torch.nn.functional as F
"""
Creating tensors
"""
a = torch.rand(...) # returns a torch.Tensor
b = torch.LongTensor(10).random_(0, 2) # 10-dim vector from [0, 1]
@rish-16
rish-16 / tf_seed.py
Created July 5, 2021 05:30
TensorFlow Experiment Seeding for GPUs
import os
import numpy as np
import random
import tensorflow as tf
from tfdeterminism import patch
def seed(s=42):
random.seed(s)
np.random.seed(s)
tf.random.set_seed(s)
@rish-16
rish-16 / dataset_dwnld_dir.py
Created May 29, 2021 07:09
A guide on Colab TPU training using PyTorch XLA (Part 5.1)
PATH = "./my_dataset/" # path to dataset on Colab instance
TRAIN_PATH = PATH + "train/"
VAL_PATH = PATH + "val/"
# your custom augmentations
T = transforms.Compose([
transforms.ToTensor(),
...
])
@rish-16
rish-16 / model.py
Created May 29, 2021 06:31
A guide on Colab TPU training using PyTorch XLA (Part 7)
device = xm.xla_device()
# define some hyper-params you'd feed into your model
in_channels = ...
random_param = ...
# create model using appropriate hyper-params
net = MyCustomNet(...)
# seat it atop the TPU worker device and switch it to train mode
@rish-16
rish-16 / datagen.py
Created May 29, 2021 06:20
A guide on Colab TPU training using PyTorch XLA (Part 6)
'''
num_replicas is the total number of times we'll replicate
the batch samples for all cores.
'''
train_sampler = torch.utils.data.distributed.DistributedSampler(
im_train,
num_replicas=xm.xrt_world_size(),
rank=xm.get_ordinal(),
shuffle=True
)
@rish-16
rish-16 / download.py
Created May 29, 2021 10:22
A guide on Colab TPU training using PyTorch XLA (Part 5.2)
!wget http://www.some_dataset_website.com/my_dataset.tar.gz
!tar -xvzf my_dataset.tar.gz
@rish-16
rish-16 / patch_viz.py
Last active December 22, 2021 06:39
Visualise selected patches from an image for comparison / sanity checks
import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import transforms
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
from patchify import patchify, unpatchify # pip install patchify