mirror of
https://github.com/libquantum/libquantum.git
synced 2025-10-03 16:51:37 +00:00
updated libquantum 1.0.0 source files
This commit is contained in:
4
CHANGES
4
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:
|
libquantum 0.9.1:
|
||||||
- Added fourth-order Runge-Kutta time evolution
|
- Added fourth-order Runge-Kutta time evolution
|
||||||
- Fixed error in quantum_measure() that caused some register values
|
- Fixed error in quantum_measure() that caused some register values
|
||||||
|
@@ -49,7 +49,7 @@ LIBTOOL=@LIBTOOL@
|
|||||||
# Flags passed to C compiler
|
# Flags passed to C compiler
|
||||||
|
|
||||||
CFLAGS=@CFLAGS@
|
CFLAGS=@CFLAGS@
|
||||||
LDFLAGS=-rpath $(LIBDIR) -version-info 6:0:3
|
LDFLAGS=-rpath $(LIBDIR) -version-info 6:1:3
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
||||||
|
18
configure
vendored
18
configure
vendored
@@ -1,6 +1,6 @@
|
|||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# Guess values for system-dependent variables and create Makefiles.
|
# 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>.
|
# Report bugs to <libquantum@libquantum.de>.
|
||||||
#
|
#
|
||||||
@@ -724,8 +724,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
|
|||||||
# Identity of this package.
|
# Identity of this package.
|
||||||
PACKAGE_NAME='libquantum'
|
PACKAGE_NAME='libquantum'
|
||||||
PACKAGE_TARNAME='libquantum'
|
PACKAGE_TARNAME='libquantum'
|
||||||
PACKAGE_VERSION='0.9.1'
|
PACKAGE_VERSION='1.0.0'
|
||||||
PACKAGE_STRING='libquantum 0.9.1'
|
PACKAGE_STRING='libquantum 1.0.0'
|
||||||
PACKAGE_BUGREPORT='libquantum@libquantum.de'
|
PACKAGE_BUGREPORT='libquantum@libquantum.de'
|
||||||
|
|
||||||
ac_unique_file="classic.c"
|
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.
|
# 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.
|
# This message is too long to be a string in the A/UX 3.1 sh.
|
||||||
cat <<_ACEOF
|
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]...
|
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||||
|
|
||||||
@@ -1411,7 +1411,7 @@ fi
|
|||||||
|
|
||||||
if test -n "$ac_init_help"; then
|
if test -n "$ac_init_help"; then
|
||||||
case $ac_init_help in
|
case $ac_init_help in
|
||||||
short | recursive ) echo "Configuration of libquantum 0.9.1:";;
|
short | recursive ) echo "Configuration of libquantum 1.0.0:";;
|
||||||
esac
|
esac
|
||||||
cat <<\_ACEOF
|
cat <<\_ACEOF
|
||||||
|
|
||||||
@@ -1510,7 +1510,7 @@ fi
|
|||||||
test -n "$ac_init_help" && exit $ac_status
|
test -n "$ac_init_help" && exit $ac_status
|
||||||
if $ac_init_version; then
|
if $ac_init_version; then
|
||||||
cat <<\_ACEOF
|
cat <<\_ACEOF
|
||||||
libquantum configure 0.9.1
|
libquantum configure 1.0.0
|
||||||
generated by GNU Autoconf 2.61
|
generated by GNU Autoconf 2.61
|
||||||
|
|
||||||
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
|
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
|
This file contains any messages produced by compilers while
|
||||||
running configure, to aid debugging if configure makes a mistake.
|
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
|
generated by GNU Autoconf 2.61. Invocation command line was
|
||||||
|
|
||||||
$ $0 $@
|
$ $0 $@
|
||||||
@@ -10109,7 +10109,7 @@ exec 6>&1
|
|||||||
# report actual input values of CONFIG_FILES etc. instead of their
|
# report actual input values of CONFIG_FILES etc. instead of their
|
||||||
# values after options handling.
|
# values after options handling.
|
||||||
ac_log="
|
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
|
generated by GNU Autoconf 2.61. Invocation command line was
|
||||||
|
|
||||||
CONFIG_FILES = $CONFIG_FILES
|
CONFIG_FILES = $CONFIG_FILES
|
||||||
@@ -10158,7 +10158,7 @@ Report bugs to <bug-autoconf@gnu.org>."
|
|||||||
_ACEOF
|
_ACEOF
|
||||||
cat >>$CONFIG_STATUS <<_ACEOF
|
cat >>$CONFIG_STATUS <<_ACEOF
|
||||||
ac_cs_version="\\
|
ac_cs_version="\\
|
||||||
libquantum config.status 0.9.1
|
libquantum config.status 1.0.0
|
||||||
configured by $0, generated by GNU Autoconf 2.61,
|
configured by $0, generated by GNU Autoconf 2.61,
|
||||||
with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
|
with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
|
||||||
|
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
# MA 02110-1301, USA
|
# 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_SRCDIR([classic.c])
|
||||||
AC_CONFIG_HEADER([config.h])
|
AC_CONFIG_HEADER([config.h])
|
||||||
|
|
||||||
|
52
gates.c
52
gates.c
@@ -289,7 +289,7 @@ void
|
|||||||
quantum_gate1(int target, quantum_matrix m, quantum_reg *reg)
|
quantum_gate1(int target, quantum_matrix m, quantum_reg *reg)
|
||||||
{
|
{
|
||||||
int i, j, k, iset;
|
int i, j, k, iset;
|
||||||
int addsize=0, decsize=0, sorted=1;
|
int addsize=0, decsize=0;
|
||||||
COMPLEX_FLOAT t, tnot=0;
|
COMPLEX_FLOAT t, tnot=0;
|
||||||
float limit;
|
float limit;
|
||||||
char *done;
|
char *done;
|
||||||
@@ -297,38 +297,36 @@ quantum_gate1(int target, quantum_matrix m, quantum_reg *reg)
|
|||||||
if((m.cols != 2) || (m.rows != 2))
|
if((m.cols != 2) || (m.rows != 2))
|
||||||
quantum_error(QUANTUM_EMSIZE);
|
quantum_error(QUANTUM_EMSIZE);
|
||||||
|
|
||||||
quantum_reconstruct_hash(reg);
|
if(reg->hashw)
|
||||||
|
|
||||||
/* calculate the number of basis states to be added */
|
|
||||||
|
|
||||||
for(i=0; i<reg->size; i++)
|
|
||||||
{
|
{
|
||||||
/* determine whether quantum register is sorted */
|
quantum_reconstruct_hash(reg);
|
||||||
|
|
||||||
if(sorted && (reg->node[i].state != i))
|
/* calculate the number of basis states to be added */
|
||||||
sorted = 0;
|
|
||||||
|
|
||||||
/* 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),
|
if(quantum_get_state(reg->node[i].state
|
||||||
*reg) == -1)
|
^ ((MAX_UNSIGNED) 1 << target), *reg) == -1)
|
||||||
addsize++;
|
addsize++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate memory for the new basis states */
|
/* allocate memory for the new basis states */
|
||||||
|
|
||||||
reg->node = realloc(reg->node,
|
reg->node = realloc(reg->node,
|
||||||
(reg->size + addsize) * sizeof(quantum_reg_node));
|
(reg->size + addsize) * sizeof(quantum_reg_node));
|
||||||
|
|
||||||
|
if(!reg->node)
|
||||||
|
quantum_error(QUANTUM_ENOMEM);
|
||||||
|
|
||||||
if(!reg->node)
|
quantum_memman(addsize*sizeof(quantum_reg_node));
|
||||||
quantum_error(QUANTUM_ENOMEM);
|
|
||||||
|
|
||||||
quantum_memman(addsize*sizeof(quantum_reg_node));
|
for(i=0; i<addsize; i++)
|
||||||
|
{
|
||||||
for(i=0; i<addsize; i++)
|
reg->node[i+reg->size].state = 0;
|
||||||
{
|
reg->node[i+reg->size].amplitude = 0;
|
||||||
reg->node[i+reg->size].state = 0;
|
}
|
||||||
reg->node[i+reg->size].amplitude = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
done = calloc(reg->size + addsize, sizeof(char));
|
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 */
|
/* remove basis states with extremely small amplitude */
|
||||||
|
|
||||||
if(!sorted)
|
if(reg->hashw)
|
||||||
{
|
{
|
||||||
for(i=0, j=0; i<reg->size; i++)
|
for(i=0, j=0; i<reg->size; i++)
|
||||||
{
|
{
|
||||||
|
39
qtime.c
39
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
|
/* 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
|
double
|
||||||
quantum_rk4a(quantum_reg *reg, double t, double *dt, double epsilon,
|
quantum_rk4a(quantum_reg *reg, double t, double *dt, double epsilon,
|
||||||
quantum_reg H(MAX_UNSIGNED, double))
|
quantum_reg H(MAX_UNSIGNED, double))
|
||||||
{
|
{
|
||||||
quantum_reg reg2, old, tmp;
|
quantum_reg reg2, old;
|
||||||
double delta, r, dtused;
|
double delta, r, dtused;
|
||||||
int i;
|
int i;
|
||||||
void *hash;
|
void *hash;
|
||||||
@@ -129,34 +130,42 @@ quantum_rk4a(quantum_reg *reg, double t, double *dt, double epsilon,
|
|||||||
|
|
||||||
for(i=0;i<reg->size;i++)
|
for(i=0;i<reg->size;i++)
|
||||||
{
|
{
|
||||||
if(quantum_real(reg->node[i].amplitude - reg2.node[i].amplitude)
|
r = 2*sqrt(quantum_prob(reg->node[i].amplitude
|
||||||
> quantum_imag(reg->node[i].amplitude - reg2.node[i].amplitude))
|
- reg2.node[i].amplitude)/
|
||||||
r = 2*quantum_real(reg->node[i].amplitude - reg2.node[i].amplitude)
|
quantum_prob(reg->node[i].amplitude
|
||||||
/ quantum_real(reg->node[i].amplitude + reg2.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);
|
|
||||||
|
|
||||||
if(r > delta)
|
if(r > delta)
|
||||||
delta = r;
|
delta = r;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dtused = *dt;
|
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)
|
if(delta > epsilon)
|
||||||
{
|
{
|
||||||
tmp = *reg;
|
memcpy(reg->node, old.node, reg->size*sizeof(quantum_reg_node));
|
||||||
*reg = old;
|
memcpy(reg2.node, old.node, reg->size*sizeof(quantum_reg_node));
|
||||||
old = tmp;
|
|
||||||
memcpy(reg2.node, reg->node, reg->size*sizeof(quantum_reg_node));
|
|
||||||
memcpy(old.node, reg->node, reg->size*sizeof(quantum_reg_node));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} while(delta > epsilon);
|
} while(delta > epsilon);
|
||||||
|
|
||||||
reg->hash = hash;
|
reg->hash = hash;
|
||||||
reg->hashw = hashw;
|
reg->hashw = hashw;
|
||||||
|
|
||||||
|
quantum_delete_qureg(&old);
|
||||||
|
quantum_delete_qureg(®2);
|
||||||
|
|
||||||
return dtused;
|
return dtused;
|
||||||
}
|
}
|
||||||
|
2
qureg.c
2
qureg.c
@@ -333,7 +333,7 @@ quantum_kronecker(quantum_reg *reg1, quantum_reg *reg2)
|
|||||||
|
|
||||||
reg.width = reg1->width+reg2->width;
|
reg.width = reg1->width+reg2->width;
|
||||||
reg.size = reg1->size*reg2->size;
|
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 */
|
/* allocate memory for the new basis states */
|
||||||
|
5
qureg.h
5
qureg.h
@@ -158,6 +158,11 @@ static inline void
|
|||||||
quantum_reconstruct_hash(quantum_reg *reg)
|
quantum_reconstruct_hash(quantum_reg *reg)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
/* Check whether register is sorted */
|
||||||
|
|
||||||
|
if(!reg->hashw)
|
||||||
|
return;
|
||||||
|
|
||||||
for(i=0; i<(1 << reg->hashw); i++)
|
for(i=0; i<(1 << reg->hashw); i++)
|
||||||
reg->hash[i] = 0;
|
reg->hash[i] = 0;
|
||||||
|
Reference in New Issue
Block a user