Skip to content

Commit

Permalink
Fixed Memory Issues. (tensorflow#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBroughton authored Feb 27, 2020
1 parent 6ab0fdf commit 0811355
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tensorflow_quantum/core/ops/tfq_simulate_expectation_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class TfqSimulateExpectationOp : public tensorflow::OpKernel {
auto DoWork = [&](int start, int end) {
int old_batch_index = -2;
int cur_batch_index = -1;
int old_num_qubits = -2;
int cur_op_index;
std::unique_ptr<StateSpace> test_state =
std::unique_ptr<StateSpace>(GetStateSpace(1, 1));
Expand Down Expand Up @@ -112,7 +113,7 @@ class TfqSimulateExpectationOp : public tensorflow::OpKernel {
// without ever having to call free (until very end). This is tricky
// to implement because right now certain statespaces can't simulate
// all states and we use StateSpaceSlow for smaller circuits.
if (num != num_qubits[old_batch_index]) {
if (num != old_num_qubits) {
test_state.reset(GetStateSpace(num, 1));
test_state->CreateState();

Expand All @@ -124,6 +125,7 @@ class TfqSimulateExpectationOp : public tensorflow::OpKernel {
// will take care of things for us.
test_state->SetStateZero();
OP_REQUIRES_OK(context, test_state->Update(circuit));
old_num_qubits = num;
}

float expectation = 0.0;
Expand Down

0 comments on commit 0811355

Please sign in to comment.