Unverified Commit 2735dea5 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Fix some compatibility issues

Testing QPT with QuaC, I was puzzled by the fact that `getPointerLike<Accelerator>` and `getPointerLike<CompositeInstruction>` were failing although I *did* send on those two parameters and the heterogenous map *does* contain those params, just that the templated functions are mismatched (possibly between the QuaC side and XACC side)

My theory was that because these are all implicit instantiations, somehow, they can become mismatched (the order in which the compiler sees those instantiations), especially with external linkage (like QuaC).

Anyway, by explicitly instantiating those (Accelerator and Composite), the issue is fixed.

Also, fix a bug in QPT where the imaginary chi vector is always uninitialized (all zeros)

Lastly, add an option to QPT to disable circuit optimization. When the circuit contains pulse instructions, the circuit optimizer doesn’t work correctly (looks like it may skip the pulse instruction and merge gates)

Tested by: running XACC tests and QuaC QPT tests.

Signed-off-by: Nguyen, Thien Minh's avatarThien Nguyen <nguyentm@ornl.gov>
parent dbde3a2d
......@@ -38,6 +38,12 @@ bool QPT::initialize(const HeterogeneousMap &parameters) {
if (parameters.keyExists<std::vector<int>>("qubit-map")) {
qubit_map = parameters.get<std::vector<int>>("qubit-map");
// Default: always optimize the circuit
optimizeCircuit = true;
if (parameters.keyExists<bool>("optimize-circuit")) {
optimizeCircuit = parameters.get<bool>("optimize-circuit");
return true;
......@@ -320,9 +326,11 @@ void QPT::execute(const std::shared_ptr<AcceleratorBuffer> buffer) const {
all_circuits = tmp_all;
// Perform default circuit optimization
auto optimizer = xacc::getIRTransformation("circuit-optimizer");
for (auto circuit : all_circuits) {
optimizer->apply(circuit, nullptr);
if (optimizeCircuit) {
auto optimizer = xacc::getIRTransformation("circuit-optimizer");
for (auto circuit : all_circuits) {
optimizer->apply(circuit, nullptr);
// Map to physical qubits if specified
......@@ -464,8 +472,7 @@ double QPT::calculate(const std::string &calculation_task,
std::vector<double> chi_theory_imag(chi_theory_real.size());
if (extra_data.keyExists<std::vector<double>>("chi-theoretical-imag")) {
std::vector<double> chi_theory_imag =
chi_theory_imag = extra_data.get<std::vector<double>>("chi-theoretical-imag");
int n = (int)std::sqrt(chi_theory_real.size());
......@@ -21,7 +21,7 @@ class QPT : public Algorithm {
CompositeInstruction *circuit;
Accelerator *qpu;
std::vector<int> qubit_map;
bool optimizeCircuit;
bool initialize(const HeterogeneousMap &parameters) override;
const std::vector<std::string> requiredParameters() const override;
......@@ -99,5 +99,6 @@ public:
virtual ~Accelerator() {}
template Accelerator* HeterogeneousMap::getPointerLike<Accelerator>(const std::string key) const;
} // namespace xacc
......@@ -131,5 +131,6 @@ public:
virtual ~CompositeInstruction() {}
template CompositeInstruction* HeterogeneousMap::getPointerLike<CompositeInstruction>(const std::string key) const;
} // namespace xacc
......@@ -250,6 +250,11 @@ template <class T>
std::unordered_map<const HeterogeneousMap *, std::map<std::string, T>>
// Make sure these basic types are always instantiatied for HeterogeneousMap
template const bool& HeterogeneousMap::get<bool>(const std::string key) const;
template const int& HeterogeneousMap::get<int>(const std::string key) const;
template const double& HeterogeneousMap::get<double>(const std::string key) const;
template <typename... Types> class Variant : public mpark::variant<Types...> {
Supports Markdown
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