Skip to content

Instantly share code, notes, and snippets.

@marekyggdrasil
marekyggdrasil / lodash_find_gets_reference.js
Last active March 19, 2016 04:03
Does the lodash _.find returns reference to the object?
code:
console.log('socket.io', token);
console.log(realtime);
let session = yield _.find(realtime, function(data) {
return data.token === token;
});
console.log('session object to be set');
console.log(session);
if (!session.socket) {
@marekyggdrasil
marekyggdrasil / README.md
Last active August 12, 2017 08:25
This gist is a reference about different Gym agent algorithms that accept only Box as observation space. Here's the link https://discuss.openai.com/t/any-algorithms-compatible-with-observation-space-other-than-box/2276 to the thread, if you want to give feedback please write it there.
@marekyggdrasil
marekyggdrasil / el4.py
Created June 18, 2018 03:12
File that tests functionality of integral MathML parser for issue: https://github.com/allofphysicsgraph/graph/issues/7
from tools.ContentMathML import mml2sympy
from lxml import etree
xml = """
<apply>
<int/>
<bvar><ci>x</ci></bvar>
<lowlimit><cn>a</cn></lowlimit>
<uplimit><ci>b</ci></uplimit>
<apply>
@marekyggdrasil
marekyggdrasil / exampleDLX.py
Created September 28, 2018 10:58
There is a publicly available library for DLX algorithm (also known as 'Algorithm X' or 'Dancing Links' algorithm) available at https://pypi.org/project/dlx/
from dlx import DLX
def genInstance(labels, rows) :
columns = []
indices_l = {}
for i in range(len(labels)) :
label = labels[i]
indices_l[label] = i
columns.append(tuple([label,0]))
return labels, rows, columns, indices_l
@marekyggdrasil
marekyggdrasil / exampleDLX.py
Created September 28, 2018 10:59
There is a publicly available library for DLX algorithm (also known as 'Algorithm X' or 'Dancing Links' algorithm) available at https://pypi.org/project/dlx/, unfortunately it comes with no documentation, I needed it so I made couple of (dirty) wrapper functions to make it work and came up with this example. Hope you'll find it useful!
from dlx import DLX
def genInstance(labels, rows) :
columns = []
indices_l = {}
for i in range(len(labels)) :
label = labels[i]
indices_l[label] = i
columns.append(tuple([label,0]))
return labels, rows, columns, indices_l
@marekyggdrasil
marekyggdrasil / aqc.py
Last active October 2, 2018 04:43
Running AQC (Adiabatic Quantum Computation) on spin chain of size N=8 and N=2 for debugging. Printing probabilities of each sping configuration for N=8 in the middle of time evolution and for N=2 at the end of time evolution (for debugging).
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from qutip import *
from scipy import *
def operators(N) :
si = qeye(2)
@marekyggdrasil
marekyggdrasil / example.py
Last active May 2, 2019 04:35
I encountered a problem related to usage of lambda functions to pass extra arguments to initial value problem solved from SciPy while used inside of Jupyter notebook environment. Perhaps someone more experienced with Jupyter could help out in the comments.
from scipy.integrate import solve_ivp
import numpy as np
def exponential_decay(t, y, alpha, beta): return -alpha*y + beta
for alpha in np.linspace(0.5, 0.7, 5) :
beta = 1.
sol = solve_ivp(lambda t, y: exponential_decay(t, y, alpha, beta), [0, 10], [2, 4, 8])
@marekyggdrasil
marekyggdrasil / run.py
Created May 14, 2019 08:21
(1) keep increasing xi (2) for every xi increase nmax to nmax + 1 and expect same spectrum
( todo )
@marekyggdrasil
marekyggdrasil / out.txt
Last active October 25, 2019 02:44
Creating step-based tests in Python with alternative execution paths. In this example we want to perform a test which always starts with `step_a` and always ends with `step_d` but in the middle can take either `step_b` and `step_c` either alternative steps. We test if final number is `12` and it can be obtained as `3*4=12` or `2*6=12` and those …
$ python -m pytest run.py -vvv
============================= test session starts ==============================
platform darwin -- Python 3.5.3, pytest-4.2.0, py-1.8.0, pluggy-0.12.0 -- /Users/marek/.pyenv/versions/3.5.3/bin/python
cachedir: .pytest_cache
rootdir: /Users/marek/Development/qtl/36a5d4cb5674e14792b03b4f79b89402, inifile:
plugins: steps-1.6.4, timeout-1.3.3, flaky-3.6.1
collected 8 items
braids_test.py::test_scenario_1[step_a] PASSED [ 12%]
braids_test.py::test_scenario_1[step_b] PASSED [ 25%]
@marekyggdrasil
marekyggdrasil / berendsen_temperature.xvg
Created October 31, 2019 04:46
Calculating histograms from GROMACS xvg files using Python
# This file was created Wed Oct 30 15:12:39 2019
# Created by:
# :-) GROMACS - gmx energy, 2018 (-:
#
# Executable: /gpfsnyu/packages/gromacs/gnu/2018/bin/gmx
# Data prefix: /gpfsnyu/packages/gromacs/gnu/2018
# Working dir: /gpfsnyu/home/mmn362/CompChem/Practicum3/Step10b
# Command line:
# gmx energy -f md.edr -o berendsen_temperature.xvg
# gmx energy is part of G R O M A C S: