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

Enable v3 MVP to be used from Python #169

Merged
merged 33 commits into from
Dec 5, 2023
Merged

Enable v3 MVP to be used from Python #169

merged 33 commits into from
Dec 5, 2023

Conversation

rturrado
Copy link
Contributor

@rturrado rturrado commented Nov 24, 2023

Renamed V1xAnalyzer::a member to V1xAnalyzer::analyzer. The same for v3.

Renamed python/module/cqasm/v1x/__init__.py Analyzer class to V1xAnalzyer. The same for v3.

python/libQasm.i now also includes v3x/cqasm-py.hpp.

test/v3x now has cpp and a python subdirectories. test/v1x also has a cpp subdirectory.

Added test/v3x/python/test_v3x_analyzer.py.

Removed pyproject.toml, and added pytest.ini.

Implemented src/v3x/cqasm.cpp default_analyzer.

cqasm-analyzer now has analyze_file and analyze_string methods (previously analyze and analyze_string).

@rturrado rturrado requested a review from pablolh November 24, 2023 17:48
We are trying to avoid including 'antlr4-runtime.h' from some header files that are being included at the same time that a conflicting Python header.
The conflicting Python header contains some defines, e.g., STRING, that 'antlr4-runtime.h' uses as enumeration values.
The build process substitutes those defines in the 'antlr4-runtime.h' code, resulting in many build errors.
We are trying to avoid including 'antlr4-runtime.h' from some header files that are being included at the same time that a conflicting Python header.
The conflicting Python header contains some defines, e.g., STRING, that 'antlr4-runtime.h' uses as enumeration values.
The build process substitutes those defines in the 'antlr4-runtime.h' code, resulting in many build errors.
src/v3x/cqasm-py.cpp Show resolved Hide resolved
src/v3x/cqasm.cpp Show resolved Hide resolved
test/v3x/python/test_v3x_analyzer.py Outdated Show resolved Hide resolved
We still have the same problem though as we have for the json_parser branch: AttributeError: module 'libQasm' has no attribute 'V3xAnalyzer'.
# Conflicts:
#	src/v3x/cqasm-py.cpp
With code: return ast.Program.deserialize(retval[0].encode("utf-8", errors="surrogateescape"))
We are now converting retval[0] to a string before encoding.
We also need to convert every error from a "libQasm string" to a "Python string" before returning.
The analyzer functions always return a vector of strings.
And, in this vector, the first string is reserved for the serialized AST.
The next strings are filled with error messages, if any.
To exercise the parse_string and analyze_string APIs.
Both when an AST or a list of errors is returned.
@rturrado rturrado requested a review from pablolh November 29, 2023 18:47
python/module/libQasm/__init__.py Outdated Show resolved Hide resolved
src/v1x/cqasm-py.cpp Show resolved Hide resolved
python/module/cqasm/v1x/__init__.py Show resolved Hide resolved
pablolh
pablolh previously approved these changes Dec 5, 2023
@rturrado rturrado merged commit 726ab59 into develop Dec 5, 2023
14 of 15 checks passed
@rturrado rturrado deleted the v3-mvp-python branch December 5, 2023 16:38
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

Successfully merging this pull request may close these issues.

2 participants