From 5086e423535f2b0a1233815f6b0362aacf36923d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Mon, 6 Jun 2022 05:19:11 +0300 Subject: [PATCH] argproc don't convert --vswf-set arguments directly to BaseSpec BaseSpec is currently not picklable, and we want to be able to save the command line arguments used. Hence we first save the ilist as tuple instead. --- qpms/argproc.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/qpms/argproc.py b/qpms/argproc.py index 2295f72..bdbffb2 100644 --- a/qpms/argproc.py +++ b/qpms/argproc.py @@ -238,12 +238,14 @@ constant_tmatrix_spec = namedtuple("constant_tmatrix_spec", ("bspec", "matrix")) cyl_sph_dimensions = namedtuple("cyl_sph_dimensions", ("radius", "height", "lMax_extend")) tmgen_spec = namedtuple("tmgen_spec", ("bgspec", "fgspec", "dims")) -def string2bspec(string): +def string2bspec_tuple(string): """ - Converts string representation of list to BaseSpec. + Converts string representation of list to BaseSpec... + And then to tuple, because we want the arguments to be picklable :( """ from .cybspec import BaseSpec - return BaseSpec(ast.literal_eval(string)) + bspec = BaseSpec(ast.literal_eval(string)) + return tuple(i for i in bspec.ilist) class ArgParser: ''' Common argument parsing engine for QPMS python CLI scripts. ''' @@ -307,10 +309,10 @@ class ArgParser: help='particle radius (cylinder; labeled)') # Alternatively, add a constant T-matrix mpgrp.add_argument("-w", "--vswf-set", nargs=1, default={}, - action=make_dict_action(argtype=string2bspec, postaction='store', first_is_key=False), + action=make_dict_action(argtype=string2bspec_tuple, postaction='store', first_is_key=False), help='Manual specification of VSWF set codes (format as a python list of integers); see docs on qpms_uvswfi_t for valid codes or simply use --lMax instead. Overrides --lMax.') mpgrp.add_argument("+w", "++vswf-set", nargs=2, default={}, - action=make_dict_action(argtype=string2bspec, postaction='store', first_is_key=True), + action=make_dict_action(argtype=string2bspec_tuple, postaction='store', first_is_key=True), metavar=('LABEL', "VSWF_SET"), help='Manual specification of VSWF set codes (format as a python list of integers); see docs on qpms_uvswfi_t for valid codes or simply use ++lMax instead. Overrides ++lMax and --lMax.') mpgrp.add_argument("-T", "--constant-tmatrix", nargs=1, default={},