diff --git a/configure b/configure index 62f58c48..9aec9834 100755 --- a/configure +++ b/configure @@ -3,7 +3,7 @@ # Quantum Package configuration script # -export QP_ROOT="$( cd "$(dirname "$0")" ; pwd -P )" +export QP_ROOT="$( cd "$(dirname "$0")" ; pwd --physical )" echo "QP_ROOT="$QP_ROOT diff --git a/scripts/qp_bitmasks.py b/scripts/qp_bitmasks.py old mode 100644 new mode 100755 index ff97edd3..223c32ba --- a/scripts/qp_bitmasks.py +++ b/scripts/qp_bitmasks.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python2 +#!/usr/bin/env python2 BIT_KIND_SIZE=64 @@ -24,7 +24,7 @@ def int_to_string(s): """ assert type(s) in (int, long) assert s>=0 - return str(s) if s in (0,1) else int_to_string(s>>1) + str(s&1) + return '{s:0b}'.format(s=s) def string_to_bitmask(s,bit_kind_size=BIT_KIND_SIZE): @@ -63,15 +63,9 @@ def int_to_bitmask(s,bit_kind_size=BIT_KIND_SIZE): >>> """ assert type(s) in (int, long) - if s>=0: - s = int_to_string(s) - result = string_to_bitmask( s, bit_kind_size ) - else: - s = int_to_string(-s-1) - result = string_to_bitmask( s, bit_kind_size ) - result = [ x.replace('1','.').replace('0','1').replace('.','0') for x in result ] - return result - + if s < 0: + s = s + (1 << bit_kind_size) + return ['{s:0{width}b}'.format(s=s,width=bit_kind_size)] class BitMask(object): @@ -102,9 +96,9 @@ class BitMask(object): self.bit_kind_size = bit_kind_size self._data_int = l - def get_N_int(self): + @property + def N_int(self): return len(self._data_int) - N_int = property(fget=get_N_int) def __getitem__(self,i): return self._data_int[i] @@ -126,7 +120,12 @@ class BitMask(object): result += int_to_bitmask(i,bit_kind_size=self.bit_kind_size) return str(result) - +def excitation_degree(l_a,l_b): + ''' + excitation_degree([895],[959]) + >> 1 + ''' + return sum(bin(a ^ b).count("1") for a,b in zip(l_a,l_b) ) // 2 if __name__ == '__main__': import doctest