pharmpy / pharmpy

A library and toolkit for pharmacometrics
https://pharmpy.github.io
GNU General Public License v3.0
48 stars 14 forks source link

TMDD is not generating all models for 2 types of DVs #2818

Open Orwa-bit opened 8 months ago

Orwa-bit commented 8 months ago

Pharmr-v0.108.0

TMDD is now running with 2 types of DV in using the run_amd but it only generated 8 QSS models (to my understanding from the updated documentations that only models with 1 DV will be removed (Wagner, CR and CR-IB only), I was expecting FULL, IB, MM models to be generated as well. What do you think? This is the code I used for TMDD:

res <- run_amd( modeltype='tmdd', input=model_tmdd, cl_init = init_cl, vc_init = init_vc, mat_init = init_mat, search_space='PERIPHERALS([1,2]);ELIMINATION([FO,ZO])', dv_types=list('drug_tot'=1L, 'target'=2L) )

antoniaih commented 8 months ago

Does this mean that the summary_tool table only contains QSS models? Does the same thing happen when you only run structsearch for TMDD models?

Orwa-bit commented 8 months ago

run structsearch produced only QSS models in v0.108.0 and v0.107.0.

run structsearch produced all models in v0.106.0 including QSS, Full, IB, MM, Wagner, CR, and CR-IB.

I was expecting to see all models except Wagner, CR, and CR-IB.

antoniaih commented 8 months ago

I cannot reproduce this behaviour. When I run structsearch for a model with 2 DVIDs it produces the correct number of models. Do you get any error message?

Orwa-bit commented 7 months ago

After rerunning and looking into the TMDD runs in v0.108, it looks like one of the QSS models was not successfully running. Therefore, I started from a different basic PK model (as an input) and using the following:

res = run_structsearch(type='tmdd', model=basicPK_replaced_dataset, results= basicPK_results, dv_types = list('drug_tot'= 1L,'target'= 2L))

I was able to generate all expected TMDD models (without the single DV models like Wagner as expected). So this is good.


I just wanted to ask you about using run_amd in TMDD. I was looking at the documentation. The example for this run is:

res <- run_amd( modeltype='tmdd', input=start_model, cl_init=2.0, vc_init=5.0, mat_init=3.0, search_space='PERIPHERALS([1,2]);ELIMINATION([FO,ZO])', dv_types=list('drug'=1, 'target'=2, 'complex'=3) ) My question is: does the input model have to be a TMDD? I tried a full dataset (2 DV types) or Basic PK + replacing dataset to have 2 types of DV (as in PKPD case), but it still generates only basic PK models with 1 filtered DV, I also tried a FULL tmdd model as a starting point, it generated another FULL tmdd model but it failed to continue with the following error (maybe I need to start with simpler tmdd model like QSS? and shouldn't it be working with datasets with more than 1 DV type as an input?): /home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/tools/amd/run.py:1165: UserWarning: IOVsearch will be skipped because occasion is None. warnings.warn('IOVsearch will be skipped because occasion is None.') /home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/tools/amd/run.py:1187: UserWarning: Allometry will be skipped because allometric_variable is None and could not be inferred through .datainfo via "body weight" descriptor. warnings.warn( /home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/tools/amd/run.py:1299: UserWarning: COVsearch will be skipped because no covariates were given or could be extracted. Check search_space definition and .datainfo usage of "covariate" type and "continuous" flag. warnings.warn( 2024-04-05 09:23:44,438 - distributed.worker - WARNING - Compute Failed Key: start_modelsearch-results Function: execute_task args: ((<function _results at 0x7f539127b2e0>, (<function start at 0x7f539127b520>, <pharmpy.workflows.tool_database.local_directory.LocalDirectoryToolDatabase object at 0x7f5367d77460>, 'ABSORPTION([FO,ZO,SEQ-ZO-FO]);ELIMINATION([MM,MIX-FO-MM]);LAGTIME([OFF,ON]);TRANSITS([0,1,3,10],*);PERIPHERALS(0..1)', 'reduced_stepwise', 'absorption_delay', 'mbic', None, , , 'minimization_successful or (rounding_errors and sigdigs>=0.1)'))) kwargs: {} Exception: 'UnexpectedToken()'

<Client: 'inproc://172.17.0.12/338/1' processes=1 threads=12, memory=46.99 GiB> <Client: 'inproc://172.17.0.12/338/10' processes=1 threads=12, memory=46.99 GiB> Exception: UnexpectedToken() Full stack: ExceptionUnexpectedToken()c(" File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/tools/amd/run.py\", line 499, in run_amd\n subresults = func(next_model, next_res)\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/tools/amd/run.py\", line 742, in _run_structsearch_tmdd\n res = run_tool(\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/tools/run.py\", line 169, in run_tool\n return run_tool_with_name(name, tool, args, kwargs)\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/tools/run.py\", line 207, in run_tool_with_name\n res = execute_workflow(wf, dispatcher=dispatcher, database=tool_database)\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/workflows/execute.py\", line 73, in execute_workflow\n res: T = dispatcher.run(workflow)\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/workflows/dispatchers/local_dask.py\", line 84, in run\n res = client.get(dsk_optimized, 'results')\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/distributed/client.py\", line 3275, in get\n results = self.gather(packed, asynchronous=asynchronous, direct=direct)\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/distributed/client.py\", line 2372, in gather\n return self.sync(\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/tools/modelsearch/tool.py\", line 133, in start\n mfl_funcs = filter_mfl_statements(mfl_statements, create_base_model(mfl_statements, model))\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/tools/modelsearch/tool.py\", line 241, in create_base_model\n base = func(base)\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/modeling/odes.py\", line 1315, in set_first_order_absorption\n model = model.update_source()\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/model/external/nonmem/model.py\", line 194, in update_source\n model, updated_dataset = update_statements(\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/model/external/nonmem/update.py\", line 706, in update_statements\n model, updated_dataset = update_ode_system(model, old_odes, new_odes)\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/model/external/nonmem/update.py\", line 386, in update_ode_system\n model = to_des(model, new)\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/model/external/nonmem/update.py\", line 636, in to_des\n newdes = des.from_odes(new, to_odes)\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/model/external/nonmem/records/code_record.py\", line 600, in from_odes\n return self.update_statements(statements)\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/model/external/nonmem/records/code_record.py\", line 555, in update_statements\n statement_nodes = self._statement_to_nodes(defined_symbols, s, rvs, trans)\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/model/external/nonmem/records/code_record.py\", line 581, in _statement_to_nodes\n node_tree = CodeRecordParser(statement_str).root\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/internals/parse/generic.py\", line 382, in init\n self.root = self.parse(buf)\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/internals/parse/generic.py\", line 394, in parse\n root = self.lark.parse(self.buffer)\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/lark/lark.py\", line 658, in parse\n return self.parser.parse(text, start=start, on_error=on_error)\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/lark/parser_frontends.py\", line 104, in parse\n return self.parser.parse(stream, chosen_start, kw)\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/lark/parsers/lalr_parser.py\", line 42, in parse\n return self.parser.parse(lexer, start)\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/lark/parsers/lalr_parser.py\", line 88, in parse\n return self.parse_from_state(parser_state)\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/lark/parsers/lalr_parser.py\", line 111, in parse_from_state\n raise e\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/lark/parsers/lalr_parser.py\", line 102, in parse_from_state\n state.feed_token(token)\n", " File \"/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/lark/parsers/lalr_parser_state.py\", line 80, in feed_token\n raise UnexpectedToken(token, expected, state=self, interactive_parser=None)\n" )Traceback (most recent call last): File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/tools/amd/run.py", line 499, in run_amd subresults = func(next_model, next_res) File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/tools/amd/run.py", line 742, in _run_structsearch_tmdd res = run_tool( File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/tools/run.py", line 169, in run_tool return run_tool_with_name(name, tool, args, kwargs) File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/tools/run.py", line 207, in run_tool_with_name res = execute_workflow(wf, dispatcher=dispatcher, database=tool_database) File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/workflows/execute.py", line 73, in execute_workflow res: T = dispatcher.run(workflow) File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/workflows/dispatchers/local_dask.py", line 84, in run res = client.get(dsk_optimized, 'results') File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/distributed/client.py", line 3275, in get results = self.gather(packed, asynchronous=asynchronous, direct=direct) File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/distributed/client.py", line 2372, in gather return self.sync( File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/tools/modelsearch/tool.py", line 133, in start mfl_funcs = filter_mfl_statements(mfl_statements, create_base_model(mfl_statements, model)) File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/tools/modelsearch/tool.py", line 241, in create_base_model base = func(base) File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/modeling/odes.py", line 1315, in set_first_order_absorption model = model.update_source() File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/model/external/nonmem/model.py", line 194, in update_source model, updated_dataset = update_statements( File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/model/external/nonmem/update.py", line 706, in update_statements model, updated_dataset = update_ode_system(model, old_odes, new_odes) File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/model/external/nonmem/update.py", line 386, in update_ode_system model = to_des(model, new) File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/model/external/nonmem/update.py", line 636, in to_des newdes = des.from_odes(new, to_odes) File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/model/external/nonmem/records/code_record.py", line 600, in from_odes return self.update_statements(statements) File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/model/external/nonmem/records/code_record.py", line 555, in update_statements statement_nodes = self._statement_to_nodes(defined_symbols, s, rvs, trans) File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/model/external/nonmem/records/code_record.py", line 581, in _statement_to_nodes node_tree = CodeRecordParser(statement_str).root File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/internals/parse/generic.py", line 382, in init self.root = self.parse(buf) File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/pharmpy/internals/parse/generic.py", line 394, in parse root = self.lark.parse(self.buffer) File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/lark/lark.py", line 658, in parse return self.parser.parse(text, start=start, on_error=on_error) File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/lark/parser_frontends.py", line 104, in parse return self.parser.parse(stream, chosen_start, kw) File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/lark/parsers/lalr_parser.py", line 42, in parse return self.parser.parse(lexer, start) File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/lark/parsers/lalr_parser.py", line 88, in parse return self.parse_from_state(parser_state) File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/lark/parsers/lalr_parser.py", line 111, in parse_from_state raise e File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/lark/parsers/lalr_parser.py", line 102, in parse_from_state state.feed_token(token) File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.10/site-packages/lark/parsers/lalr_parser_state.py", line 80, in feed_token raise UnexpectedToken(token, expected, state=self, interactive_parser=None) Exception: UnexpectedToken()

pharmr version: 0.108.0 '0.108.0' Pharmpy version: 0.108.0

artikandms commented 6 months ago

Hello @Orwa-bit I have a question about the dataset you used in run_structsearch. I'm aware the function need a basic pk model, but what did you use as dataset? Did you keep multiple DVID? Or just one since you used a basic pk model?

After rerunning and looking into the TMDD runs in v0.108, it looks like one of the QSS models was not successfully running. Therefore, I started from a different basic PK model (as an input) and using the following:

res = run_structsearch(type='tmdd', model=basicPK_replaced_dataset, results= basicPK_results, dv_types = list('drug_tot'= 1L,'target'= 2L))

I was able to generate all expected TMDD models (without the single DV models like Wagner as expected). So this is good.

Orwa-bit commented 6 months ago

Hi @artikandms

I replaced the filtered dataset (1 DVID in basic PK) with a multiple DVID dataset before running run_structsearch to generate TMDD models. The code I used is listed in the following issue:

https://github.com/pharmpy/pharmpy/issues/2735

Hope that helps.