Skip to content

memory leak #51

Description

@Co1lin

Graph deconstruction will not release occupied memory.

test code:

#include <iostream>
#include <vector>

#include "quartz/tasograph/tasograph.h"
#include "quartz/context/context.h"
using namespace quartz;

const std::string input_file = "../experiment/nam_circs/adder_8.qasm";

Context ctx({
        GateType::h, GateType::cx, GateType::x, GateType::rz, GateType::add,
        GateType::input_qubit, GateType::input_param
});
QASMParser qasm_parser(&ctx);

template<class Vec, class VT>
void append(Vec& vec, const VT& value) {
  vec.emplace_back(value);
}

auto graph_from_qasm_file(const std::string& file) {
  DAG *dag = nullptr;
  qasm_parser.load_qasm(file, dag);
  return std::make_shared<Graph>( Graph(&ctx, dag) );
}

int main()
{
  std::vector<std::shared_ptr<Graph>> buffer;
  std::cout << "Reading graph...  " << std::endl;
  const auto test_graph = Graph::from_qasm_file(&ctx, input_file);
//  const auto test_graph = graph_from_qasm_file(input_file);
  std::cout << "test_graph.get_num_qubits() = " << test_graph->gate_count() << std::endl;
  while (true) {
    int delta = 0;
    std::cin >> delta;
    if (delta >= 0) {
      std::cout << "Start appending: size(buffer) = " << buffer.size() << " delta = " << delta << std::endl;
      for (int i = 0; i < delta; i++) {
        auto tmp_graph = Graph::from_qasm_file(&ctx, input_file);
        append(buffer, tmp_graph);
      }
      std::cout << "Appending finished: size(buffer) = " << buffer.size() << "\n\n";
    }
    else {
      std::cout << "\nStart popping: size(buffer) = " << buffer.size() << " delta = " << delta << std::endl;
      for (int i = delta; i < 0; i++) {
        buffer.pop_back();
      }
      std::cout << "Popping finished: size(buffer) = " << buffer.size() << "\n\n";
    }
  }

  return 0;
}
ps afu | awk 'NR>1 {$5=int($5/1024)"M";}{ print;}' | grep test_mem

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions