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

Fixed MPS save failure when memory limit is ignored #2248

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
Fixes a bug preventing the MPS simulator from running when its estimate
for the required memory is too large, even when `max_memory_mb=-1`.
2 changes: 1 addition & 1 deletion src/simulators/circuit_executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ uint_t Executor<state_t>::get_max_parallel_shots(
const Config &config, const Circuit &circ,
const Noise::NoiseModel &noise) const {
uint_t mem = required_memory_mb(config, circ, noise);
if (mem == 0)
if (mem == 0 || !check_required_memory_)
return circ.shots * circ.num_bind_params;

if (sim_device_ == Device::GPU && num_gpus_ > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import math
import numpy as np
from qiskit import QuantumCircuit, transpile
from qiskit.circuit.library import PauliEvolutionGate
from qiskit.quantum_info import SparsePauliOp
from qiskit.synthesis import SuzukiTrotter
from test.terra.backends.simulator_test_case import SimulatorTestCase, supported_methods


Expand Down Expand Up @@ -60,3 +63,32 @@ def test_save_matrix_product_state(self, method, device):
self.assertTrue(np.allclose(val, target))
for val, target in zip(value[1], target_lambda_reg):
self.assertTrue(np.allclose(val, target))

@supported_methods(["automatic", "matrix_product_state"])
def test_save_matrix_product_state_memory_limit(self, method, device):
"""Test save matrix_product_state instruction when max memory check is disabled"""
backend = self.backend(
method=method,
device=device,
matrix_product_state_max_bond_dimension=10,
max_memory_mb=-1, # Disable memory limit check
)

L = 100
hamiltonian = SparsePauliOp.from_sparse_list([], num_qubits=L)
for x in range(L - 1):
hamiltonian += SparsePauliOp.from_sparse_list(
[
("XX", (x, x + 1), 1),
("YY", (x, x + 1), 1),
],
num_qubits=L,
)
qc = QuantumCircuit(L)
qc.append(
PauliEvolutionGate(hamiltonian, synthesis=SuzukiTrotter(reps=100)), qargs=qc.qubits
)
qc = qc.decompose()
qc.save_matrix_product_state("mps")
result = backend.run(qc).result().data(0)
self.assertTrue("mps" in result)
Loading