Skip to content

Instantly share code, notes, and snippets.

View lucainnocenti's full-sized avatar

Luca Innocenti lucainnocenti

  • University of Palermo
  • Palermo
View GitHub Profile
@lucainnocenti
lucainnocenti / Some math notes
Last active August 29, 2015 14:15
Some math notes
[toc]
Mittag-Leffler expansions
============
Let $f(z)$ be a complex function with an infinite number of *simple* poles $z_n$, and holomorphic at the origin. Suppose also that the poles are ordered in the following way
$$ 0 < | z_1| \leq | z_2 | \le \dots \le | z_n| \le \dots $$
If
1. $\mathcal{C}_n$ is a contour encircling all poles up to $z_n$,
@lucainnocenti
lucainnocenti / harmonic-oscillator.md
Created February 17, 2015 15:45
Linear harmonic oscillator

#Linear Harmonic Oscillator [toc]

Consider the linear oscillator equation $$ \tag{LHO} y'' + \omega^2 y = 0. $$ We want to solve this equation using a series expansion around the origin. ##Frobenius Solution Method Start with the Ansatz $$ y(x) = x^\rho \sum_{n=0}^\infty c_n x^n, $$ where $c_0 \neq 0$ by definition (otherwise we would just rename the coefficients and absorb into $\rho$ the lowest power of $x$). Using this into the original differential equation gives the condition

#!/usr/bin/python3
import struct
import os
import time
start_time = time.time()
# ============ CONSTANTS TO (OPTIONALLY) SET =============
WINDOW_SIZE = 100
INPUT_FILE_NAME = 'data_lab\\timetags5byte.bin'
# OUTPUT_FILE_NAME = 'output.txt'
base6ToBase10Conversion[n_Integer] :=
ToExpression[StringJoin["6^^", ToString@n]]
labelToIndex[label_String] := With[{
elementsConversionRules = {"H" -> 0, "V" -> 1, "D" -> 2, "A" -> 3,
"L" -> 4, "R" -> 5}
},
If[
StringLength@label == 4,
-(1 +
@lucainnocenti
lucainnocenti / rbm_after_refactor.py
Created November 20, 2017 09:53 — forked from gabrieleangeletti/rbm_after_refactor.py
Restricted Boltzmann Machine implementation in TensorFlow, before and after code refactoring. Blog post: http://blackecho.github.io/blog/programming/2016/02/21/refactoring-rbm-tensor-flow-implementation.html
import tensorflow as tf
import numpy as np
import os
import zconfig
import utils
class RBM(object):
@lucainnocenti
lucainnocenti / CodeMirror-add-italic-shortcut.js
Last active February 25, 2018 20:48
Execute this code in the console to add the `Cmd-I` shortcut for markdown italic to all CodeMirror cells in the page. Tested on Google Colaboratory.
var script = document.createElement('script');
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(script);
map = {'Cmd-I': function(cm) {
var s = cm.getSelection(),
t = s.slice(0, 1) === '*' && s.slice(-1) === '*';
cm.replaceSelection(t ? s.slice(1, -1) : '*' + s + '*', 'around');
}};
$('.CodeMirror').each(function() {
$(this)[0].CodeMirror.addKeyMap(map);
@lucainnocenti
lucainnocenti / plot_estimates_average_gate_fidelity.py
Last active May 30, 2018 11:56
Produces a plot to see how well the true gate fidelity is estimated, for different sample sizes
import progressbar
import numpy as np
import matplotlib.pyplot as plt
import qutip
def average_fidelity(U, V, sample_size):
total = 0
for idx in range(sample_size):
psi = qutip.rand_ket_haar(8)
total += np.abs((psi.dag() * U.dag() * V * psi)[0, 0])**2
@lucainnocenti
lucainnocenti / bibitem-sorter.py
Last active December 13, 2023 06:17
Python script to sort the bibitem entries according to the citation order in the text. Useful when one has for some reason to not use bibtex and .bib files. Usage is as `python bibitem-sorter.py file.tex sorted_file.tex`
import argparse
import os
import sys
import re
def printBold(msg):
HEADER = '\033[95m'
BOLD = '\033[1m'
print(HEADER + BOLD + msg + '\x1b[0m')
@lucainnocenti
lucainnocenti / latex-clean.sh
Created August 2, 2018 23:03
Small script to clean a folder from latex auxiliary files
#!/bin/sh
arg=${1:-.}
exts="aux bbl blg brf idx ilg ind lof log lol lot out toc synctex.gz fls fdb_latexmk run.xml bcf"
if [ -d $arg ]; then
for ext in $exts; do
rm -f $arg/*.$ext
done
rm -f $arg/*Notes.bib
@lucainnocenti
lucainnocenti / QW-for-QSE_conditions_on_ds.m
Last active November 11, 2019 11:35
Generate conditions for the ds parameters, as per QW paper. See also https://github.com/lucainnocenti/QSE-with-QW-code.
(* Create the expressions that must be satisfied by the d_s coefficients to generate a specific target
state after the coin is projected onto the + state. *)
generateConditionsForDs[n_, s_] := Sum[
Conjugate[u[i] - d[i]] (u[i + n - s] - d[i + n - s]) + Conjugate[d[i + 1]] d[i + n - s + 1],
{i, 1, s}
] /. {d[1] -> 0, d[n + 1] -> u[n + 1]};