Skip to content

Commit

Permalink
Merge branch 'main' into paper
Browse files Browse the repository at this point in the history
  • Loading branch information
sgbaird committed Jun 10, 2022
2 parents 21fc69d + 96ef7e4 commit a5c332d
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ MANIFEST
src/xtal2png/meta.yaml
xtal2png/meta.yaml
tmp/**
results/model-*.pt
results/sample-*.png
34 changes: 31 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# CHANGELOG

## Unreleased

Changes unreleased.

### Bug Fixes

- general:
- fix typos, remove extraneous figure, add future work ([d0ffb91](https://github.com/sparks-baird/xtal2png/commit/d0ffb917e062c0a580a42dc5ee5309c4e036e48f)) ([#67](https://github.com/sparks-baird/xtal2png/pull/67))

## [v0.4.0](https://github.com/sparks-baird/xtal2png/releases/tag/v0.4.0) - 2022-06-03 02:01:29

<!-- Release notes generated using configuration in .github/release.yml at v0.4.0 -->

## What's Changed
### Other Changes
* available on conda-forge by @sgbaird in https://github.com/sparks-baird/xtal2png/pull/49
* fix colab link in index.md by @sgbaird in https://github.com/sparks-baird/xtal2png/pull/53
* add colab link to README by @sgbaird in https://github.com/sparks-baird/xtal2png/pull/52
* fixup colab link by @sgbaird in https://github.com/sparks-baird/xtal2png/pull/56
* add note about needing development versions of pyscaffold and extensions by @sgbaird in https://github.com/sparks-baird/xtal2png/pull/58
* Support rgb images in `png2xtal` by converting to grayscale by @sgbaird in https://github.com/sparks-baird/xtal2png/pull/62


**Full Changelog**: https://github.com/sparks-baird/xtal2png/compare/v0.3.0...v0.4.0

### Bug Fixes

- general:
- fixup colab link ([7803383](https://github.com/sparks-baird/xtal2png/commit/7803383b2e1acbb565b417d82606a6c40ac425b8)) ([#56](https://github.com/sparks-baird/xtal2png/pull/56))
- fix colab link in index.md ([7ff9bfa](https://github.com/sparks-baird/xtal2png/commit/7ff9bface93181f40fcf9e733dd082f737249b74)) ([#53](https://github.com/sparks-baird/xtal2png/pull/53))

## [v0.3.0](https://github.com/sparks-baird/xtal2png/releases/tag/v0.3.0) - 2022-05-31 17:28:49

<!-- Release notes generated using configuration in .github/release.yml at v0.3.0 -->
Expand Down Expand Up @@ -61,10 +92,7 @@ Feature ranges for `a`, `b`, `c`, `volume`, and `distance` are chosen based on M

## [v0.1.6](https://github.com/sparks-baird/xtal2png/releases/tag/v0.1.6) - 2022-05-27 05:36:46

- no changes

<!-- Release notes generated using configuration in .github/release.yml at v0.1.6 -->

## What's Changed
### Other Changes
* minor typos, clarification by @sgbaird in https://github.com/sparks-baird/xtal2png/pull/29
Expand Down
19 changes: 19 additions & 0 deletions notebooks/3.0-denoising-diffusion.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"language_info": {
"name": "python"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
49 changes: 49 additions & 0 deletions notebooks/ddpm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from os import path

from denoising_diffusion_pytorch import GaussianDiffusion, Trainer, Unet
from mp_time_split.core import MPTimeSplit

from xtal2png.core import XtalConverter

mpt = MPTimeSplit()
mpt.load()

fold = 0
train_inputs, val_inputs, train_outputs, val_outputs = mpt.get_train_and_val_data(fold)

data_path = path.join("data", "preprocessed", "mp-time-split")
xc = XtalConverter(save_dir=data_path)

model = Unet(dim=64, dim_mults=(1, 2, 4, 8), channels=1).cuda()

diffusion = GaussianDiffusion(
model,
channels=1,
image_size=64,
timesteps=10000, # number of steps
loss_type="l1", # L1 or L2
).cuda()

trainer = Trainer(
diffusion,
data_path,
image_size=64,
train_batch_size=2,
train_lr=2e-5,
train_num_steps=700000, # total training steps
gradient_accumulate_every=2, # gradient accumulation steps
ema_decay=0.995, # exponential moving average decay
amp=True, # turn on mixed precision
)

trainer.train()

sampled_images = diffusion.sample(batch_size=100)

# import numpy as np
# from PIL import Image
# data = np.squeeze(sampled_images.cpu().numpy())
# imgs = []
# for d in data:
# img = Image.fromarray(d, mode="L")
# imgs.append(img)
2 changes: 1 addition & 1 deletion reports/paper.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ authors:
orcid: 0000-0002-6583-7755
equal-contrib: false
affiliation: "1" # (Multiple affiliations must be quoted)
- name: Michael Alverson
- name: Michael D. Alverson
orcid: 0000-0002-4857-7584
equal-contrib: false
affiliation: "1, 2" # (Multiple affiliations must be quoted)
Expand Down
41 changes: 33 additions & 8 deletions scripts/run_grayskull.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Touch up the conda recipe from grayskull using conda-souschef."""
import os
from copy import deepcopy
from copy import copy
from os import getcwd
from os.path import basename, dirname, join, normpath
from pathlib import Path
from shutil import copyfile
from warnings import warn

import numpy as np
from souschef.recipe import Recipe

import xtal2png as module
Expand All @@ -16,6 +17,11 @@

name, version = module.__name__, module.__version__

replace_underscores_with_hyphens = True

if replace_underscores_with_hyphens:
name = name.replace("_", "-")

src_dirname = "src"
if basename(normpath(getcwd())) != src_dirname:
warn(
Expand Down Expand Up @@ -45,12 +51,31 @@

my_recipe = Recipe(load_file=fpath)

bld = my_recipe["build"]
bld.add_section({"noarch": "python"})
blank_line = deepcopy(bld.value[bld.value.index("")])
bld.value[bld.value.index("")].remove()
# how to add blank_line back in? Following doesn't seem to work:
bld.value = bld.value + [blank_line]
# ensure proper order for conda-forge
keys = list(my_recipe.keys())

# https://docs.conda.io/projects/conda-build/en/latest/resources/define-metadata.html
key_order = [
"package",
"source",
"build",
"requirements",
"test",
"outputs",
"about",
"app",
"extra",
]
unshared_keys = np.setdiff1d(key_order, keys)

ordered_keys = copy(key_order)
for key in unshared_keys:
ordered_keys.remove(key)

for key in ordered_keys:
my_recipe.yaml.move_to_end(key)

my_recipe["build"].add_section({"noarch": "python"})

try:
del my_recipe["build"]["skip"]
Expand Down Expand Up @@ -81,7 +106,7 @@
# my_recipe["about"].insert(0, "key", "value")

# # sometimes package names differ between PyPI and Anaconda (e.g. `kaleido`)
# my_recipe["requirements"]["run"].replace("kaleido", "python-kaleido")
my_recipe["requirements"]["run"].replace("kaleido", "python-kaleido")

# # It's better to install some packages either exclusively via Anaconda or
# # via custom PyPI installation instructions (see e.g. the selectable table from:
Expand Down

0 comments on commit a5c332d

Please sign in to comment.