qir-alliance / qcor Goto Github PK
View Code? Open in Web Editor NEWC++ compiler for heterogeneous quantum-classical computing built on Clang and XACC
Home Page: http://docs.aide-qc.org
License: MIT License
C++ compiler for heterogeneous quantum-classical computing built on Clang and XACC
Home Page: http://docs.aide-qc.org
License: MIT License
(gdb) bt
#0 0x00007ffff6907a08 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#1 0x00007ffff6908d53 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#2 0x00007ffff690974d in _Unwind_Find_FDE () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#3 0x00007ffff6905848 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#4 0x00007ffff6906a10 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#5 0x00007ffff6906f89 in _Unwind_RaiseException () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#6 0x00007ffff69bb78c in __cxa_throw () from /lib/x86_64-linux-gnu/libstdc++.so.6
#7 0x00007ffff4458eb3 in pyxasm::pyxasmParser::expr_stmt (this=0x7fffffff8cb0) at ../handlers/token_collector/pyxasm/generated/pyxasmParser.cpp:2272
#8 0x00007ffff445819f in pyxasm::pyxasmParser::small_stmt (this=0x7fffffff8cb0) at ../handlers/token_collector/pyxasm/generated/pyxasmParser.cpp:2017
#9 0x00007ffff445788c in pyxasm::pyxasmParser::simple_stmt (this=0x7fffffff8cb0) at ../handlers/token_collector/pyxasm/generated/pyxasmParser.cpp:1888
#10 0x00007ffff444f1f8 in pyxasm::pyxasmParser::single_input (this=0x7fffffff8cb0) at ../handlers/token_collector/pyxasm/generated/pyxasmParser.cpp:128
#11 0x00007ffff44b9b99 in qcor::PyXasmTokenCollector::collect (this=0x7fffe806dd70, PP=..., Toks=..., bufferNames=std::vector of length 1, capacity 1 = {...}, ss=...)
at ../handlers/token_collector/pyxasm/pyxasm_token_collector.cpp:188
#12 0x00007fffe1e44d10 in qcor::run_token_collector (PP=..., Toks=..., bufferNames=std::vector of length 1, capacity 1 = {...}) at ../handlers/token_collector/token_collector_util.cpp:198
#13 0x00007fffe5652a1e in qcor::QCORSyntaxHandler::GetReplacement (this=0x7fffffffa040, PP=..., kernel_name="ansatz", program_arg_types=std::vector of length 2, capacity 2 = {...},
program_parameters=std::vector of length 2, capacity 2 = {...}, bufferNames=std::vector of length 1, capacity 1 = {...}, Toks=..., OS=..., add_het_map_ctor=true)
at ../handlers/qcor_syntax_handler.cpp:85
#14 0x00007fffe682e219 in qcor::QJIT::run_syntax_handler (this=0x1e6fed0,
kernel_src="__qpu__ void ansatz(qreg q,double theta) {\nusing qcor::pyxasm;\n\n", ' ' <repeats 12 times>, "X(q[0])\n", ' ' <repeats 12 times>, "Ry(q[1], theta)\n", ' ' <repeats 12 times>, "CX(q[1], q[0])\n}\n", add_het_map_kernel_ctor=true) at runtime/jit/qcor_jit.cpp:218
The following causes an assertion to be triggered
@qjit
def oracle(q : qreg):
"""
Define the oracle for our phase estimation algorithm,
a T gate on the last qubit
"""
... oracle code ...
but this does not
@qjit
def oracle(q : qreg):
... oracle code ...
make it easier to say PYTHONPATH=$(qcor -pythonpath) ( may consist of both qcor and xacc install paths )
but not when running that test individually by itself.
__qpu__ void hwe(qreg q, std::vector<double> x, const int layers,
std::vector<std::pair<int,int>> cnot_coupling) {
assert(x.size() == layers*q.size()*5);
...
}
we should try to support asserts like the above in quantum kernels. right now this is a compile error
<built-in>:21:154: error: use of undeclared identifier 'extension__'
( static_cast < bool > ( x . size ( ) == layers * q . size ( ) * 5 ) ? void ( 0 ) : assert_fail ( "x.size() == layers*q.size()*5" , "hwe_test.cpp" , 3 , extension__ PRETTY_FUNCTION__ ) ) ;
We should add a api call that lets users specific backend info like shots, backend, etc.
I followed the instructions for installation and got the error below:
ld: library not found for -lqir-qrt
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
None
1
Create internal runtime functions that make it easier on us to map XACC IR to LLVM IR qrt calls. We should have a kernel preamble function call, a simplified function for creating qrt calls, and a end submission call.
I'm seeing the following results for compiling examples/unitary/ccnot.cpp with opt = 1
{
"AcceleratorBuffer": {
"name": "qreg_DCnZQHYUmN",
"size": 3,
"Information": {},
"Measurements": {
"000": 10,
"001": 142,
"010": 166,
"011": 179,
"100": 175,
"101": 46,
"110": 205,
"111": 101
}
}
}
and the correct result without optimization
{
"AcceleratorBuffer": {
"name": "qreg_goULRASYIr",
"size": 3,
"Information": {},
"Measurements": {
"011": 1024
}
}
}
I tried all the level 1 passes individually to see what was causing the error, only thing that caused the incorrect results was single-qubit-merge.
@tnguyen-ornl
We need to update the clang code-gen tool to add necessary mac os x compiler headers.
Must figure out how to do this in a syntactically efficient manner, that can be used in C or C++
qcor-driver on mac os x does not work currently.
Ability to pass literals to kernels:
e.g. __qpu__ void myKernel(qreg q, int varName)
, we should be able to call myKernel(q, 0)
(passes 0
to varName
).
Currently, we need to assign literal to a local variable before passing it to the function argument.
Ability to assign classical function return values to local classical variables.
e.g.
std::vector<double> myLocalArray = someFunc(...); // someFunc is strictly classical
Currently, this is not available/not reliable.
We can work around this by modifying the function signature to take the local variable by reference and update it rather than returning a value.
__qpu__ void myKernel(qreg q, int switchVar) {
if (switchVar != 0) {
// Do something, e.g. add gates
}
}
Maybe related to the above, early return should also be nice.
e.g.
__qpu__ void myKernel(qreg q, int switchVar) {
if (swicthVar == 0) {
return;
}
// Gates when switchVar != 0
}
In Python, we should enable it so that one can extract the unitary matrix representation of an evaluated quantum kernel
@qjit
def ansatz(q : qreg, theta : float):
...
u_mat = ansatz.as_unitary_matrix(q, 2.2)
Similarly, in C++
auto u_mat = ansatx::as_unitary_matrix(q,2.2);
To do this, we could start by porting the https://github.com/eclipse/xacc/blob/master/quantum/plugins/algorithms/gradient_strategies/autodiff/Autodiff.cpp visitor implementation to qcor_utils
We need to hook up the ability to use controlled versions of defined qjit kernels (and adjoint, print, etc).
for a simple test problem, I am noticing on the Mojave CI that qcor compile times are much slower than on Linux with brew or apt-get.
@tnguyen-ornl will you look into this separately on your Mojave install?
We need to develop a standard library for qcor that is automatically installed when qcor is installed.
Rz(q[(i], x[rz_xidx]);
this did not throw an error and just did not put the quantum::rz() function in the rewritten src.
We want to take something like
for (int i = 0; i < n; i++) {
H(q[i]);
}
to
for (int i = 0; i < 1; i++) {
H(q[0]);
H(q[1]);
H(q[2]);
...
H(q[n-1]);
}
when we know at compile time what n is.
Look into LoopInfoWrapperPass
Rigetti QCS has moved to a access model whereby you have a JupyterLab IDE, no more VM with sudo access.
The VM is not bad, 32gb RAM and 8 cores, Ubuntu 20.04.
You cannot run the aide-qc install script as is, it requires sudo.
You can clone deploy and dpkg -x xacc .
to install locally. Problem is that the qcor executable has hard-coded paths.
When I try to just in time compile a kernel with name 't' (any function body content), I get a weird symbol not found error coming out of the jit code
def t(q : qreg):
H(q[0])
CNOT(q[0], q[1])
CNOT(q[1], q[2])
Measure(q[0])
Measure(q[1])
Measure(q[2])
Failure value returned from cantFail wrapped call
Symbols not found: [ __cxx_global_var_init ]
UNREACHABLE executed at /usr/local/aideqc/llvm/include/llvm/Support/Error.h:749!
Aborted (core dumped)
(gdb) bt
#0 0x00007ffff6907a08 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#1 0x00007ffff6908d53 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#2 0x00007ffff690974d in _Unwind_Find_FDE () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#3 0x00007ffff6905848 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#4 0x00007ffff6906a10 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#5 0x00007ffff6906f89 in _Unwind_RaiseException () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#6 0x00007ffff69bb78c in __cxa_throw () from /lib/x86_64-linux-gnu/libstdc++.so.6
#7 0x00007ffff4458eb3 in pyxasm::pyxasmParser::expr_stmt (this=0x7fffffff8cb0) at ../handlers/token_collector/pyxasm/generated/pyxasmParser.cpp:2272
#8 0x00007ffff445819f in pyxasm::pyxasmParser::small_stmt (this=0x7fffffff8cb0) at ../handlers/token_collector/pyxasm/generated/pyxasmParser.cpp:2017
#9 0x00007ffff445788c in pyxasm::pyxasmParser::simple_stmt (this=0x7fffffff8cb0) at ../handlers/token_collector/pyxasm/generated/pyxasmParser.cpp:1888
#10 0x00007ffff444f1f8 in pyxasm::pyxasmParser::single_input (this=0x7fffffff8cb0) at ../handlers/token_collector/pyxasm/generated/pyxasmParser.cpp:128
#11 0x00007ffff44b9b99 in qcor::PyXasmTokenCollector::collect (this=0x7fffe806dd70, PP=..., Toks=..., bufferNames=std::vector of length 1, capacity 1 = {...}, ss=...)
at ../handlers/token_collector/pyxasm/pyxasm_token_collector.cpp:188
#12 0x00007fffe1e44d10 in qcor::run_token_collector (PP=..., Toks=..., bufferNames=std::vector of length 1, capacity 1 = {...}) at ../handlers/token_collector/token_collector_util.cpp:198
#13 0x00007fffe5652a1e in qcor::QCORSyntaxHandler::GetReplacement (this=0x7fffffffa040, PP=..., kernel_name="ansatz", program_arg_types=std::vector of length 2, capacity 2 = {...},
program_parameters=std::vector of length 2, capacity 2 = {...}, bufferNames=std::vector of length 1, capacity 1 = {...}, Toks=..., OS=..., add_het_map_ctor=true)
at ../handlers/qcor_syntax_handler.cpp:85
#14 0x00007fffe682e219 in qcor::QJIT::run_syntax_handler (this=0x1e6fed0,
kernel_src="__qpu__ void ansatz(qreg q,double theta) {\nusing qcor::pyxasm;\n\n", ' ' <repeats 12 times>, "X(q[0])\n", ' ' <repeats 12 times>, "Ry(q[1], theta)\n", ' ' <repeats 12 times>, "CX(q[1], q[0])\n}\n", add_het_map_kernel_ctor=true) at runtime/jit/qcor_jit.cpp:218
We should hook up the qcor executable to provide a --credentials or something like that would take the name of the accelerator, and any other info to write the appropriate .*_config file.
qcor --set-credentials ibm --hub ibm-q-ornl --group ornl --project PROJECT
There should also be an --update-credentials to change some of this info.
Just like we have set_qpu
we should also have setters for python for optimization and placement.
qcor -append-default-include-path /my/custom/path/to/always/include
qcor -print-default-include-paths
qcor -clear-default-include-paths
For IR Passes, we really want to flatten entry level quantum kernels (those whose parent or caller is regular function / not quantum / something like main()). This will make it easier on us to figure out the flattened qasm qrt calls and map to XACC IR. This flattening can be accomplished via function inlining. This link seems to suggest that clang will automatically accomplish this for functions annotated with __attribute__((always_inline))
https://lists.llvm.org/pipermail/llvm-dev/2018-May/123425.html.
We should be able to add this attribute to non-entry kernels in the token_collector_util.cpp file
.
Thinking out loud - need to provide documentation and mechanism for advanced users to leverage QuantumKernel<Derived,Args...>.
We should implement the adapt vqe workflow as a QuantumSimulationWorkflow.
We should provide a way to build quantum kernels programmatically (similar to other packages circuit types).
This should be a high-level wrapper around either the QJIT work or the xacc IRProvider.
It should alternately allow a user to provide a unitary matrix and delegate to a desired circuit synthesis strategy.
It should be treated just like a standard quantum kernel function, exposing some kind of call operation.
You should be able to declaratively provide kernel arguments or variables.
things like getObservable should be createObservable
Steps to reproduce:
qcor/examples/qrt
folder.qcor -o deuteron_qpp -qpu qpp deuteron_task_initiate.cpp
deuteron_qpp
executable.qcor -o deuteron_qpp -qpu qpp deuteron_task_initiate.cpp
deuteron_task_initiate.cpp:1:10: fatal error: 'qcor.hpp' file not found
#include "qcor.hpp"
^~~~~~~~~~
1 error generated.
None
1
We need to delete the file deuteron_qpp
to get it to work again.
Need to update PyObjectiveFunction to support gradients by creating the kernel_evaluator functor and passing to the helper ObjectiveFunction
We can add metadata to the llvm ir printout with this class. Think about using it to maybe add xacc ir toString to a qrt call.
We need to setup the vqe objective to default to autodiff when gradient strategy is not provided. May need some update to autodiff, in that it looks for CompositeInstruction variables, and those are not set on the qcor composite instruction.
Add a .readme to give high level overview of each subdirectory of qcor/examples/
.
if we install with apt-get, then the install directory will be /usr/local/xacc, which will have root permissions, and anyone using python or qjit will not be able to cache or read llvm module bitcode files. Need to update qjit to cache to the home directory.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.