Skip to content

A second pySMT synthesis in the same process fails with SolverRedefinitionError #90

Closed

Description

@ondrik

Bug: in one Python process, every pySMT synthesis after the first fails, even with a new Synthesizer for each run:

pysmt.exceptions.SolverRedefinitionError: Solver opensmt already defined

Reproduction (master at 1af733c, src/ on the module path):

from synth import Synthesizer

for _ in range(2):
    Synthesizer().synthesis(qasm_file="benchmarks/ghz/2.qasm", vectors="all", solving="pysmt", solver="z3",
                            mode="incremental", complex_representation="FiveTuple")

The first call returns the Bell circuit and the second raises. Basic mode, or yices2 after z3, fail the same way.

Cause: on every pySMT synthesis, Synthesizer.add_solvers() registers opensmt, yices2, smtinterpol, cvc5 and dReal as generic solvers in pySMT's global environment (add_one_solver). This happens even when the synthesis uses z3, which pySMT has built in. pySMT keeps registrations for the whole process and refuses to register a name it already has.

How much it matters: only the Python API offers pySMT (-s has no pysmt), but notebooks, benchmark loops and test suites run several syntheses in one process. The docs' advice to create a new Synthesizer for every run doesn't help, because the state is pySMT's, not the Synthesizer's.

Fix: draft PR #55 already handles this: it reuses a registered solver when its command and logics are the same, and raises SolverConfigError otherwise. One thing to keep in mind when fixing #61, though:

Found while working on #89.

Activity

  1. added a commit that references this issue on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions