Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory leak #51

Open
Co1lin opened this issue Sep 12, 2022 · 0 comments
Open

memory leak #51

Co1lin opened this issue Sep 12, 2022 · 0 comments

Comments

@Co1lin
Copy link
Collaborator

Co1lin commented Sep 12, 2022

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
@Co1lin Co1lin closed this as completed Oct 12, 2022
@Co1lin Co1lin reopened this Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant