Skip to content

Commit d54ff3a

Browse files
committed
Support abc's dsec solver
1 parent 7bcb9df commit d54ff3a

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

Valaig/External.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
import Valaig.External.Basic
22
import Valaig.External.Ric3
3+
import Valaig.External.Abc

Valaig/External/Abc.lean

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Valaig.External.Basic
2+
3+
namespace Valaig.External
4+
5+
def Abc.dsec (timeoutMs : Option Nat := none) : SafetyAigerMC :=
6+
{
7+
timeoutMs,
8+
supportsAag := false,
9+
interpretOutput,
10+
safetyArgs,
11+
}
12+
where
13+
safetyArgs (problem : System.FilePath) : IO.Process.SpawnArgs :=
14+
let cmd := "abc"
15+
let cmdStr := s!"read {problem.toString}; "
16+
let args := #["-c", cmdStr]
17+
{ cmd, args }
18+
19+
interpretOutput (out : IO.Process.Output) : EResult := do
20+
if out.stdout.contains "Networks are equivalent." then
21+
return Result.proof
22+
else
23+
return Result.counterexample
24+
25+
end Valaig.External

Valaig/External/Basic.lean

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ open Valaig.Aig
88

99
structure ExternalMC where
1010
timeoutMs : Option Nat := none
11+
supportsAag : Bool := true
1112
interpretOutput (output : IO.Process.Output) : EResult
1213

1314
structure SafetyAigerMC extends ExternalMC where
@@ -71,9 +72,15 @@ def checkSafety (config : SafetyAigerMC) (aig : Aiger) : IO EResult := do
7172
IO.FS.withTempDir fun dir => do
7273
-- Some solvers need the extension to be aag to work correctly so we create
7374
-- such a file rather than just using withTempFile
74-
let path := dir / "model.aag"
75-
IO.FS.withFile path .write fun handle => do
75+
let aagPath := dir / "model.aag"
76+
let aigPath := dir / "model.aig"
77+
IO.FS.withFile aagPath .write fun handle => do
7678
aig.writeAag <| IO.FS.Stream.ofHandle handle
79+
80+
if ¬config.supportsAag then
81+
let _ ← runProcess none { cmd := "aigtoaig", args := #[aagPath.toString, aigPath.toString] }
82+
83+
let path := if config.supportsAag then aagPath else aigPath
7784
let out ← runProcess config.timeoutMs (config.safetyArgs path)
7885
return out >>= config.interpretOutput
7986

0 commit comments

Comments
 (0)