From a88843b324a3dabc485fb9a68ac37de930f355ae Mon Sep 17 00:00:00 2001 From: libquantum Date: Thu, 27 Oct 2016 04:26:15 +0900 Subject: [PATCH] updated libquantum 1.0.0 source files --- CHANGES | 4 ++++ Makefile.in | 2 +- configure | 18 +++++++++--------- configure.in | 2 +- gates.c | 52 +++++++++++++++++++++++++--------------------------- qtime.c | 39 ++++++++++++++++++++++++--------------- qureg.c | 2 +- qureg.h | 5 +++++ 8 files changed, 70 insertions(+), 54 deletions(-) diff --git a/CHANGES b/CHANGES index 79ad2e2..edbb7e7 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +libquantum 1.0.0: + - Fixed quantum_gate1 to work properly with sorted regs + - Fixed several bugs in quantum_rk4a + libquantum 0.9.1: - Added fourth-order Runge-Kutta time evolution - Fixed error in quantum_measure() that caused some register values diff --git a/Makefile.in b/Makefile.in index 6492f05..1004f7e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -49,7 +49,7 @@ LIBTOOL=@LIBTOOL@ # Flags passed to C compiler CFLAGS=@CFLAGS@ -LDFLAGS=-rpath $(LIBDIR) -version-info 6:0:3 +LDFLAGS=-rpath $(LIBDIR) -version-info 6:1:3 # Dependencies diff --git a/configure b/configure index 056b6c7..adfa4d4 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.61 for libquantum 0.9.1. +# Generated by GNU Autoconf 2.61 for libquantum 1.0.0. # # Report bugs to . # @@ -724,8 +724,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='libquantum' PACKAGE_TARNAME='libquantum' -PACKAGE_VERSION='0.9.1' -PACKAGE_STRING='libquantum 0.9.1' +PACKAGE_VERSION='1.0.0' +PACKAGE_STRING='libquantum 1.0.0' PACKAGE_BUGREPORT='libquantum@libquantum.de' ac_unique_file="classic.c" @@ -1346,7 +1346,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures libquantum 0.9.1 to adapt to many kinds of systems. +\`configure' configures libquantum 1.0.0 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1411,7 +1411,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of libquantum 0.9.1:";; + short | recursive ) echo "Configuration of libquantum 1.0.0:";; esac cat <<\_ACEOF @@ -1510,7 +1510,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -libquantum configure 0.9.1 +libquantum configure 1.0.0 generated by GNU Autoconf 2.61 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, @@ -1524,7 +1524,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by libquantum $as_me 0.9.1, which was +It was created by libquantum $as_me 1.0.0, which was generated by GNU Autoconf 2.61. Invocation command line was $ $0 $@ @@ -10109,7 +10109,7 @@ exec 6>&1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by libquantum $as_me 0.9.1, which was +This file was extended by libquantum $as_me 1.0.0, which was generated by GNU Autoconf 2.61. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -10158,7 +10158,7 @@ Report bugs to ." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -libquantum config.status 0.9.1 +libquantum config.status 1.0.0 configured by $0, generated by GNU Autoconf 2.61, with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" diff --git a/configure.in b/configure.in index 7f7e338..3750490 100644 --- a/configure.in +++ b/configure.in @@ -20,7 +20,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA -AC_INIT([libquantum], [0.9.1], [libquantum@libquantum.de]) +AC_INIT([libquantum], [1.0.0], [libquantum@libquantum.de]) AC_CONFIG_SRCDIR([classic.c]) AC_CONFIG_HEADER([config.h]) diff --git a/gates.c b/gates.c index 69ce793..3732a92 100644 --- a/gates.c +++ b/gates.c @@ -289,7 +289,7 @@ void quantum_gate1(int target, quantum_matrix m, quantum_reg *reg) { int i, j, k, iset; - int addsize=0, decsize=0, sorted=1; + int addsize=0, decsize=0; COMPLEX_FLOAT t, tnot=0; float limit; char *done; @@ -297,38 +297,36 @@ quantum_gate1(int target, quantum_matrix m, quantum_reg *reg) if((m.cols != 2) || (m.rows != 2)) quantum_error(QUANTUM_EMSIZE); - quantum_reconstruct_hash(reg); - - /* calculate the number of basis states to be added */ - - for(i=0; isize; i++) + if(reg->hashw) { - /* determine whether quantum register is sorted */ + quantum_reconstruct_hash(reg); - if(sorted && (reg->node[i].state != i)) - sorted = 0; + /* calculate the number of basis states to be added */ - /* determine whether XORed basis state already exists */ + for(i=0; isize; i++) + { + /* determine whether XORed basis state already exists */ - if(quantum_get_state(reg->node[i].state ^ ((MAX_UNSIGNED) 1 << target), - *reg) == -1) - addsize++; - } - - /* allocate memory for the new basis states */ + if(quantum_get_state(reg->node[i].state + ^ ((MAX_UNSIGNED) 1 << target), *reg) == -1) + addsize++; + } + + /* allocate memory for the new basis states */ - reg->node = realloc(reg->node, - (reg->size + addsize) * sizeof(quantum_reg_node)); + reg->node = realloc(reg->node, + (reg->size + addsize) * sizeof(quantum_reg_node)); + + if(!reg->node) + quantum_error(QUANTUM_ENOMEM); - if(!reg->node) - quantum_error(QUANTUM_ENOMEM); + quantum_memman(addsize*sizeof(quantum_reg_node)); - quantum_memman(addsize*sizeof(quantum_reg_node)); - - for(i=0; inode[i+reg->size].state = 0; - reg->node[i+reg->size].amplitude = 0; + for(i=0; inode[i+reg->size].state = 0; + reg->node[i+reg->size].amplitude = 0; + } } done = calloc(reg->size + addsize, sizeof(char)); @@ -409,7 +407,7 @@ quantum_gate1(int target, quantum_matrix m, quantum_reg *reg) /* remove basis states with extremely small amplitude */ - if(!sorted) + if(reg->hashw) { for(i=0, j=0; isize; i++) { diff --git a/qtime.c b/qtime.c index 0b97608..32e513e 100644 --- a/qtime.c +++ b/qtime.c @@ -98,13 +98,14 @@ quantum_rk4(quantum_reg *reg, double t, double dt, } /* Adaptive Runge-Kutta. Stores the new stepsize in dt and returns the - stepsize actually used. */ + stepsize actually used. For further details, see Press et al., + Numerical Recipes in C (Second Edition, CUP, 1992), Sec. 16.3 */ double quantum_rk4a(quantum_reg *reg, double t, double *dt, double epsilon, quantum_reg H(MAX_UNSIGNED, double)) { - quantum_reg reg2, old, tmp; + quantum_reg reg2, old; double delta, r, dtused; int i; void *hash; @@ -129,34 +130,42 @@ quantum_rk4a(quantum_reg *reg, double t, double *dt, double epsilon, for(i=0;isize;i++) { - if(quantum_real(reg->node[i].amplitude - reg2.node[i].amplitude) - > quantum_imag(reg->node[i].amplitude - reg2.node[i].amplitude)) - r = 2*quantum_real(reg->node[i].amplitude - reg2.node[i].amplitude) - / quantum_real(reg->node[i].amplitude + reg2.node[i].amplitude); - else - r = 2*quantum_imag(reg->node[i].amplitude - reg2.node[i].amplitude) - / quantum_imag(reg->node[i].amplitude + reg2.node[i].amplitude); + r = 2*sqrt(quantum_prob(reg->node[i].amplitude + - reg2.node[i].amplitude)/ + quantum_prob(reg->node[i].amplitude + + reg2.node[i].amplitude)); if(r > delta) delta = r; + } dtused = *dt; - *dt *= pow(epsilon/delta, 0.2); + + if(delta < epsilon) + *dt *= 0.9*pow(epsilon/delta, 0.2); + else + *dt *= 0.9*pow(epsilon/delta, 0.25); + + if(*dt > 4*dtused) + *dt = 4*dtused; + + else if(*dt < 0.25*dtused) + *dt = 0.25*dtused; if(delta > epsilon) { - tmp = *reg; - *reg = old; - old = tmp; - memcpy(reg2.node, reg->node, reg->size*sizeof(quantum_reg_node)); - memcpy(old.node, reg->node, reg->size*sizeof(quantum_reg_node)); + memcpy(reg->node, old.node, reg->size*sizeof(quantum_reg_node)); + memcpy(reg2.node, old.node, reg->size*sizeof(quantum_reg_node)); } } while(delta > epsilon); reg->hash = hash; reg->hashw = hashw; + + quantum_delete_qureg(&old); + quantum_delete_qureg(®2); return dtused; } diff --git a/qureg.c b/qureg.c index 14a33f2..b0a3fe8 100644 --- a/qureg.c +++ b/qureg.c @@ -333,7 +333,7 @@ quantum_kronecker(quantum_reg *reg1, quantum_reg *reg2) reg.width = reg1->width+reg2->width; reg.size = reg1->size*reg2->size; - reg.hashw = reg1->size*reg2->size + 2; + reg.hashw = reg.width+2; /* allocate memory for the new basis states */ diff --git a/qureg.h b/qureg.h index 20ff32f..2ee5871 100644 --- a/qureg.h +++ b/qureg.h @@ -158,6 +158,11 @@ static inline void quantum_reconstruct_hash(quantum_reg *reg) { int i; + + /* Check whether register is sorted */ + + if(!reg->hashw) + return; for(i=0; i<(1 << reg->hashw); i++) reg->hash[i] = 0;