Skip to content

Instantly share code, notes, and snippets.

View ericspod's full-sized avatar

Eric Kerfoot ericspod

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ericspod
ericspod / check_environment.py
Created April 21, 2025 15:13
Environment check script
#! /usr/bin/env python
"""
Script for checking various elements of the runtime environment and print a large amount of diagnostic information.
This is meant to be used for debugging environments used with MONAI, but doesn't directly need MONAI itself. It will
print information about the environment including trying to get installed packages, test PyTorch with CUDA, and then
have MONAI print its debugging information if no errors encountered. If MONAI is not installed this script should still
work and produce useful information.
"""
@ericspod
ericspod / pytorch_test.py
Last active April 14, 2025 16:43
Pytorch Test Script
import torch
print("Version=",torch.__version__)
print("CUDA=",torch.cuda.is_available())
for i in range(torch.cuda.device_count()):
props=torch.cuda.get_device_properties(i)
print(f" {props.name}, mem={int(props.total_memory/2**20)}MiB")
@ericspod
ericspod / clean_code.md
Created April 20, 2023 11:44 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@ericspod
ericspod / format_json.py
Last active July 4, 2024 14:53 — forked from jannismain/CompactJSONEncoder.py
A JSON Encoder in Python, that puts small lists on single lines.
import os
import sys
import json
import datetime
from typing import Union
# from https://gist.github.com/jannismain/e96666ca4f059c3e5bc28abb711b5c92
class CompactJSONEncoder(json.JSONEncoder):
@ericspod
ericspod / attachable_test.py
Created April 26, 2020 21:37
Attachable Test
from ignite.engine import Events, Engine
class Attachable:
"""
This class contains an internal dictionary `attach_map` associating events with the bound methods to be triggered
on those events. This dictionary can be populated by the contructor or by external clients after construction and
before `attach` is called.
"""
def __init__(self, attach_map):
self.attach_map = dict(attach_map)
@ericspod
ericspod / baseengine.py
Last active April 11, 2021 23:29
Base Engine, Trainer, and Evaluator
import torch
import warnings
import threading
import numpy as np
from ignite.engine.engine import Engine, Events
def ensure_tuple(vals):
"""
Returns a tuple containing just `vals` if it is not a list or tuple, or `vals` converted to a tuple otherwise.
@ericspod
ericspod / matrixops.py
Created July 29, 2019 15:56
Matrix operations not needed
def matZero(n,m):
'''Return a list of lists with the given dimensions containing zeros.'''
return [[0]*m for i in range(n)]
def matIdent(n):
'''Return a list of lists defining the identity matrix of rank `n'.'''
mat=matZero(n,n)
for nn in range(n):
mat[nn][nn]=1.0
@ericspod
ericspod / decimatetets.py
Created August 10, 2018 15:40
Decimate Tets with VTK
import vtk
import os,sys,math
# read unstructured grid
r=vtk.vtkXMLUnstructuredGridReader()
r.SetFileName(sys.argv[1]) # first command line argument after script name
r.Update()
orig=r.GetOutput()