mirror of
https://github.com/LCPQ/quantum_package
synced 2025-01-10 13:08:23 +01:00
Merge branch 'master' of github.com:LCPQ/quantum_package
This commit is contained in:
commit
b8821ce04c
@ -36,6 +36,13 @@ function fail()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if [[ -z $QPACKAGE_ROOT ]]
|
||||||
|
then
|
||||||
|
echo "Error:"
|
||||||
|
echo "QPACKAGE_ROOT environment variable is not set."
|
||||||
|
echo "source quantum_package.rc"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
MODULE=$1
|
MODULE=$1
|
||||||
|
|
||||||
|
68
scripts/follow_output.py
Executable file
68
scripts/follow_output.py
Executable file
@ -0,0 +1,68 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
"""Follow the output files in standard output"""
|
||||||
|
|
||||||
|
class OutputFollower(object):
|
||||||
|
|
||||||
|
def __init__(self,filename):
|
||||||
|
self.filename = filename
|
||||||
|
self.dir = filename+'/output/'
|
||||||
|
self.last_time = {}
|
||||||
|
self.last_line = {}
|
||||||
|
self.data = {}
|
||||||
|
self.update_file_list()
|
||||||
|
self.running = False
|
||||||
|
|
||||||
|
def update_file_list(self):
|
||||||
|
self.file_list = filter(lambda x: x.endswith('.rst'), os.listdir(self.dir) )
|
||||||
|
for filename in self.file_list:
|
||||||
|
filename = self.dir+'/'+filename
|
||||||
|
statbuf = os.stat(filename)
|
||||||
|
date = statbuf.st_mtime
|
||||||
|
if filename not in self.last_time:
|
||||||
|
self.last_time[filename] = -1
|
||||||
|
self.last_line[filename] = -1
|
||||||
|
self.data[filename] = []
|
||||||
|
if date > self.last_time[filename]:
|
||||||
|
# Read file
|
||||||
|
file = open(filename,'r')
|
||||||
|
self.data[filename] = file.read().splitlines()
|
||||||
|
file.close()
|
||||||
|
# Print new lines
|
||||||
|
output = self.data[filename]
|
||||||
|
for line in output[self.last_line[filename]+1:]:
|
||||||
|
print line
|
||||||
|
self.last_time[filename] = date
|
||||||
|
self.last_line[filename] = len(output)-1
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
self.running = True
|
||||||
|
while self.running:
|
||||||
|
time.sleep(1.)
|
||||||
|
self.update_file_list()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
F = OutputFollower(sys.argv[1])
|
||||||
|
|
||||||
|
# Handle signals
|
||||||
|
import signal
|
||||||
|
def handler(signum,frame):
|
||||||
|
F.running = False
|
||||||
|
|
||||||
|
for i in [2, 15]:
|
||||||
|
try:
|
||||||
|
signal.signal(i, handler)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
F.start()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
||||||
|
|
133
scripts/qp_bitmasks.py
Normal file
133
scripts/qp_bitmasks.py
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
#! /usr/bin/env python
|
||||||
|
|
||||||
|
BIT_KIND_SIZE=64
|
||||||
|
|
||||||
|
|
||||||
|
def int_to_string(s):
|
||||||
|
"""Transforms any integer to a string representation
|
||||||
|
>>> print int_to_string(10)
|
||||||
|
1010
|
||||||
|
>>> print int_to_string(1024)
|
||||||
|
10000000000
|
||||||
|
>>> print int_to_string(123456789)
|
||||||
|
111010110111100110100010101
|
||||||
|
>>> print int_to_string(12345678912345678910)
|
||||||
|
1010101101010100101010011000111110000001011001010010010000111110
|
||||||
|
>>> print int_to_string(0)
|
||||||
|
0
|
||||||
|
>>> print int_to_string(-128)
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "<stdin>", line 1, in <module>
|
||||||
|
File "qp_bitmasks.py", line 23, in int_to_string
|
||||||
|
assert s>=0
|
||||||
|
AssertionError
|
||||||
|
"""
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
def string_to_bitmask(s,bit_kind_size=BIT_KIND_SIZE):
|
||||||
|
"""Transforms a string into an bitmask
|
||||||
|
>>> print string_to_bitmask(10)
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "<stdin>", line 1, in <module>
|
||||||
|
File "qp_bitmasks.py", line 30, in string_to_bitmask
|
||||||
|
assert type(s) == str
|
||||||
|
AssertionError
|
||||||
|
>>> print string_to_bitmask('10')
|
||||||
|
['0000000000000000000000000000000000000000000000000000000000000010']
|
||||||
|
>>> print string_to_bitmask('1010'*64)
|
||||||
|
['1010101010101010101010101010101010101010101010101010101010101010', '1010101010101010101010101010101010101010101010101010101010101010', '1010101010101010101010101010101010101010101010101010101010101010', '1010101010101010101010101010101010101010101010101010101010101010']
|
||||||
|
>>> print string_to_bitmask('1010'*64,4)
|
||||||
|
['1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010', '1010']
|
||||||
|
"""
|
||||||
|
assert type(s) == str
|
||||||
|
assert bit_kind_size > 0
|
||||||
|
|
||||||
|
while len(s) % bit_kind_size != 0:
|
||||||
|
s = '0'+s
|
||||||
|
return [ s[i:i+bit_kind_size] for i in range(0,len(s),bit_kind_size) ]
|
||||||
|
|
||||||
|
|
||||||
|
def int_to_bitmask(s,bit_kind_size=BIT_KIND_SIZE):
|
||||||
|
"""Transforms a string into an bitmask
|
||||||
|
>>> int_to_bitmask(1)
|
||||||
|
['0000000000000000000000000000000000000000000000000000000000000001']
|
||||||
|
>>> int_to_bitmask(-1)
|
||||||
|
['1111111111111111111111111111111111111111111111111111111111111111']
|
||||||
|
>>> int_to_bitmask(10)
|
||||||
|
['0000000000000000000000000000000000000000000000000000000000001010']
|
||||||
|
>>> int_to_bitmask(-10)
|
||||||
|
['1111111111111111111111111111111111111111111111111111111111110110']
|
||||||
|
>>>
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class BitMask(object):
|
||||||
|
|
||||||
|
"""
|
||||||
|
>>> A = BitMask( [ -127,47 ], bit_kind_size=8)
|
||||||
|
>>> print A
|
||||||
|
['10000001', '00101111']
|
||||||
|
>>> print A[0]
|
||||||
|
-127
|
||||||
|
>>> print A[1]
|
||||||
|
47
|
||||||
|
>>> A[0] = 127
|
||||||
|
>>> print A
|
||||||
|
['01111111', '00101111']
|
||||||
|
>>> A[1] = '100'
|
||||||
|
>>> print A
|
||||||
|
['01111111', '00000100']
|
||||||
|
>>> A[1] = '10000001'
|
||||||
|
>>> print A
|
||||||
|
['01111111', '10000001']
|
||||||
|
>>> print A[1]
|
||||||
|
-127
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def __init__(self,l=[],bit_kind_size=BIT_KIND_SIZE):
|
||||||
|
self.bit_kind_size = bit_kind_size
|
||||||
|
self._data_int = l
|
||||||
|
|
||||||
|
def get_N_int(self):
|
||||||
|
return len(self._data_int)
|
||||||
|
N_int = property(fget=get_N_int)
|
||||||
|
|
||||||
|
def __getitem__(self,i):
|
||||||
|
return self._data_int[i]
|
||||||
|
|
||||||
|
def __setitem__(self,i,value):
|
||||||
|
if type(value) in (int,long):
|
||||||
|
self._data_int[i] = value
|
||||||
|
elif type(value) == str:
|
||||||
|
s = string_to_bitmask(value,bit_kind_size=self.bit_kind_size)[0]
|
||||||
|
if s[0] == '0':
|
||||||
|
self._data_int[i] = int(s,2)
|
||||||
|
else:
|
||||||
|
s = s.replace('0','.').replace('1','0').replace('.','1')
|
||||||
|
self._data_int[i] = -int(s,2)-1
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
result = []
|
||||||
|
for i in self._data_int:
|
||||||
|
result += int_to_bitmask(i,bit_kind_size=self.bit_kind_size)
|
||||||
|
return str(result)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import doctest
|
||||||
|
doctest.testmod()
|
127
scripts/qpackage
Executable file
127
scripts/qpackage
Executable file
@ -0,0 +1,127 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Runs the programs.
|
||||||
|
# Thu Jun 26 23:40:20 CEST 2014
|
||||||
|
|
||||||
|
# Check environment
|
||||||
|
###################
|
||||||
|
|
||||||
|
if [[ -z $QPACKAGE_ROOT ]]
|
||||||
|
then
|
||||||
|
echo "Error:"
|
||||||
|
echo "QPACKAGE_ROOT environment variable is not set."
|
||||||
|
echo "source quantum_package.rc"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# List of executables
|
||||||
|
#####################
|
||||||
|
|
||||||
|
declare -A EXECUTABLES
|
||||||
|
for EXE in $(find $QPACKAGE_ROOT/src -type f -executable | grep -e "$QPACKAGE_ROOT/src/[^/]*/[^/]*$")
|
||||||
|
do
|
||||||
|
EXECUTABLES["$(basename "${EXE}")"]="${EXE}"
|
||||||
|
done
|
||||||
|
|
||||||
|
function print_list()
|
||||||
|
{
|
||||||
|
echo
|
||||||
|
echo "Available programs:"
|
||||||
|
echo
|
||||||
|
for EXE in ${!EXECUTABLES[@]}
|
||||||
|
do
|
||||||
|
printf " * %-30s [ %s ]\n" $EXE ${EXECUTABLES[$EXE]}
|
||||||
|
done | sort
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
# Help message
|
||||||
|
##############
|
||||||
|
|
||||||
|
function print_help()
|
||||||
|
{
|
||||||
|
cat << EOF
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
qpackage -h | --help
|
||||||
|
qpackage -l | --list
|
||||||
|
qpackage run <program> <EZFIO_input>
|
||||||
|
qpackage reset <EZFIO_input>
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h --help Print help message
|
||||||
|
-l --list List executables
|
||||||
|
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
ARGS=$(getopt -o "hl" -l "help,list" -n $0 -- "$@")
|
||||||
|
|
||||||
|
[[ $? -eq 0 ]] || exit 1
|
||||||
|
|
||||||
|
eval set -- "$ARGS"
|
||||||
|
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
print_help
|
||||||
|
exit 0
|
||||||
|
shift ;;
|
||||||
|
|
||||||
|
-l|--list)
|
||||||
|
print_list
|
||||||
|
exit 0
|
||||||
|
shift ;;
|
||||||
|
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Run commands
|
||||||
|
##############
|
||||||
|
|
||||||
|
function run()
|
||||||
|
{
|
||||||
|
# run $EXE $EZFIO
|
||||||
|
# Starts the executable in one process and
|
||||||
|
# displays the output files in stdout
|
||||||
|
EXE=${EXECUTABLES[$1]}
|
||||||
|
EZFIO=$2
|
||||||
|
date
|
||||||
|
${QPACKAGE_ROOT}/scripts/follow_output.py ${EZFIO} &
|
||||||
|
${EXE} ${EZFIO}
|
||||||
|
kill -2 %1
|
||||||
|
wait
|
||||||
|
date
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset()
|
||||||
|
{
|
||||||
|
# reset $EZFIO
|
||||||
|
rm -rf $1/output/*.rst
|
||||||
|
rm -rf $1/determinants/{n_det,psi_det.gz,psi_coef.gz}
|
||||||
|
}
|
||||||
|
|
||||||
|
COMMAND=$1
|
||||||
|
shift
|
||||||
|
|
||||||
|
case "${COMMAND}" in
|
||||||
|
run)
|
||||||
|
run $1 $2
|
||||||
|
;;
|
||||||
|
reset)
|
||||||
|
reset $1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
print_help
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user