mirror of
https://github.com/LCPQ/quantum_package
synced 2024-10-19 22:41:48 +02:00
Little refractoring (#88)
* Fix header * little refractoring * Follow good bash rules * Update ifort.cfg * One liners
This commit is contained in:
parent
b10f6227f3
commit
314e98a0d1
2
configure
vendored
2
configure
vendored
@ -3,7 +3,7 @@
|
|||||||
# Quantum Package configuration script
|
# 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
|
echo "QP_ROOT="$QP_ROOT
|
||||||
|
|
||||||
|
|
||||||
|
27
scripts/qp_bitmasks.py
Normal file → Executable file
27
scripts/qp_bitmasks.py
Normal file → Executable file
@ -1,4 +1,4 @@
|
|||||||
#! /usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
|
|
||||||
BIT_KIND_SIZE=64
|
BIT_KIND_SIZE=64
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ def int_to_string(s):
|
|||||||
"""
|
"""
|
||||||
assert type(s) in (int, long)
|
assert type(s) in (int, long)
|
||||||
assert s>=0
|
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):
|
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)
|
assert type(s) in (int, long)
|
||||||
if s>=0:
|
if s < 0:
|
||||||
s = int_to_string(s)
|
s = s + (1 << bit_kind_size)
|
||||||
result = string_to_bitmask( s, bit_kind_size )
|
return ['{s:0{width}b}'.format(s=s,width=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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BitMask(object):
|
class BitMask(object):
|
||||||
@ -102,9 +96,9 @@ class BitMask(object):
|
|||||||
self.bit_kind_size = bit_kind_size
|
self.bit_kind_size = bit_kind_size
|
||||||
self._data_int = l
|
self._data_int = l
|
||||||
|
|
||||||
def get_N_int(self):
|
@property
|
||||||
|
def N_int(self):
|
||||||
return len(self._data_int)
|
return len(self._data_int)
|
||||||
N_int = property(fget=get_N_int)
|
|
||||||
|
|
||||||
def __getitem__(self,i):
|
def __getitem__(self,i):
|
||||||
return self._data_int[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)
|
result += int_to_bitmask(i,bit_kind_size=self.bit_kind_size)
|
||||||
return str(result)
|
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__':
|
if __name__ == '__main__':
|
||||||
import doctest
|
import doctest
|
||||||
|
Loading…
Reference in New Issue
Block a user