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
Get["https://raw.githubusercontent.com/lucainnocenti/quantum-gate-learning-1803.07119-Mathematica-code/master/QPauliAlgebra.m"]
HTildeToff = \[Pi]/8 QPauliExpr[
(1 + 4 (\[Nu]1 + \[Nu]2 + \[Nu]3 + \[Nu]4))
+ 2 (4 (\[Nu]1 - \[Nu]2) - 1) x[3]
- (z[1] + z[2]) (1 - x[3])
+ (1 + 4 (\[Nu]1 + \[Nu]2 - \[Nu]3 - \[Nu]4)) z[1] z[2]
+ Sqrt[-((1 -
4 (\[Nu]1 - \[Nu]2))^2 - (4 (\[Nu]3 - \[Nu]4))^2)] (z[1] -
z[2]) z[3]
];
@lucainnocenti
lucainnocenti / displacedFockProbs.m
Created December 17, 2019 19:01
Mathematica snippets to compute photon number distributions of displaced Fock states, and maybe other stuff
displacedFockProbs[n_, mu_, k_] := Times[
k! / n! * mu^(k - n),
Exp[-mu],
Sum[Binomial[n, j] (-mu)^j / (k - n + j)!, {j, n - k, n}]^2
];
@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]};
@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 / 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 / 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 / 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 / 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):
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 +
#!/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'