Skip to content

Instantly share code, notes, and snippets.

import numpy as np
import matplotlib.pyplot as plt
p = np.linspace(0,1j*2*np.pi,50)
θ = np.linspace(0,np.pi/2,50)
P,Θ = np.meshgrid(p,θ)
m = np.exp(P)*np.sin(Θ)*np.cos(Θ) + np.sin(Θ)**2
b = m.flatten()
r,i = np.real(b), np.imag(b)
import matplotlib.pyplot as plt
from qiskit import *
from qiskit.tools.monitor import job_monitor
from qiskit.tools.visualization import plot_bloch_multivector, plot_histogram
from math import pi
qr = QuantumRegister(3, name="q")
crz, crx = ClassicalRegister(1, name="crz"), ClassicalRegister(1, name="crx")
c0 = ClassicalRegister(1, name="c0")
import qutip
import matplotlib.pyplot as plt
import numpy as np
b = qutip.Bloch()
# vec = [0,1,0]
th = np.linspace(0, np.pi, 20)
xz = np.sin(th)
yz = np.zeros(20)
zz = np.cos(th)
@silgon
silgon / exploit_structure.jl
Last active July 6, 2023 22:44
exploit_structure.jsl
using SparseArrays
using LinearAlgebra
using BandedMatrices
using SpecialMatrices
using ToeplitzMatrices
using Random
using BlockArrays
using FFTW
BLAS.set_num_threads(1)
import numpy as np
import cvxpy as cp
α = 0.3
A = np.array([[1., α], [α, 1.5]])
# maximum eigenvalue
t = cp.Variable()
prob = cp.Problem(cp.Minimize(t), [np.eye(2)*t-A>>0])
prob.solve()
# minimum eigenvalue
t = cp.Variable()

Sanity check for convex optimization set

image

import plotly.express as px
df = px.data.tips()
color_map = dict(Sun="#881122", Sat="#991188", Fri="#221122", Thur="#887722")
fig = px.sunburst(df, path=['day', 'time', 'sex'], color="day", values='total_bill',
color_discrete_map=color_map)
fig.show()
## No Express (without order)
def build_hierarchical_dataframe(df, levels, value_column, color_column, color_map):
levels_rev = levels[::-1]
import numpy as np
import matplotlib.pyplot as plt
n_steps = 50
c, d= np.array([3,3]),np.array([1,2])
a = c-d
b = (np.linalg.norm(c)**2-np.linalg.norm(d)**2)/2
x = np.linspace(0, 4, n_steps)
y = np.linspace(0, 4, n_steps)
X, Y = np.meshgrid(x, y)