qcor.hpp 2.84 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
 *******************************************************************************/
11
#pragma once
Mccaskey, Alex's avatar
Mccaskey, Alex committed
12

13
#include "qcor_lang_ext.hpp"
14

Mccaskey, Alex's avatar
Mccaskey, Alex committed
15
16
namespace qcor {

17
namespace __internal__ {
18
19
20
21
22
23
24
25
// This class gives us a way to
// run some startup routine before
// main(). Specifically we use it to ensure that
// the accelerator backend is set in the event no
// quantum kernels are found by the syntax handler.
class internal_startup {
public:
  internal_startup() {
26
27
28
#ifdef __internal__qcor__compile__plugin__path
  qcor::__internal__::append_plugin_path(__internal__qcor__compile__plugin__path);
#endif
29
30
// IMPORTANT: This needs to be set before quantum::initialize
#ifdef __internal__qcor__compile__qrt__mode
31
    quantum::set_qrt(__internal__qcor__compile__qrt__mode);
32
#endif
33
34
#ifdef __internal__qcor__compile__backend
    quantum::initialize(__internal__qcor__compile__backend, "empty");
35
#endif
36
37
38
#ifdef __internal__qcor__compile__shots
    quantum::set_shots(std::stoi(__internal__qcor__compile__shots));
#endif
39
#ifdef __internal__qcor__compile__opt__level
40
41
42
43
44
    xacc::internal_compiler::__opt_level =
        __internal__qcor__compile__opt__level;
#endif
#ifdef __internal__qcor__compile__opt__print__stats
    xacc::internal_compiler::__print_opt_stats = true;
45
46
#endif
#ifdef __internal__qcor__compile__opt__passes
47
48
    xacc::internal_compiler::__user_opt_passes =
        __internal__qcor__compile__opt__passes;
49
50
#endif
#ifdef __internal__qcor__compile__placement__name
51
52
    xacc::internal_compiler::__placement_name =
        __internal__qcor__compile__placement__name;
53
54
#endif
#ifdef __internal__qcor__compile__qubit__map
55
56
57
    xacc::internal_compiler::__qubit_map =
        xacc::internal_compiler::parse_qubit_map(
            __internal__qcor__compile__qubit__map);
58
59
60
#endif
#ifdef __internal__qcor__compile__decorator__list
  xacc::internal_compiler::apply_decorators(__internal__qcor__compile__decorator__list);
61
#endif
62
63
#ifdef __internal__qcor__print__final__submission
    xacc::internal_compiler::__print_final_submission = true;
64
65
66
#endif
#ifdef __internal__qcor__validate__execution
    xacc::internal_compiler::__validate_nisq_execution = true;
67
68
69
#endif
#ifdef __internal__qcor__autograd__method
    xacc::internal_compiler::set_autograd_method(__internal__qcor__autograd__method);
70
#endif
71
72
73
74
  }
};
internal_startup startup;

75
76
77
} // namespace __internal__

} // namespace qcor
78
79

#define qcor_include_qasm(NAME) extern "C" void NAME(qreg);
80
#define qcor_include_qsharp(NAME, RETURN_TYPE, ...) extern "C" RETURN_TYPE NAME(...);