Commit 6398d23e authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

adding OptFunction to python api


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent db16933d
Pipeline #66412 passed with stage
in 6 minutes and 42 seconds
import xacc
def rosen(x):
return (1.-x[0])**2 + 100*(x[1]-x[0]**2)**2
optimizer = xacc.getOptimizer('nlopt', {'nlopt-maxeval':10000})
f = xacc.OptFunction(rosen, 2)
result = optimizer.optimize(f)
print(result)
\ No newline at end of file
......@@ -30,6 +30,7 @@
#include <pybind11/eigen.h>
#include <pybind11/iostream.h>
#include <pybind11/operators.h>
#include <pybind11/functional.h>
namespace py = pybind11;
using namespace xacc;
......@@ -428,6 +429,9 @@ PYBIND11_MODULE(_pyxacc, m) {
xacc::Algorithm::initialize,
"Initialize the algorithm with given AlgorithmParameters.");
py::class_<xacc::OptFunction> (m, "OptFunction", "")
.def(py::init<std::function<double(const std::vector<double> &)>,const int>());
// Expose Optimizer
py::class_<xacc::Optimizer, std::shared_ptr<xacc::Optimizer>>(
m, "Optimizer",
......
......@@ -31,7 +31,7 @@ TEST(XASMCompilerTester, checkSimple) {
}
TEST(XASMCompilerTester, checkApplyAll) {
auto compiler = xacc::getCompiler("xasm");
auto IR = compiler -> compile(R"([&](qbit q) {
range(q, {{"gate","H"},{"nqubits",4}});
......@@ -40,6 +40,10 @@ TEST(XASMCompilerTester, checkApplyAll) {
std::cout << "KERNEL\n" << IR->getKernels()[0]->toString() << "\n";
}
TEST(XASMCompilerTester, checkUnknownParameter) {
}
int main(int argc, char **argv) {
xacc::Initialize(argc, argv);
::testing::InitGoogleTest(&argc, argv);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment