Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ORNL Quantum Computing Institute
qcor
Commits
2de70efd
Commit
2de70efd
authored
Jun 16, 2021
by
Mccaskey, Alex
Browse files
commit fix to seg fault issue
Signed-off-by:
Alex McCaskey
<
mccaskeyaj@ornl.gov
>
parent
3b576034
Changes
6
Hide whitespace changes
Inline
Side-by-side
examples/CMakeLists.txt
View file @
2de70efd
...
...
@@ -53,10 +53,10 @@ add_qcor_compile_and_exe_test(quasimo_vqe quasimo/VqeWithAnsatzCircuit.cpp)
add_qcor_compile_and_exe_test
(
quasimo_trotter quasimo/TrotterTdWorkflow.cpp
)
add_qcor_compile_and_exe_test
(
quasimo_iqpe_vqe quasimo/IterativeQpeVqe.cpp
)
add_qcor_compile_and_exe_test
(
quasimo_adapt_vqe quasimo/AdaptVqeWorkflow.cpp
)
add_qcor_compile_and_exe_test
(
quasimo_qaoa quasimo/QaoaWorkflow.cpp
)
#
add_qcor_compile_and_exe_test(quasimo_qaoa quasimo/QaoaWorkflow.cpp)
add_qcor_compile_and_exe_test
(
quasimo_qite quasimo/QiteWorkflow.cpp
)
add_qcor_compile_and_exe_test
(
quasimo_heisenberg quasimo/TdWorkflowHeisenbergModel.cpp
)
add_qcor_compile_and_exe_test
(
quasimo_verified_qpe quasimo/VerifiedQuantumPhaseEstimation.cpp
)
#
add_qcor_compile_and_exe_test(quasimo_verified_qpe quasimo/VerifiedQuantumPhaseEstimation.cpp)
add_qcor_compile_and_exe_test
(
hadamard_ctrl_test ctrl-gates/simple_hadamard_test.cpp
)
add_qcor_compile_and_exe_test
(
multi_ctrl_test ctrl-gates/multiple_controls.cpp
)
...
...
@@ -73,6 +73,7 @@ add_qcor_compile_and_exe_test(qrt_qpu_lambdas_in_loop qpu_lambda/deuteron_lambda
add_qcor_compile_and_exe_test
(
qrt_qpu_lambda_deuteron qpu_lambda/deuteron_vqe.cpp
)
add_qcor_compile_and_exe_test
(
qrt_qpu_lambda_objfunc qpu_lambda/deuteron_vqe_obj_func.cpp
)
add_qcor_compile_and_exe_test
(
qrt_qpu_lambda_hadamard_test ctrl-gates/hadamard_test.cpp
)
add_qcor_compile_and_exe_test
(
qrt_qpu_lambda_compute_action qpu_lambda/lambda_with_compute_action.cpp
)
# Arithmetic tests
add_qcor_compile_and_exe_test
(
qrt_qpu_arith_adder arithmetic/simple.cpp
)
...
...
examples/qpu_lambda/lambda_with_compute_action.cpp
0 → 100644
View file @
2de70efd
#include
"qcor.hpp"
int
main
()
{
auto
ansatz
=
qpu_lambda
([](
qreg
q
,
double
theta
)
{
X
(
q
[
0
]);
X
(
q
[
2
]);
compute
{
Rx
(
q
[
0
],
constants
::
pi
/
2
);
for
(
auto
i
:
range
(
3
))
H
(
q
[
i
+
1
]);
for
(
auto
i
:
range
(
3
))
{
CX
(
q
[
i
],
q
[
i
+
1
]);
}
}
action
{
Rz
(
q
[
3
],
theta
);
}
});
std
::
string
s
=
R"#((0.0454063,0) 2^ 0^ 1 3 + (0.0454063,0) 1^ 2^ 3 0 + (0.168336,0) 2^ 0^ 0 2 + (0.1202,0) 1^ 0^ 0 1 + (0.174073,0) 1^ 3^ 3 1 + (-0.174073,-0) 1^ 3^ 1 3 + (-0.0454063,-0) 3^ 0^ 2 1 + (-0.0454063,-0) 2^ 0^ 3 1 + (-0.0454063,-0) 1^ 2^ 0 3 + (-0.168336,-0) 2^ 0^ 2 0 + (-0.1202,-0) 2^ 3^ 2 3 + (-0.0454063,-0) 3^ 1^ 2 0 + (-0.165607,-0) 1^ 2^ 1 2 + (0.165607,0) 0^ 3^ 3 0 + (-0.1202,-0) 0^ 1^ 0 1 + (0.0454063,0) 3^ 1^ 0 2 + (0.165607,0) 1^ 2^ 2 1 + (0.165607,0) 2^ 1^ 1 2 + (0.0454063,0) 1^ 3^ 2 0 + (-0.0454063,-0) 0^ 3^ 1 2 + (-0.1202,-0) 3^ 2^ 3 2 + (-0.0454063,-0) 2^ 1^ 3 0 + (-0.174073,-0) 3^ 1^ 3 1 + (0.1202,0) 2^ 3^ 3 2 + (0.0454063,0) 3^ 0^ 1 2 + (-0.165607,-0) 3^ 0^ 3 0 + (0.165607,0) 3^ 0^ 0 3 + (0.174073,0) 3^ 1^ 1 3 + (0.1202,0) 3^ 2^ 2 3 + (0.0454063,0) 0^ 2^ 3 1 + (0.168336,0) 0^ 2^ 2 0 + (0.1202,0) 0^ 1^ 1 0 + (-0.0454063,-0) 0^ 2^ 1 3 + (-0.165607,-0) 2^ 1^ 2 1 + (-0.165607,-0) 0^ 3^ 0 3 + (-0.1202,-0) 1^ 0^ 1 0 + (-0.168336,-0) 0^ 2^ 0 2 + (0.0454063,0) 2^ 1^ 0 3 + (-0.479678,-0) 3^ 3 + (-1.24885,-0) 0^ 0 + (-0.479678,-0) 1^ 1 + (0.708024,0) + (0.0454063,0) 0^ 3^ 2 1 + (-0.0454063,-0) 1^ 3^ 0 2 + (-1.24885,-0) 2^ 2)#"
;
auto
H
=
createOperator
(
"fermion"
,
s
);
auto
q
=
qalloc
(
4
);
auto
objective
=
createObjectiveFunction
(
ansatz
,
H
,
q
,
1
);
auto
optimizer
=
createOptimizer
(
"nlopt"
,
{{
"maxeval"
,
20
}});
// Optimize the above function
auto
[
optval
,
opt_params
]
=
optimizer
->
optimize
(
*
objective
.
get
());
// Print the result
printf
(
"energy = %f
\n
"
,
optval
);
}
\ No newline at end of file
runtime/jit/qcor_jit.in.cpp
View file @
2de70efd
...
...
@@ -510,7 +510,7 @@ void QJIT::jit_compile(const std::string &code,
// Add dependency before JIT compile:
new_code
=
dependencyCode
+
new_code
;
std
::
cout
<<
"New code:
\n
"
<<
new_code
<<
"
\n
"
;
//
std::cout << "New code:\n" << new_code << "\n";
// Hash the new code
std
::
hash
<
std
::
string
>
hasher
;
auto
hash
=
hasher
(
new_code
);
...
...
@@ -524,7 +524,6 @@ void QJIT::jit_compile(const std::string &code,
auto
module_bitcode_file_name
=
cached_kernel_codes
[
hash
];
std
::
string
full_path
=
qjit_cache_path
+
"/"
+
module_bitcode_file_name
;
std
::
cout
<<
"REUSING QJIT CACHED MODULE
\n
"
;
// Load the bitcode file as Module
SMDiagnostic
error
;
auto
ctx
=
std
::
make_unique
<
LLVMContext
>
();
...
...
@@ -672,7 +671,6 @@ void QJIT::jit_compile(const std::string &code,
// Get and store the kernel_name(CompositeInstruction parent, Args...) function
auto
parent_symbol
=
cantFail
(
jit
->
lookup
(
parent_mangled_name
));
auto
parent_rawFPtr
=
parent_symbol
.
getAddress
();
std
::
cout
<<
"INSERTING "
<<
kernel_name
<<
", "
<<
parent_mangled_name
<<
"
\n
"
;
kernel_name_to_f_ptr_with_parent
.
insert
({
kernel_name
,
parent_rawFPtr
});
for
(
const
auto
&
[
orig_name
,
mangled_name
]
:
mangled_kernel_dep_map
)
{
...
...
runtime/kernel/quantum_kernel.hpp
View file @
2de70efd
...
...
@@ -266,7 +266,7 @@ class QuantumKernel {
static
std
::
string
openqasm
(
Args
...
args
)
{
Derived
derived
(
args
...);
KernelSignature
<
Args
...
>
callable
(
derived
);
return
internal
::
openqasm
(
callable
,
args
...);
return
internal
::
openqasm
<
Args
...
>
(
callable
,
args
...);
}
virtual
~
QuantumKernel
()
{}
...
...
@@ -665,14 +665,14 @@ class _qpu_lambda {
template
<
typename
...
FunctionArgs
>
double
observe
(
Observable
&
obs
,
FunctionArgs
...
args
)
{
KernelSignature
<
FunctionArgs
...
>
callable
(
*
this
);
return
internal
::
observe
(
obs
,
callable
,
args
...);
return
internal
::
observe
<
FunctionArgs
...
>
(
obs
,
callable
,
args
...);
}
template
<
typename
...
FunctionArgs
>
void
ctrl
(
std
::
shared_ptr
<
CompositeInstruction
>
ir
,
const
std
::
vector
<
qubit
>
&
ctrl_qbits
,
FunctionArgs
...
args
)
{
KernelSignature
<
FunctionArgs
...
>
callable
(
*
this
);
internal
::
apply_control
(
ir
,
ctrl_qbits
,
callable
,
args
...);
internal
::
apply_control
<
FunctionArgs
...
>
(
ir
,
ctrl_qbits
,
callable
,
args
...);
}
template
<
typename
...
FunctionArgs
>
...
...
@@ -712,7 +712,7 @@ class _qpu_lambda {
void
adjoint
(
std
::
shared_ptr
<
CompositeInstruction
>
parent_kernel
,
FunctionArgs
...
args
)
{
KernelSignature
<
FunctionArgs
...
>
callable
(
*
this
);
return
internal
::
apply_adjoint
(
parent_kernel
,
callable
,
args
...);
return
internal
::
apply_adjoint
<
FunctionArgs
...
>
(
parent_kernel
,
callable
,
args
...);
}
template
<
typename
...
FunctionArgs
>
...
...
@@ -729,19 +729,19 @@ class _qpu_lambda {
template
<
typename
...
FunctionArgs
>
std
::
size_t
n_instructions
(
FunctionArgs
...
args
)
{
KernelSignature
<
FunctionArgs
...
>
callable
(
*
this
);
return
internal
::
n_instructions
(
callable
,
args
...);
return
internal
::
n_instructions
<
FunctionArgs
...
>
(
callable
,
args
...);
}
template
<
typename
...
FunctionArgs
>
Eigen
::
MatrixXcd
as_unitary_matrix
(
FunctionArgs
...
args
)
{
KernelSignature
<
FunctionArgs
...
>
callable
(
*
this
);
return
internal
::
as_unitary_matrix
(
callable
,
args
...);
return
internal
::
as_unitary_matrix
<
FunctionArgs
...
>
(
callable
,
args
...);
}
template
<
typename
...
FunctionArgs
>
std
::
string
openqasm
(
FunctionArgs
...
args
)
{
KernelSignature
<
FunctionArgs
...
>
callable
(
*
this
);
return
internal
::
openqasm
(
callable
,
args
...);
return
internal
::
openqasm
<
FunctionArgs
...
>
(
callable
,
args
...);
}
};
...
...
@@ -813,7 +813,7 @@ class KernelSignature {
void
ctrl
(
std
::
shared_ptr
<
xacc
::
CompositeInstruction
>
ir
,
const
std
::
vector
<
qubit
>
&
ctrl_qbits
,
Args
...
args
)
{
internal
::
apply_control
(
ir
,
ctrl_qbits
,
*
this
,
args
...);
internal
::
apply_control
<
Args
...
>
(
ir
,
ctrl_qbits
,
*
this
,
args
...);
}
void
ctrl
(
std
::
shared_ptr
<
xacc
::
CompositeInstruction
>
ir
,
...
...
runtime/objectives/objective_function.hpp
View file @
2de70efd
...
...
@@ -360,6 +360,7 @@ public:
dx
=
(
*
gradiend_method
)(
x
,
cost_val
);
}
kernel
->
clear
();
return
cost_val
;
}
...
...
runtime/qrt/impls/nisq/nisq_qrt.cpp
View file @
2de70efd
...
...
@@ -78,19 +78,6 @@ class NISQ : public ::quantum::QuantumRuntime,
}
public:
// AJM DEBUGGING
// virtual ~NISQ() override {
// std::cout << "DESTROYING NISQ\n";
// if (program) std::cout << program->name();
// std::cout << ", " << program.use_count() << "\n";
// }
// NISQ() = default;
// NISQ(const NISQ& n) : program(n.program), provider(n.provider), mark_as_compute(n.mark_as_compute) {
// }
std
::
shared_ptr
<::
quantum
::
QuantumRuntime
>
clone
()
override
{
return
std
::
make_shared
<
NISQ
>
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment