Skip to content

Instantly share code, notes, and snippets.

View refraction-ray's full-sized avatar

Shixin Zhang refraction-ray

View GitHub Profile
@refraction-ray
refraction-ray / 0_tfq.py
Last active May 5, 2022 08:57
tensorflow quantum vs tensorcircuit
import tensorflow as tf
import tensorflow_quantum as tfq
import cirq
import sympy
import numpy as np
nwires, nlayers = 6, 3
qubits = [cirq.GridQubit(0, i) for i in range(nwires)]
symbols = sympy.symbols("params_0:" + str(nlayers * nwires * 2))
@refraction-ray
refraction-ray / demo.py
Created July 11, 2020 07:11
tensorflow gradienttape with ragged tensor
import tensorflow as tf
## note tape.watch() cannot accept ragged tensor as input
rt = tf.ragged.constant([[1.], [2., 3.]])
# rt = rt.to_tensor()
with tf.GradientTape() as t:
t.watch(rt.values)
loss = 2*rt[0,0]+rt[1,1]**3
g_flatten = t.gradient(loss, rt.values)
g = rt.with_values(g_flatten)
print(g)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@refraction-ray
refraction-ray / einsum_symbol.ipynb
Created May 30, 2020 01:44
einsum_symbol.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@refraction-ray
refraction-ray / ia.py
Created April 13, 2020 02:32
基于 xalpha 的逐年指数涨幅拆解与分析
import xalpha as xa
import pandas as pd
import datetime as dt
def _percent(r):
return round((r-1)*100, 2)
def index_analysis(code, start, end):
dfe = xa.get_daily("peb-"+code, end=end, prev=20).iloc[-1]
end = dfe["date"].strftime("%Y%m%d")
@refraction-ray
refraction-ray / mcad.py
Created September 12, 2019 11:26
Solution for ad of mcmc
@tf.custom_gradient
def idn(x):
def grad(*dx):
return tf.zeros_like(dx[0])
return x, grad
def probexp(beta, s):
return tf.exp(-beta*s)
def obss(beta, s):
@refraction-ray
refraction-ray / svd_gradient.ipynb
Created September 2, 2019 09:03
Complex SVD backprop demo
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@refraction-ray
refraction-ray / upmonitor.sh
Created August 7, 2019 10:05
A super light-weighted monitoring and alerting tool, if you don't want to configure any of there monitoring tools
#! /bin/bash
ips=("8.8.8.8"
"baidu.com")
webs=("http://10.0.0.1:8080")
address="user@mails.domain"
for ip in "${ips[@]}"; do
@refraction-ray
refraction-ray / customfeedstock.md
Last active July 30, 2019 09:06 — forked from piyushrpt/customfeedstock.md
Setting up custom conda feedstock
@refraction-ray
refraction-ray / eigh-issue.ipynb
Last active July 10, 2019 08:31
Possible issue on numpy eigh
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.