Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smetana addConstr() error while using gurobi solver #51

Open
BananaJumper96 opened this issue Nov 22, 2024 · 0 comments
Open

Smetana addConstr() error while using gurobi solver #51

BananaJumper96 opened this issue Nov 22, 2024 · 0 comments

Comments

@BananaJumper96
Copy link

This is my smetana command:

rule smetana:
    input:
        gatherbinmodels
    output:
        detailed_tsv = os.path.join(outpath, "SMETANA", "{binID}_detailed.tsv")
    params:
        smetana_media = "M8",  # Replace with your media
        smetana_solver = "gurobi",    # Replace with your solver
        smetana_flavor = "fbc2",
        media_db = os.path.join(databasesDir, "media_db.tsv"),
        binID = lambda wildcards: wildcards.binID  # Extract bin ID from the input filename
    conda:
        os.path.join(envDir, "env_gurobi.yaml")
    log:
        os.path.join(outpath, "logs", "{binID}_smetana.log")
    shell:
        """
        tmpdir=$(mktemp -d)
        trap "rm -rf $tmpdir" EXIT

        mkdir -p "$(dirname "{output.detailed_tsv}")"

        echo -e "\\nRunning SMETANA for sample {wildcards.binID} ... " >> "{log}"

        cp "{params.media_db}" "$tmpdir/" >> "{log}" 2>&1
        cp {input:q} "$tmpdir/" >> "{log}" 2>&1

        cd "$tmpdir"
        smetana -o "{wildcards.binID}" \
            --flavor "{params.smetana_flavor}" \
            --mediadb "$(basename "{params.media_db}")" \
            -m "{params.smetana_media}" \
            --detailed \
            --solver "{params.smetana_solver}" \
            -v *.xml >> "{log}" 2>&1

        cp "{wildcards.binID}_detailed.tsv" "{output.detailed_tsv}" >> "{log}" 2>&1

        echo "SMETANA analysis for sample {wildcards.binID} completed." >> "{log}"
        """
        
    It is running a snakemake file. However when using the gurobi solver, I get the following error:
Running SMETANA for sample bin.122 ... 
Loading community: all
Running SCS for community all on medium M8...
Restricted license - for non-production use only - expires 2026-11-23
Traceback (most recent call last):
  File "/mnt/lscratch/users/rparise/Thesis/Envs/ece8ca1e4744f5192f12549dd720d25d_/bin/smetana", line 89, in <module>
    main(
  File "/mnt/lscratch/users/rparise/Thesis/Envs/ece8ca1e4744f5192f12549dd720d25d_/lib/python3.11/site-packages/smetana/interface.py", line 345, in main
    entries = run_detailed(comm_id, community, medium_id, excluded_mets, env, verbose, min_mol_weight,
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/lscratch/users/rparise/Thesis/Envs/ece8ca1e4744f5192f12549dd720d25d_/lib/python3.11/site-packages/smetana/interface.py", line 174, in run_detailed
    scs = sc_score(community, environment=env, verbose=verbose)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/lscratch/users/rparise/Thesis/Envs/ece8ca1e4744f5192f12549dd720d25d_/lib/python3.11/site-packages/smetana/smetana.py", line 38, in sc_score
    solver = solver_instance(community.merged)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/lscratch/users/rparise/Thesis/Envs/ece8ca1e4744f5192f12549dd720d25d_/lib/python3.11/site-packages/reframed/solvers/__init__.py", line 104, in solver_instance
    return solvers[solver](model)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/lscratch/users/rparise/Thesis/Envs/ece8ca1e4744f5192f12549dd720d25d_/lib/python3.11/site-packages/reframed/solvers/gurobi_solver.py", line 57, in __init__
    self.build_problem(model)
  File "/mnt/lscratch/users/rparise/Thesis/Envs/ece8ca1e4744f5192f12549dd720d25d_/lib/python3.11/site-packages/reframed/solvers/solver.py", line 99, in build_problem
    self.update()
  File "/mnt/lscratch/users/rparise/Thesis/Envs/ece8ca1e4744f5192f12549dd720d25d_/lib/python3.11/site-packages/reframed/solvers/solver.py", line 80, in update
    self.add_constraints(self._cached_constrs)
  File "/mnt/lscratch/users/rparise/Thesis/Envs/ece8ca1e4744f5192f12549dd720d25d_/lib/python3.11/site-packages/reframed/solvers/gurobi_solver.py", line 72, in add_constraints
    self.problem.addConstr(expr, sense_mapping[sense], rhs, constr_id)
  File "src/gurobipy/_model.pyx", line 3894, in gurobipy._model.Model.addConstr
TypeError: addConstr() takes at most 3 positional arguments (5 given)

Could you help me find out what is causing this error and how I can fix that addConstr() error? Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant