dakk / qlasskit

A python-to-quantum compiler
https://dakk.github.io/qlasskit/
Apache License 2.0
56 stars 11 forks source link

Add py2bexp CLI tool to convert qlassf functions to boolean expressions #56

Closed tomv42 closed 3 months ago

tomv42 commented 3 months ago

Summary:

This pull request introduces the py2bexp command-line tool to the qlasskit package. The tool converts qlassf functions in a Python script to boolean expressions. It also includes initial tests for the functionality.

Changes:

  1. Added py2bexp.py to qlasskit/tools package:

    • Implements the conversion of qlassf functions to boolean expressions.
    • Supports reading from a file or stdin.
    • Allows specifying entrypoint function, output file, expression form, and output format.
    • Includes command-line arguments parsing with argparse.
  2. Updated setup.py:

    • Added py2bexp as a console script entry point for seamless installation and usage.
  3. Initial Tests in test_tools.py:

    • Included tests for help and version commands.
    • Added tests for default behavior, specific entrypoint, and different expression forms.
    • Verified DIMACS format output for CNF.
    • Note: Tests currently do not have assertions but printing results looks good.
      • I don't know what kind of assertion would be appropriate...

Related Issue:

This PR resolves issue #28

@dakk, I'm looking forward to your feedback.

dakk commented 3 months ago

Thank you, I will review tomorrow UTC; in the meanwhile, can you please take care of failing tests on CI?

Anyway, in tests you can assert the string you are printing 👍

tomv42 commented 3 months ago

Yes, I'm working on it.

tomv42 commented 3 months ago

I added satisfactory assertions to all the unit tests except one, by comparing the results against sympy expressions and testing that the form is the right one with sympy too.

This didn't work for anf where calling is_anf resulted in a type error. Which is weird because it didn't for the others.

For the DIMACS test, as the order of the symbols when converting to DIMACS is not guaranteed, and all the permutations of the names of the symbols give equivalent expressions, the test compares all the possible permutations of the 3 symbols.

dakk commented 3 months ago

@tomv42 with very few modification, you can also write the code for this: https://github.com/dakk/qlasskit/issues/26 , if you have time. You need to open a PR today, and then we have a week to review / request changes / edits.

tomv42 commented 3 months ago

@dakk I made the requested changes :)