by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Leonard Harris
    @lh64
    @glucksfall There's not a simple function for deleting a Rule but you can try manually recreating the model.rules object by excluding the Rule(s) you don't want, using model.reset_equations to clear out the reactions, species, etc. created by BNG, and then regenerating the network. Here's a small example script I put together doing that:
    Rodrigo Santibáñez
    @glucksfall
    Thank you @lh64.
    saubhagya-gatech
    @saubhagya-gatech

    Hello everyone,

    I was wondering if it is possible to provide multivariate distribution as prior instead of independent priors for parameters in PyDream?

    Oscar Ortega
    @ortega2247
    Hi @saubhagya-gatech , sorry for the late reply. Dream(ZS) has a minimum number of chains requirement of 3. Unfortunately, pydream doesn't support the usage of multivariate distributions as a prior
    saubhagya-gatech
    @saubhagya-gatech
    @ortega2247 Thank you!
    Leonard Harris
    @lh64
    @pietromicheli You should be able to accomplish what you want using the initials or param_values arguments to the run method of the simulator. I'm attaching an example here. I defined two simple rules: X() >> None and A() + X() >> X(). In the code, I first run a simulation of the full system. Then, I run two sequential simulations, the first with only the X() >> None rule and the second with only the A() + X() >> X() rule, where the concentration of X() from the first simulation is fed into the simulator for the second simulation using the initials argument to ScipyOdeSimulator.run. To be clear, the second "simulation" is actually a series of simulations from output time point to output time point, with the final concentration of A() from the previous step and the corresponding value of X() passed into the simulator at each step. I have it loop over three different numbers of output points (10, 100, and 1000) to show how the output of the sequential simulation approaches the true result from the full simulation as the number of output points increases. I'm attaching those plots here as well. Hopefully this helps. If you have any further questions just let us know.
    Figure_1.png
    figure_2.png
    figure_3.png
    pietromicheli
    @pietromicheli

    @lh64 Thank you for the answer!

    Actually my first approach to this problem was to iteratively run one simulation for each time point just as you suggested, but I wasn't very happy with the computational cost of a such sequential simulation (expecially for a high number of time points). However looking at your code I noticed that (stupidly) I created at each iteration a new simulator object (via ScipyOdeSimulator() function). So it turned out that this unnecessary step tripled the cost of each iteration, compared to the cost that runinning the simulations (via .run() method) using always the same simulator object at each iteration would require. The overall cost is still quite high obviously, but for reasonably small number of time points it is tollerable.

    Your answer and your code has been really helpfull, thanks a lot! :)

    saubhagya-gatech
    @saubhagya-gatech
    Hello @ortega2247
    Was there any change made in the PyDream in the last one month? I installed the package again and the "start" argument is not working. It does not matter what chain initialization I give, the chains are starting at random positions. Any help here would be appreciated. Before I reinstalled PyDream yesterday, I did not have this issue.
    saubhagya-gatech
    @saubhagya-gatech
    Here is the output file. I have printed the list of starting positions of 5 chains, and I also print the parameters received my likelihood function as "proposed parameter values". The first step has totally different proposed values then what is specified in the "start". I think this might be a bug.
    Oscar Ortega
    @ortega2247
    Hi @saubhagya-gatech , I am sorry PyDREAM is having issues. PyDREAM hasn't been updated since March 25 so I am not sure why this is happening. If you used pip to install pydream you can check the version installed by typing: pip show pydream in the terminal. The version should be 2.0.0
    If you send me a reproducible example, that would help me to find where the problem is
    saubhagya-gatech
    @saubhagya-gatech
    Thank you Oscar. I was looking at Github and I see pull request accepted on May 14th which had some changes relevant to the start argument. Is "pip install" currently installing version with these changes?
    https://github.com/LoLab-VU/PyDREAM/pull/20/files/384866c232f9a16b8da4a7ececea62d665eaf644
    I will prepare a reproducible example. I actually manually installed March 25 version using the source code and that is not showing the mentioned issue
    saubhagya-gatech
    @saubhagya-gatech
    I did some more numerical tests and found that if I used this version:( https://github.com/LoLab-VU/PyDREAM/releases/tag/v2.0.0) the start argument is working, but if I use the version installed from "pip install pydream", the start argument is not working. Give me few minute to send an example
    Oscar Ortega
    @ortega2247
    mmm so strange. pip install should be installing this release: https://github.com/LoLab-VU/PyDREAM/releases/tag/v2.0.0 unless you are using python 2
    saubhagya-gatech
    @saubhagya-gatech
    ah ok. I am currently double-checking my python versions and package locations. I will get back to you either today or tomorrow if I figure out what is happening.
    On a different note, the version with acceptance-ratio correction is not released yet, right?
    Oscar Ortega
    @ortega2247
    that's correct
    i should be releasing it soon
    Oscar Ortega
    @ortega2247
    it fixes the reporting of acceptance rates when one restarts a pydream run. Before this fix, we observed that the acceptance rates were dropping when restarting because the number of accepted points where reset to zero instead of keeping the history of the number of accepted points in the previous run
    saubhagya-gatech
    @saubhagya-gatech
    That makes sense. Thank you. Here is a reproducible example. After running the mcmc_run.py, you can run reading_results.py to print the first step that chains actually took. This is coming out to be different from the first step defined in "start" which is also printed in the python outputs. I could not think of any reason for this. Any help would be appreciated.
    ^ it might not be related to versions and might not even be an "issue". I am just trying to understand what is happening.
    opurcell
    @opurcell

    Hi, I am having some ongoing trouble with the SBML exporter. Specifically the line 'sbml_output = export(model, 'sbml'). I never had problems before and had been using PySB to build and then export my models for some time, but after starting a new venv (under PyCharm) and I assume then using the latest package versions I started having issues. I solved these by just returning to the exact package versions for everything that I had, which fixed it. However now I am moving from a local instance to AWS, I am seeing the same issues and so far have not been able to solve them with package versions. The initial error is:

    Traceback (most recent call last):
    File "predict_KOs.py", line 605, in <module>
    main()
    File "predict_KOs.py", line 591, in main
    mode_1_results = run_mode_1()
    File "predict_KOs.py", line 375, in run_mode_1
    model = build.build_model(networks[network])
    File "/home/ubuntu/build.py", line 1177, in build_model
    sbml_output = export(model, 'sbml')
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/export/init.py", line 176, in export
    return e.export()
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/export/sbml.py", line 315, in export
    return libsbml.writeSBMLToString(self.convert(level=level))
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/export/sbml.py", line 125, in convert
    pysb.bng.generate_equations(self.model)
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/bng.py", line 732, in generate_equations
    verbose=verbose, **kwargs).split('\n'))
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/bng.py", line 672, in generate_network
    bngfile.execute()
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/bng.py", line 443, in execute
    output += self.generator.get_content()
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/generator/bng.py", line 26, in get_content
    self.generate_content()
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/generator/bng.py", line 31, in generate_content
    self.generate_parameters()
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/generator/bng.py", line 42, in generate_parameters
    exprs = self.model.expressions_constant()
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/core.py", line 1976, in expressions_constant
    cset = ComponentSet(e for e in self.expressions
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/core.py", line 2255, in init
    for value in iterable:
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/core.py", line 1977, in <genexpr>
    if e.is_constant_expression())
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/core.py", line 1644, in is_constant_expression
    for a in self.expr.atoms())
    File "/home/ubuntu/.local/lib/python3.7/site-packages/sympy/core/basic.py", line 523, in atoms
    result = {node for node in nodes if not node.args}
    File "/home/ubuntu/.local/lib/python3.7/site-packages/sympy/core/basic.py", line 523, in <setcomp>
    result = {node for node in nodes if not node.args}
    AttributeError: 'str' object has no attribute 'args'

    which is obtained using sympy==1.6.1. If I instead use sympy 1.5.1 (which is the version I had it working locally with), I get a an error about the BNG2.pl file, which I have confirmed is where it should be:

    Traceback (most recent call last):
    File "predict_KOs.py", line 605, in <module>
    main()
    File "predict_KOs.py", line 591, in main
    mode_1_results = run_mode_1()
    File "predict_KOs.py", line 375, in run_mode_1
    model = build.build_model(networks[network])
    File "/home/ubuntu/build.py", line 1177, in build_model
    sbml_output = export(model, 'sbml')
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/export/init.py", line 176, in export
    return e.export()
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/export/sbml.py", line 315, in export
    return libsbml.writeSBMLToString(self.convert(level=level))
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/export/sbml.

    the end of the second error was missed off:

    Traceback (most recent call last):
    File "predict_KOs.py", line 605, in <module>
    main()
    File "predict_KOs.py", line 591, in main
    mode_1_results = run_mode_1()
    File "predict_KOs.py", line 375, in run_mode_1
    model = build.build_model(networks[network])
    File "/home/ubuntu/build.py", line 1177, in build_model
    sbml_output = export(model, 'sbml')
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/export/init.py", line 176, in export
    return e.export()
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/export/sbml.py", line 315, in export
    return libsbml.writeSBMLToString(self.convert(level=level))
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/export/sbml.py", line 125, in convert
    pysb.bng.generate_equations(self.model)
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/bng.py", line 732, in generate_equations
    verbose=verbose, **kwargs).split('\n'))
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/bng.py", line 672, in generate_network
    bngfile.execute()
    File "/home/ubuntu/.local/lib/python3.7/site-packages/pysb/bng.py", line 487, in execute
    p_err.rstrip())
    pysb.bng.BngInterfaceError:
    Can't open perl script "BioNetGen-2.5.0/BNG2.pl": No such file or directory

    Rodrigo Santibáñez
    @glucksfall
    use
    from pysb.pathfinder import set_path
    set_path('bng', path_to_BNG2.pl)
    opurcell
    @opurcell
    Thanks, that fixed it. I'm curious tho - why is there the sympy package dependency? i.e. why does it work with 1.5.1, but not with 1.6.1?
    Rodrigo Santibáñez
    @glucksfall
    I'm just a pySB user...
    opurcell
    @opurcell
    I see. Well thanks for the fix. If anyone in the pySB dev community is able to shed any light on the dependency issue that would be great. Im using python 3.7 and pySB 1.11. BioNetGen 2-5-0.
    Alex Lubbock
    @alubbock
    sympy 1.6.1 was only recently released. We've added support for it in the PySB master branch on Github, which will be included in the next PySB release.
    If you install using an anaconda environment conda install -c alubbock pysb, the dependency versions should be pinned correctly (please let me know if not).
    opurcell
    @opurcell
    OK thanks for the explanation. Good to know.
    Rodrigo Santibáñez
    @glucksfall

    Hello everyone, I hope you're fine. I have a problem trying to export a model to stochkit. Do you still support the simulator? I tested the following

    from pysb.examples import robertson
    model = robertson.model
    
    from pysb.export import *
    export(model, 'stochkit')

    and the output is

    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-9-7b665249f49e> in <module>
          3 
          4 from pysb.export import *
    ----> 5 export(model, 'stochkit')
    
    /usr/local/lib/python3.8/dist-packages/pysb/export/__init__.py in export(model, format, docstring)
        174     export_class = getattr(export_module, formats[format])
        175     e = export_class(model, docstring)
    --> 176     return e.export()
        177 
        178 def pad(text, depth=0):
    
    /usr/local/lib/python3.8/dist-packages/pysb/export/stochkit.py in export(self, initials, param_values)
        250 
        251             # expand only expressions used in the rate eqn
    --> 252             for e in {sym for sym in rxn["rate"].atoms()
        253                       if isinstance(sym, Expression)}:
        254                 rate = re.sub(r'\b%s\b' % e.name,
    
    /usr/local/lib/python3.8/dist-packages/sympy/core/basic.py in atoms(self, *types)
        521             result = {node for node in nodes if isinstance(node, types)}
        522         else:
    --> 523             result = {node for node in nodes if not node.args}
        524         return result
        525 
    
    /usr/local/lib/python3.8/dist-packages/sympy/core/basic.py in <setcomp>(.0)
        521             result = {node for node in nodes if isinstance(node, types)}
        522         else:
    --> 523             result = {node for node in nodes if not node.args}
        524         return result
        525 
    
    AttributeError: 'str' object has no attribute 'args'
    am I doing something wrong?
    ABsintio
    @ABsintio

    Hello everyone. I'm a third year computer science student at the University "La Sapienza" in Rome and I have to use the interface PySB/cupSODA to simulate an sbml model on a GPU. I wrote a simple python script

    from pysb.importers.sbml import model_from_sbml
    from pysb.simulator.cupsoda import CupSodaSimulator
    
    filename="BIOMD0000000005_url.txt"
    model = model_from_sbml(filename=filename, cleanup=False)
    simulator = CupSodaSimulator(model=model)

    but I get this error

    AttributeError                            Traceback (most recent call last)
    <ipython-input-5-b1ba6e155a18> in <module>
    ----> 1 simulator = CupSodaSimulator(model=model)
    
    ~/anaconda3/lib/python3.8/site-packages/pysb/simulator/cupsoda.py in __init__(self, model, tspan, initials, param_values, verbose, **kwargs)
        197 
        198         # generate the equations for the model
    --> 199         pysb.bng.generate_equations(self._model, self._cleanup, self.verbose)
        200 
        201         # build integrator options list from our defaults and any kwargs
    
    ~/anaconda3/lib/python3.8/site-packages/pysb/bng.py in generate_equations(model, cleanup, verbose, **kwargs)
        729     if model.reactions:
        730         return
    --> 731     lines = iter(generate_network(model, cleanup=cleanup,
        732                                   verbose=verbose, **kwargs).split('\n'))
        733     _parse_netfile(model, lines)
    
    ~/anaconda3/lib/python3.8/site-packages/pysb/bng.py in generate_network(model, cleanup, append_stdout, verbose, **kwargs)
        670         bngfile.action('generate_network', overwrite=True,
        671                        verbose=bng_action_debug, **kwargs)
    --> 672         bngfile.execute()
        673 
        674         output = bngfile.read_netfile()
    
    ~/anaconda3/lib/python3.8/site-packages/pysb/bng.py in execute(self, reload_netfile, skip_file_actions)
        441             output = ''
        442             if self.model and not reload_netfile:
    --> 443                 output += self.generator.get_content()
        444             if reload_netfile:
        445                 filename = reload_netfile if \
    
    ~/anaconda3/lib/python3.8/site-packages/pysb/generator/bng.py in get_content(self)
         24     def get_content(self):
         25         if self.__content == None:
    ---> 26             self.generate_content()
         27         return self.__content
         28 
    
    ~/anaconda3/lib/python3.8/site-packages/pysb/generator/bng.py in generate_content(self)
         29     def generate_content(self):
         30         self.__content = "begin model\n"
    ---> 31         self.generate_parameters()
         32         self.generate_compartments()
         33         self.generate_molecule_types()
    
    ~/anaconda3/lib/python3.8/site-packages/pysb/generator/bng.py in generate_parameters(self)
         40 
         41     def generate_parameters(self):
    ---> 42         exprs = self.model.expressions_constant()
         43         if not self.model.parameters and not exprs:
         44             return
    
    ~/anaconda3/lib/python3.8/site-packages/pysb/core.py in expressions_constant(self)
       1974     def expressions_constant(self):
       1975         """Return a ComponentSet of constant expressions."""
    -> 1976         cset = ComponentSet(e for e in self.expressions
       1977                             if e.is_constant_expression())
       1978         return cset
    
    ~/anaconda3/lib/python3.8/site-packages/pysb/core.py in __init__(self, iterable)
       2253         self._index_map = {}
       2254         if iterable is not None:
    -> 2255             for value in iterable:
       2256                 self.add(value)
       2257 
    
    ~/anaconda3/lib/python3.8/site-packages/pysb/core.py in <genexpr>(.0)
       1975         """Return a ComponentSet of constant expressions."""
       1976         cset = ComponentSet(e for e in self.expressions
    -> 1977                             if e.is_constant_expression())
       1978         return cset
       1979 
    
    ~/anaconda3/lib/python3.8/site-packages/pysb/core.py in is_constant_expression(self)
       1642                    (isinstance(a, Expression) and a.is_constant_expression()) or
       1643                    isinstance(a, sympy.Number)
    -> 16
    1644                    for a in self.expr.atoms())
       1645 
       1646     def get_value(self):
    
    ~/anaconda3/lib/python3.8/site-packages/sympy/core/basic.py in atoms(self, *types)
        521             result = {node for node in nodes if isinstance(node, types)}
        522         else:
    --> 523             result = {node for node in nodes if not node.args}
        524         return result
        525 
    
    ~/anaconda3/lib/python3.8/site-packages/sympy/core/basic.py in <setcomp>(.0)
        521             result = {node for node in nodes if isinstance(node, types)}
        522         else:
    --> 523             result = {node for node in nodes if not node.args}
        524         return result
        525 
    
    AttributeError: 'str' object has no attribute 'args'
    What do I have to do?
    Thanks to everyone
    Rodrigo Santibáñez
    @glucksfall
    Hi @ABsintio, could you try this:
    from pysb.examples import robertson
    model = robertson.model
    
    from pysb.simulator import CupSodaSimulator
    
    from pysb.pathfinder import set_path
    set_path('cupsoda', '/opt/git-repositories/cupSODA.aresio/')
    CupSodaSimulator(model, tspan = range(0,10)).run().dataframe
    image.png
    Please change the path to cupsoda.
    ABsintio
    @ABsintio

    @glucksfall Thanks a lot! Then I try this. Just another question. Where is the cupSODA path? Because i have a directory, let's suppose /A/B/C/, with an executable named cupSODA35. So I entered the command

    set_path("cupsoda", "/A/B/C")

    but it gave me the following erorr

    ValueError                                Traceback (most recent call last)
    <ipython-input-7-c68e23d371de> in <module>
    ----> 1 set_path("cupsoda", "/A/B/C/")
    
    ~/anaconda3/lib/python3.8/site-packages/pysb/pathfinder.py in set_path(prog_name, full_path)
        234         raise ValueError('%s is not a known external executable' % prog_name)
        235 
    --> 236     _path_cache[prog_name] = _validate_path(prog_name, full_path)
        237 
        238 
    
    ~/anaconda3/lib/python3.8/site-packages/pysb/pathfinder.py in _validate_path(prog_name, full_path)
        291 
        292         # It's a directory, try appending the executable name
    --> 293         return _validate_path(prog_name, os.path.join(full_path,
        294                                                       _get_executable(
        295                                                           prog_name)))
    
    ~/anaconda3/lib/python3.8/site-packages/pysb/pathfinder.py in _validate_path(prog_name, full_path)
        276 def _validate_path(prog_name, full_path):
        277     if not os.access(full_path, os.F_OK):
    --> 278         raise ValueError('Unable to access path %s. Check the file exists '
        279                          'and the current user has permission to access it.' %
        280                          full_path)
    
    ValueError: Unable to access path /A/B/C/cupSODA. Check the file exists and the current user has permission to access it.
    Do I have to rename cupSODA35 into cupSODA ?
    Rodrigo Santibáñez
    @glucksfall
    I would suggest compile cupsoda with the correct capability of your GPU. Mine is 61: nvcc kernel.cu cupSODA.cu input_reader.cpp stoc2det.cpp -gencode=arch=compute_61,code=compute_61 -O3 -o cupSODA --use_fast_math --cudart static
    ABsintio
    @ABsintio
    @glucksfall How can I see what's the correct capability ?