Pass ancilla buffer to XACC even if user passes multiple qregs#259
Open
ausbin wants to merge 1 commit intoqir-alliance:masterfrom
Open
Pass ancilla buffer to XACC even if user passes multiple qregs#259ausbin wants to merge 1 commit intoqir-alliance:masterfrom
ausbin wants to merge 1 commit intoqir-alliance:masterfrom
Conversation
This is an attempt to address the Quantum++ backend receiving
out-of-range qubit indices in some cases. For example, due to using a
different code path, this code works (thanks to Akihiro for both
examples):
#include <qcor_arithmetic>
__qpu__ void CUa(qreg x, int a, int N) {
// c = |1>
qreg c = qalloc(1);
X(c[0]);
// x = |3>
X(x[0]);
X(x[1]);
mul_integer_mod_in_place::ctrl(c, x, a, N);
Measure(x);
}
int main() {
set_verbose(true);
int a = 1;
int N = 2;
set_shots(2);
auto x = qalloc(2);
CUa(x, a, N);
x.print();
}
Yet this code throws a runtime error:
#include <qcor_arithmetic>
__qpu__ void CUa(qreg x, qreg c, int a, int N) {
// c = |1>
X(c[0]);
// x = |3>
X(x[0]);
X(x[1]);
mul_integer_mod_in_place::ctrl(c, x, a, N);
Measure(x);
}
int main() {
set_verbose(true);
int a = 1;
int N = 2;
set_shots(2);
auto x = qalloc(2);
auto c = qalloc(1);
CUa(x, c, a, N);
x.print();
}
Specifically, the error was:
terminate called after throwing an instance of 'qpp::exception::MatrixMismatchSubsys'
what(): In qpp::apply(): Matrix mismatch subsystems!
Or with XACC built with debug mode, the following assertion is tripped
beforehand:
.../xacc/quantum/plugins/qpp/accelerator/QppVisitor.cpp:96: qpp::idx xacc::quantum::QppVisitor::xaccIdxToQppIdx(size_t) const: Assertion `in_idx < m_buffer->size()' failed.
With this change, this issue no longer occurs because the ancilla buffer
is passed for xacc::internal_compiler::execute(). Before,
xacc::internal_compiler::execute() noticed that some instructions were
referencing an AcceleratorBuffer `aux_temp_buffer` not in the list of
buffers passed to it and tried to recreate one, but that apparently
failed to prevent some misbehavior in this case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is an attempt to address the Quantum++ backend receiving out-of-range qubit indices in some cases. For example, due to using a different code path, this code works (thanks to Akihiro for both examples):
Yet this code throws a runtime error:
Specifically, the error was:
Or with XACC built with debug mode, the following assertion is tripped beforehand:
With this change, this issue no longer occurs because the ancilla buffer is passed for
xacc::internal_compiler::execute(). Before,xacc::internal_compiler::execute()noticed that some instructions were referencing an AcceleratorBufferaux_temp_buffernot in the list of buffers passed to it and tried to recreate one, but that apparently failed to prevent some misbehavior in this case.Testing
Ran those two examples above, both of which worked. Also ran the unit tests via
ctest, and no new tests failed compared to master