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

Compiler conformance: Quantum declaration #219

Closed
wants to merge 5 commits into from
Closed

Compiler conformance: Quantum declaration #219

wants to merge 5 commits into from

Conversation

moar55
Copy link
Contributor

@moar55 moar55 commented Sep 11, 2021

This pull request conforms QASM3-MLIR conversions of quantum declarations with the latest QASM3 grammar. Relevant to #190

@moar55 moar55 closed this Sep 11, 2021
@moar55 moar55 reopened this Sep 11, 2021
auto mlir = qcor::mlir_compile(complex_if, "complex_if",
qcor::OutputType::MLIR, false);
std::cout << mlir << "\n";
// qcor::execute(complex_if, "complex_if");
Copy link
Contributor Author

@moar55 moar55 Sep 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commented line in quantum declaration test blows up memory because of the measurement assignment statement.
If the preceding testcase is commented this works. It could be gtest doesn't do a tear down after each test?

@moar55 moar55 changed the title Compiler conformance: Quantum declaration Compiler conformance#https://github.com/ORNL-QCI/qcor/issues/190: Quantum declaration Sep 11, 2021
@moar55 moar55 changed the title Compiler conformance#https://github.com/ORNL-QCI/qcor/issues/190: Quantum declaration Compiler conformance: Quantum declaration Sep 11, 2021
Copy link
Collaborator

@amccaskey amccaskey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary comments:

(1) we need to fix these diffs - a good number of the files have global changes to the whole file which makes it difficult to see what changed in the file. May need to reclone and copy changes in and re-PR.
(2) All changes to adhere to latest from upstream (at least in this case) should be additions and not modifications breaking backwards compatibility. Tests should not be updated to reflect the new syntax, but instead, you should add a new test to demonstrate and test the new syntax.

add_test(NAME qcor_qasm3_test_nisq_ifstmt COMMAND qasm3CompilerTester_nisq_ifstmt)
target_include_directories(qasm3CompilerTester_nisq_ifstmt PRIVATE . ../../ ${CMAKE_SOURCE_DIR}/tools/clang-wrapper/ ${CMAKE_SOURCE_DIR}/handlers ${XACC_ROOT}/include/gtest)
target_link_libraries(qasm3CompilerTester_nisq_ifstmt qcor-mlir-api gtest gtest_main qcor-clang-wrapper qcor-syntax-handler ${CLANG_LIBS})

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing a bunch of these diff files where you've deleted the entire file and replaced with new content. This makes it hard to see what you've changed. Can you try to fix this? You may need a fresh fork and copy just your changes into that fork, then issue a new PR.

Copy link
Contributor Author

@moar55 moar55 Sep 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why that happened but I will fix it in a new PR 👍

@@ -4,7 +4,7 @@
TEST(qasm3VisitorTester, checkAlias) {
const std::string alias_by_indicies = R"#(OPENQASM 3;
include "qelib1.inc";
qubit q[6];
qubit[6] q;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to note - I want this implementation to conform to the qasm3.g4 spec upstream, but we are free to keep existing, or introduce novel, syntax. So in this case, yes, we should update the parser to handle qubit[N] q, but we should make sure that the existing qubit q[N] also works for our own backwards compatibility.

@@ -486,7 +486,7 @@ include "qelib1.inc";
// phi_est = 11/16 (denom = 16 since we have 4 bits)
// => phi = 2pi * 11/16 = 11pi/8 = 2pi - 5pi/8
// i.e. we estimate the -5*pi/8 angle...
qubit q[2];
qubit[2] q;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going back to the comment below - instead of changing all occurrences of qubit declarations to be in the new syntax, I prefer you keep it all as is, and add a new test that shows the compiler can handle this new syntax. I'm really interested in conserving backwards compatibility with what we already have, while at the same time ensuring we are compatible with these latest changes from upstream.

@@ -1,485 +1,499 @@
#include "gtest/gtest.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another case of deleting the whole file and replacing with new contents, which has messed up the diff.

@moar55
Copy link
Contributor Author

moar55 commented Sep 14, 2021

Would such syntax be also valid:
qubit [4] q1, q2[3]
@amccaskey

@amccaskey
Copy link
Collaborator

Good question. My initial thought is no. You should be consistent in single line comma separated declarations. In the case you specify, I think qubit[4] implies a specific type (namely an array of 4 qubits) and that should be for all variables in the comma separated declaration.

@moar55
Copy link
Contributor Author

moar55 commented Sep 15, 2021

sounds good 👍
I also think allowing both kind of declarations for qreg would make the grammar and the implementation simpler. Given that we are not planning to adhere exactly to the openqasm 3 grammar.
So have both:
qreg[4] q0;
and
qreg q0[4];.
It is obvious why this would make the grammar simpler. Regarding the implementation I either have to make two visitors or have a single visitor with and std::variant identifier list vector(one variant for 'qubit' identifier list and the other for 'qreg' identifier list). The former approach fees like an overkill and the latter wouldn't be so clean. Atleast these are the implementations that I have in mind... What do you think? @amccaskey

@moar55 moar55 closed this Sep 20, 2021
@moar55 moar55 deleted the compiler_conformance branch October 25, 2021 15:15
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