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

Failure reading DIMACS files with 10 variables or more #185

Open
natanaeljr opened this issue Nov 23, 2023 · 0 comments
Open

Failure reading DIMACS files with 10 variables or more #185

natanaeljr opened this issue Nov 23, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@natanaeljr
Copy link

Describe the bug

Reading DIMACS files fails with files having more than 10 variables from CNF.

Reproducible example code

main.cpp:

#include <lorina/common.hpp>
#include <tweedledum/Synthesis/pkrm_synth.h>
#include <kitty/dynamic_truth_table.hpp>
#include <mockturtle/networks/xag.hpp>
#include <mockturtle/io/dimacs_reader.hpp>
#include <tweedledum/Utils/Classical/xag_simulate.h>
#include <lorina/dimacs.hpp>

using namespace tweedledum;

int main()
{
  mockturtle::xag_network xag;
  lorina::return_code ret = lorina::read_dimacs("graphE.cnf", mockturtle::dimacs_reader(xag));
  if (ret != lorina::return_code::success)
    return 1;
  std::vector<kitty::dynamic_truth_table> truth_tables = xag_simulate(xag);
  Circuit circuit = pkrm_synth(truth_tables[0]);
  return 0;
}

graphE.cnf:

p cnf 12 31
1 2 3 0
4 5 6 0
7 8 9 0
10 11 12 0
-1 -2 0
-1 -3 0
-2 -3 0
-4 -5 0
-4 -6 0
-5 -6 0
-7 -8 0
-7 -9 0
-8 -9 0
-10 -11 0
-10 -12 0
-11 -12 0
-1 -4 0
-2 -5 0
-3 -6 0
-1 -7 0
-2 -8 0
-3 -9 0
-10 -1 0
-2 -11 0
-3 -12 0
-4 -7 0
-5 -8 0
-6 -9 0
-4 -10 0
-5 -11 0
-6 -12 0

Expected behavior

The DIMACS file is successfully read and the circuit is synthetized.

Information

  • tweedledum version: v1.1.1
  • Python version: v1.1.1
  • C++ compiler: 13.2.1
  • Operating system: Arch Linux

Additional context

Suggested fix for this issue:

diff --git a/external/lorina/lorina/dimacs.hpp b/external/lorina/lorina/dimacs.hpp
index dc44b9a..e8bd60f 100644
--- a/external/lorina/lorina/dimacs.hpp
+++ b/external/lorina/lorina/dimacs.hpp
@@ -99,7 +99,7 @@ public:
 namespace dimacs_regex
 {
 static std::regex problem_spec( R"(^p\s+([cd]nf)\s+([0-9]+)\s+([0-9]+)$)" );
-static std::regex clause( R"(((-?[1-9]+)+ +)+0)" );
+static std::regex clause( R"(((-?[1-9][0-9]*)+ +)+0)" );
 
 } // namespace dimacs_regex
@natanaeljr natanaeljr added the bug Something isn't working label Nov 23, 2023
@natanaeljr natanaeljr changed the title Reading DIMACS files fails with files having more than 10 variables from CNF Failure reading DIMACS files with more than 10 variables Nov 23, 2023
@natanaeljr natanaeljr changed the title Failure reading DIMACS files with more than 10 variables Failure reading DIMACS files with 10 variables or more Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant