2021年5月28日金曜日

Octave 6.2.0 + MKL (intel-oneapi-mkl 2021)

The following is the configure option to include MKL in Octave.
MKL is installed via Spack, and the version is intel-oneapi-mkl@2021.2.0

CPPFLAGS=" -I${MKLROOT}/include -I${MKLROOT}/include/fftw" \
LDFLAGS=" -L${MKLROOT}/lib/intel64" \
CFLAGS="-O3 -fPIC -DM_PI=3.1415926535897932384  -I${MKLROOT}/include -I${MKLROOT}/include/fftw" \
F77="gfortran" \
../octave-6.2.0/configure --prefix=/path/to/install \
--with-blas="-lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread" \
--with-lapack="-lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread" \
--with-fftw3="-lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm" \
--with-fftw3f="-lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm" \
--disable-java --enable-static

It seems that using intel compiler with mkl is problematic.

2021年5月17日月曜日

GeoTracker and Googe Earth Virtual Tour

 I am creating this kind of movie, and finally, I have succeeded to find the set of tools useful on Linux.


(1) GeoTracker on Android
This allows me to get the positions at each time point located with GPS.
https://play.google.com/store/apps/details?id=com.ilyabogdanovich.geotracker&hl=ja&gl=US

(2) RouteConverterLinux
This allows me to edit the points measured above without losing the timing information.
I tried with Google Maps, but it automatically deletes the timing information.

On Ubuntu 20.04, I needed to install OpenJDK 14, and the command is;
/usr/lib/jvm/java-14-openjdk-amd64/bin/java -jar RouteConverterLinux.jar 

https://www.routeconverter.de/downloads/de

(3) Google Earth
You should be able to google "Virtual Tour", and scrutinize ;)


The movie I am creating:


2021年5月8日土曜日

Poco F3

 I have not written this, but I succeeded to get Xiaomi's Poco F3 on the launch date in Europe via Amazon (8G RAM/ 256 storage ver).

So far so good, and love 48M pixel camera!


PS:
I did not know, but recent android can transfer the environment very easily. The thing I love most is that Google authenticator entries can be transferred using QR code with just one step.

Pixel Experience (Android 11) for Xiaomi A1

 I have recently bought the Poco F3, and my old Xiaomi A1 can be bricked!
So, I became to want to test some custom ROMs.

Finally, I realized the pixel experience only offers Android 11 as an official one, and installed it.

I just followed the instruction and it worked!

I may not use this intensively, but it seems the ROM is quite stable.

So far, the only defect I have found is that there is no way to use the tele-lens.



2021年5月1日土曜日

Inverse QFT

Based on the last QFT , I tried the inverse QFT.

I got the result of  [640, 654, 573, 666, 615, 601, 635, 654, 616, 603, 646, 602, 629, 605, 593, 668].
This means that the initial state of QFFT is recovered by iQFFT.

The codes of QFT and iQFT are as follows (as far as I understand).



namespace QFT_naive {
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Arrays;
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Math;
@EntryPoint()
operation SayHello() : Unit {
let nQubit = 4;
let maxNum = PowI(2,nQubit);
mutable counts = new Int[maxNum];
mutable theta = new Double[maxNum];
mutable revSeq = new Int[nQubit];

for iQubit in 0..(nQubit-1){
set theta w/= iQubit <- calcTheta(IntAsDouble(iQubit+1));
}

for iQubit in 0..(nQubit-1){
set revSeq w/= iQubit <- nQubit-1-iQubit;
}
for trial in 1..10000 {
use input = Qubit[nQubit] {
// 1/sqrt(8) (|000> + |001> + ,,, + |111>)
for iQubit in 0..(nQubit-1){
H(input[iQubit]);
}

// Star QFT
for iQubit in 0..(nQubit-1){
H(input[iQubit]);
for jQubit in 1..(nQubit-1-iQubit){
(Controlled R1)([input[jQubit+iQubit]],(theta[jQubit],input[iQubit]));
}

}

let numLoopSwap = Floor(IntAsDouble(nQubit)*0.5);
for iQubit in 0..(numLoopSwap-1) {
SWAP(input[iQubit],input[nQubit-1-iQubit]);
}
// Start Inverse QFFT
for iQubit in 0..(numLoopSwap-1) {
SWAP(input[iQubit],input[nQubit-1-iQubit]);
}
for iQubit in revSeq{
for jQubit in 0..(nQubit-1)-iQubit-1{
let kQubit = revSeq[(nQubit-1)-jQubit];
let controlQubit = nQubit-kQubit-1;
let rotationIndex= nQubit-(kQubit+iQubit)-1;
(Controlled R1)([input[controlQubit]],(-1.0*theta[rotationIndex],input[iQubit]));
}
H(input[iQubit]);
}
let res = MultiM(input);
let bit = ResultArrayAsInt(res);
set counts w/= bit <- counts[bit]+ 1;
ResetAll(input);
}
}
for j in 0..(maxNum-1) {
Message(IntAsString(counts[j]));
}
}
function calcTheta(l : Double) : Double {
return 2.0*PI()/(PowD(2.0,l));
}
}


Normal distribution of dice rolls: Python animation

 Since my wife started learning statistics, and I wanted to give her some intuitive understanding of the normal distribution, standard deviation, 95% confidence region etc, I made a small python code which generates an animation of the histogram of dice rolls.

This could help others time ;)

(Distribute under MIT license)



import random
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import norm

def main():

numTrial = 1000000
numDice = 20
sumResults = []

bin=np.arange(numDice-0.5, numDice*6+1.5, 1)
print(bin)

fig = plt.figure()
iFig = 1
for iTrial in range(numTrial):
sumDice = 0
for iDice in range(numDice):
sumDice += random.randint(1,6)
sumResults.append(sumDice)

if iTrial % 100 == 0:
ax = fig.add_subplot()
ax.set_title(str(numDice)+" dices case")
ax.set_xlabel("Sum of rolls")
ax.set_ylabel("Frequency")
n, bins, patches = plt.hist(sumResults,bins=bin)

loc,scale = norm.fit(sumResults)
plt.plot(bin,sum(n)*norm.pdf(bin,loc,scale),color="y")
txt = "STD:"+str(round(scale,4))
plt.text(5.0,0.01,txt,size=30)

p25 =norm.ppf(0.025 ,loc,scale)
p975=norm.ppf(0.975,loc,scale)
plt.axvline(x=p25, ymin=0.1, ymax=0.9,color="r")
plt.axvline(x=p975, ymin=0.1, ymax=0.9,color="r")
plt.savefig(str('{:05d}'.format(iFig))+".png")
iFig += 1
plt.pause(.001)
fig.clear()

if __name__ == "__main__":
main()