gradient_function.cpp 1.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/*******************************************************************************
 * Copyright (c) 2018-, UT-Battelle, LLC.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the BSD 3-Clause License 
 * which accompanies this distribution. 
 *
 * Contributors:
 *   Alexander J. McCaskey - initial API and implementation
 *   Thien Nguyen - implementation
 *******************************************************************************/
Nguyen, Thien Minh's avatar
Nguyen, Thien Minh committed
11
12
13
#include "gradient_function.hpp"
#include "xacc.hpp"
#include "xacc_service.hpp"
14
#include "qcor_utils.hpp"
15
#include "xacc_internal_compiler.hpp"
Nguyen, Thien Minh's avatar
Nguyen, Thien Minh committed
16
namespace qcor {
17
namespace __internal__ {
18
19
std::shared_ptr<GradientFunction>
get_gradient_method(const std::string &type,
20
21
                    std::shared_ptr<ObjectiveFunction> obj_func,
                    xacc::HeterogeneousMap options) {
22
23
24
  if (!xacc::isInitialized())
    xacc::internal_compiler::compiler_InitializeXACC();
  auto service = xacc::getService<KernelGradientService>(type);
25
  service->initialize(obj_func, std::move(options));
26
  return service;
Nguyen, Thien Minh's avatar
Nguyen, Thien Minh committed
27
}
28
29
30

std::shared_ptr<GradientFunction>
get_gradient_method(const std::string &type,
31
                    std::function<std::shared_ptr<CompositeInstruction>(
32
33
                        std::vector<double>)>
                        kernel_eval,
34
                    Operator &obs) {
35
36
37
38
39
40
  if (!xacc::isInitialized())
    xacc::internal_compiler::compiler_InitializeXACC();
  auto service = xacc::getService<KernelGradientService>(type);
  service->initialize(kernel_eval, obs);
  return service;
}
41
42
} // namespace __internal__
} // namespace qcor