updated libquantum 1.0.0 source files

This commit is contained in:
libquantum
2016-10-27 04:26:15 +09:00
parent 7091733a35
commit a88843b324
8 changed files with 70 additions and 54 deletions

View File

@@ -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

View File

@@ -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

18
configure vendored
View File

@@ -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 <libquantum@libquantum.de>.
#
@@ -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 <bug-autoconf@gnu.org>."
_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'`\\"

View File

@@ -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])

52
gates.c
View File

@@ -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; i<reg->size; 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; i<reg->size; 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; i<addsize; i++)
{
reg->node[i+reg->size].state = 0;
reg->node[i+reg->size].amplitude = 0;
for(i=0; i<addsize; i++)
{
reg->node[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; i<reg->size; i++)
{

39
qtime.c
View File

@@ -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;i<reg->size;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(&reg2);
return dtused;
}

View File

@@ -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 */

View File

@@ -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;