Open mortele opened 3 years ago
@mortele Referring your example code #72, put the args in a tuple looks nice. I just add that we need a * operator to unpack the tuple:
args = tuple(args[:10 + int(charges_flag) + int(mass_flag)])
dd = domain_decomposition(
*args, ##args
...
)
## testing
def f (a, b, c):
return a*b*c
x = tuple([3, 5 ])
print( f(*x, 10 ) ) ## 150
I tried to define two args arg_in and arg_recv; but I think using arg_recv in my try here is a silly mistake.. As when the tuple is generated the values are used, not the variables, thus I still have to make the args_recv explicit.
!!!!!!!!!!!!!!!!!!!!!!!!!! NOT CORRECT, can ignore !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Affiliated_DD_Args_in_Len = 9 ## can also use the append without defining the length ?
args_in = [None for _ in range(Affiliated_DD_Args_Len)]
args_in[:7] = [
velocities,
indices,
bond_forces,
angle_forces,
field_forces,
names,
types
]
if charges_flag: ## add charge related
args_in[7] = charges
args_in[8] = field_q_forces
## args_recv for the (..) = dd
args_recv = args_in.copy()
args_recv.insert(0, positions)
if molecules_flag:
args_recv.append(bonds)
args_recv.append(molecules)
## convert to tuple
args_in = tuple(args_in)
args_recv= tuple(args_recv)
############### DD
if config.domain_decomposition:
dd = domain_decomposition(
positions,
pm,
*args_in,
molecules=molecules if molecules_flag else None,
bonds=bonds if molecules_flag else None,
verbose=args.verbose,
comm=comm,
)
args_recv = dd #<------------ WRONG
Hi @mortele, this is a rewriting of the call about the domain_decomposition() function.
args_in = [
velocities,
indices,
bond_forces,
angle_forces,
field_forces,
names,
types
]
args_recv = [
'positions',
'velocities',
'indices',
'bond_forces',
'angle_forces',
'field_forces',
'names',
'types'
]
if charges_flag: ## add charge related
args_in.append(charges)
args_in.append(field_q_forces)
args_recv.append('charges')
args_recv.append('field_q_forces')
if molecules_flag:
args_recv.append('bonds')
args_recv.append('molecules')
## convert to tuple
args_in = tuple(args_in)
## cmd string to excecut the (...) = dd
_str_receive_dd = ','.join(args_recv)
_cmd_receive_dd = f"({_str_receive_dd }) = dd"
############### DD
if config.domain_decomposition:
dd = domain_decomposition(
positions,
pm,
*args_in,
molecules=molecules if molecules_flag else None,
bonds=bonds if molecules_flag else None,
verbose=args.verbose,
comm=comm,
)
exec(_cmd_receive_dd )
Nice work! We should meet on Monday to discuss!
Nice work! We should meet on Monday to discuss!
👌😄 see you on Monday~
These long function calls to
domain_decomposition(...)
with many lines of arguments doubled by the if test clause for the molecules being present is getting cumbersome. Look into rewriting this in a more sane way, so we can add conditional arrays to the decomposition without having to add 2ⁿ if test clauses, each with it's own 10+ lines of arguments. See discussion from #72.