Example program for the fidelity computation according to the paper:

Klaus M. Frahm, Robert Fleckinger, Dima L. Shepelyansky, 
Eur. Phys. J. D {\bf 29}, 139 (2004)

-----------------------------------------------

FILES:
------
The package contains the following files:

LICENCE  => the licence (GPL for the source-code files and free, non-commercial
		for the binary file "raw2fig").
Makefile => the make file for the compilation
README   => this file
complex.cc => definition of complex-number class
complex.h  => header file for complex-number class
fidelity.cc => main test-program for the simulation of the quantum computing 
		of quantum tent map according to the above paper
quantum.cc => definition of qubit_state class with numerous member functions
		in particular many quantum gates and QFT without error, with 
		static or noise errors are implemented
quantum.h  => header file for qubit_state class 
random.cc  => a random number generator with two seed numbers of 32 bits
		avoiding correlation effects when using a large number of 
		random numbers (the period is much larger than 2^32 !!)
random.h   => header file for random number generator 
raw2fig => a dynamic Linux i386-elf-binary to create Husimi-function 
		graphics in fig-format from quantum-state files in 
		raw-format and p-representation, this binary should run on 
		any i386-compatible recent Linux system (with glibc-2.1 or 
		higher and libstdc++.so.5 from gcc-3.x.x)
raw2gif.sh => a script that transforms automatically all quantum-state files 
		in the current directory/folder 
		from raw-format and p-representation to gif files to represent 
		the Husimi-funtion. This script requires the binary raw2fig 
		and the transfig package in order to transform fig-files 
		to gif files (version transfig 3.2.x available from 
		http://www.xfig.org/ or as package in any recent standard 
		Linux distribution such as Mandrake/Mandriva, Fedora, 
		Redhat, Suse, Debian etc.).

COMPILING:
----------
To compile the program type simply:

make

which creates "fidelity.out". The make file uses by default the g++ compiler 
(from the gcc-package). It should well compile with all versions of gcc 
(2.95/2.96, 3.2.x, 3.3.x, 4.x,y). It should also compile with all other 
standard C++-Compilers, it has been tested with intel icc (7.0, 7.1, 8.0, 9.0)
and C++ from AIX64 (with the most agressive option -O5 !!). The program is 
quite selfcontained, it uses its own package for complex numbers and does 
not rely on libstc++ or similar for this such that incompatibilities between 
different Linux-/Unix versions are minimized. 
It furthermore uses standard C "printf", "sprintf" etc. for input/output 
(and not C++ input/output using the ostream or iostream classes etc.).



RUNNING:
--------
This program requires 7 command line parameters 
and should be invoked by:

./fidelity.out K n_q eps1 eps2 print_step steps1 steps2

where:

K is the classical K-value as decribed in the paper. 

n_q is qubit number (maximal value is 23)

eps1 and eps2 are the static error epsilon values from the paper with eps1 for 
the diagonal and eps2 off-diagonal error in the spin-type Hamiltonian
for the static error. (All results in the paper were obtained with eps1=eps2 = 
epsilon)

print_step = is an integer number indicating every which iteration the 
intermediate quantum-states should be saved, eventually to create later 
Husimifunction graphics using "raw2fig" and "raw2gif.sh". A value of zero 
indicates that no intermediate quantum-states are saved (as far as the 
creation of graphics is concerned).

steps1 is the number of forward iterations

steps2 is the number of backward iterations, if steps1=steps2 is chosen, one 
should recover the initial state which is a gaussian wave packet close to 
q=\pi and p=0 (actually p=1 in order to avoid to start exactly from the 
classical fix point). 


For example:

./fidelity.out 1.7 14 1e-5 1e-5 1 10 10

starts the simulation with K_cl=1.7, 14 qubits and epsilon=10^-5, with saving 
of intermediated states at each iteration and 10 forward and 10 backward 
iterations. Aftwards, one can create gif-figures of the Husimifunctions of the 
intermediate states by:

./raw2gif.sh

One can also create png, jpg, eps, pdf etc. by editing in this script the line:
FIGFORMAT="gif" 
to:
FIGFORMAT="jpg" 
etc. However, one should be aware that eps creates potentially large files 
and jpg undesired compression effects reducing the quality of the figures (in 
certain case with a very considerable quality reduction). The png format is 
equally useful as gif (i.e. good compromise between reasonable file-size and 
still exact, reversible compression).
The script uses as intermediate format the "fig-format" from transfig and 
xfig. However the intermediate fig-files are erased due to space requirements. 
Their file size is several times the size of the raw files which is just the 
complex array of coefficients of the quantum-state in p-representation in 
pure binary format (=> file size of *.raw files is 16*2^n_q bytes ).


Another example with a long simulation for the fidelity without saving of 
intermediate states is:

./fidelity.out 1.7 14 1e-5 1e-5 0 10000 0

The simulation will stop if the fidelity drops below 0.5 (this can be changed 
in the main funtion of fidelity.cc by changing the value of the variable 
"sat_val").


The program creates the following files:

-----------------------------------
1) if print_step > 0: 
quant_clean_*.raw => raw file of quantum states with perfect quantum computation
quant_stat*.raw => the same with static errors
quant_clean_back_*.raw/quant_stat_back_*.raw => for the backward computation
Here the * in the file name is of the form: 
_(qubit-number)_(K-value)_(iteration-number)_(epsilon-value)

After creation of gif-files as described above one obtains for each file of 
type quant*.raw a file quant*.gif.
-----------------------------------
2) 
stat_fid_*.dat: data file in ascii-form containing columns with:
iteration number, fidelity, ln(fidelity), n_q, eps1, eps2, K
Here * is of the form:
_(qubit-number)_(eps1)_(eps2)_(K-value)

all_stat_fid.dat: the same as stat_fid_*.dat but with all data in one file 
even if the programm is started with different parameters. This file is used 
to monitor overall progression if the main program is started in a loop in a 
script with different parameters.

-----------------------------------
3) Backup-files in order to recover from a previous calculation (when the 
job is killed due to power failure etc.). These files are created/updated 
every 60 seconds or every iteration (depending of which is longer). In case 
the job is killed, it is sufficient to restart the program with the identical 
parameters and then it will recover the calculation and lose at most 60 
seconds or one iteration. These backup-files are:

time_*.dat => the latest iteration at which at backup occurred, if this file 
exists (with the same *-parameter-values as in 2) the program trys to recover 
a previous calculation. Erasing this file will force the calculation to 
restart from beginning (which will also erase "stat_fid_*.dat" from above!).

vector_clean_*.raw => the perfect quantum state at the latest backup

vector_stat_*.raw => the quantum state with static errors at the latest backup
if the vector*-files are damages/erased without erasing time_*.dat, the 
program tries to recover the calculation but this will fail!

save_times.dat => all iteration numbers where a backup has occurred, used 
to monitor. 


The main code for the quantum compuation basics is in "quantum.h/cc" which 
defines a class "qubit_state" and many member functions. The structure and the
use of these functions is pretty obvious for someone with C++-experience. 
People interested in using this code should study the source and the comments 
describing the purposes of every function.
