Sanity check for convex optimization set
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
h = 1 | |
p = np.pi*1/3 | |
m = np.arange(1,101) | |
A_m = 2*h*np.sin(m*p)/(m**2*p*(np.pi-p)) | |
x = np.linspace(0,np.pi,150) | |
# f = A_m* np.sin(m[np.newaxis,:]*x[:,np.newaxis]) | |
f = A_m * np.sin(np.outer(x,m)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from langchain_openai import ChatOpenAI | |
from langchain_core.output_parsers import JsonOutputParser | |
from langchain_core.output_parsers import PydanticOutputParser | |
from langchain_core.prompts import PromptTemplate | |
from pydantic import BaseModel, ValidationError | |
from typing import List, Optional | |
# Initialize the language model. Replace 'openai' with your specified model. | |
llm = ChatOpenAI(model="gpt-4o-mini",temperature=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using SparseArrays | |
using LinearAlgebra | |
using BandedMatrices | |
using SpecialMatrices | |
using ToeplitzMatrices | |
using Random | |
using BlockArrays | |
using FFTW | |
BLAS.set_num_threads(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
NewerOlder