Skip to content

Instantly share code, notes, and snippets.

View Strilanc's full-sized avatar

Craig Gidney Strilanc

View GitHub Profile
from typing import Iterable, Tuple
import time
import numpy as np
def to_mask(word: str) -> int:
"""Converts a word into a bitmask where each bit indicates presence of a letter."""
t = 0
for c in word:
@Strilanc
Strilanc / stim_tableau_vs_circuit.py
Created July 13, 2022 23:59
Code to convert a stim.Circuit into an equivalent stim.Tableau and a stim.Tableau into an equivalent stim.Circuit. The circuit decomposition isn't efficient but it's simple to write.
from typing import List
import stim
def circuit_to_tableau(circuit: stim.Circuit) -> stim.Tableau:
s = stim.TableauSimulator()
s.do_circuit(circuit)
return s.current_inverse_tableau() ** -1
@Strilanc
Strilanc / scratch.py
Created July 7, 2022 17:03
Generating a depth 52 14-controlled-X using measurement based uncomputation
from typing import Optional, Dict
import cirq
def compose(*gates: cirq.Gate) -> cirq.Gate:
matrix = cirq.unitary(gates[0])
for g in gates[1:]:
matrix = cirq.unitary(g) @ matrix
return cirq.MatrixGate(matrix)
@Strilanc
Strilanc / hastings_stim_pymatching.py
Created July 12, 2021 00:02
Estimating the threshold of a new quantum code using stim and pymatching.
import csv
import pathlib
import time
from dataclasses import dataclass
from typing import Callable, List, Dict, Any, Set, FrozenSet, Iterable, Tuple
import math
import pymatching
import networkx as nx
import stim
import matplotlib.pyplot as plt
@Strilanc
Strilanc / webgl_cube.html
Created June 9, 2020 01:37
Chopped down webgl cube example
<html>
<body>
<script>
let canvas = document.createElement('canvas');
document.body.appendChild(canvas);
let gl = canvas.getContext('webgl');
if (!gl) {
throw new Error("!gl")
}
@Strilanc
Strilanc / minimal_web_xr.html
Created March 1, 2020 23:03
The bare minimum needed to render to an immersive headset.
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>WebXR Testing</title>
</head>
<body>
<input id="button_enter" type="button" value="Loading..." disabled/>
<script>
const GL = WebGLRenderingContext;
@Strilanc
Strilanc / sim-factor.py
Created May 9, 2019 08:15
Simulates samples that Shor's algorithm would generate, in order to estimate how often factoring succeeds.
from typing import Optional, List, Dict, Callable, Any
from collections import defaultdict
import fractions
import math
import random
import sys
import matplotlib.pyplot as plt
@Strilanc
Strilanc / high_persistence_of_multiplication_search.py
Created March 22, 2019 05:54
Code to search for numbers with large persistence of multiplication. Finds the largest known ones in under a second.
def persistence(n):
t = 0
while n >= 10:
t += 1
n2 = 1
for d in str(n):
n2 *= int(d)
n = n2
return t
@Strilanc
Strilanc / zach-linear-3-sat.py
Last active October 4, 2016 01:18
For the record, the algorithm works just fine on this problem. Here's a simple python script that sets up the transfer matrix and finds the eigenvalues/eigenvectors:
from itertools import *
import string
from numpy import *
from scipy import *
from scipy.linalg import *
#Script for setting up transfer matrix describing the evolution of diagonal
#elements of the density matrix given a list of three variable clauses.
#
#The Transfer matrix maps the vector of state populations (diagonal elements of
@Strilanc
Strilanc / polynomial-root-phase-diagram.py
Created August 31, 2016 17:43
Renders colorful density plots of the roots of polynomials with coefficients drawn from a small set of sets.
import numpy as np
import cv2
import itertools
import math
import cmath
w = h = 1024
deg = 11
# The root phases to sample frame, and the color that goes with each.