From 11b03c391b91042650c1446c2a2b142e535c06fc Mon Sep 17 00:00:00 2001 From: Gadi Aleksandrowicz Date: Tue, 29 Oct 2024 18:27:55 +0200 Subject: [PATCH 1/2] Fixed MPS save failure when memory limit is ignored --- src/simulators/circuit_executor.hpp | 2 +- .../test_save_matrix_product_state.py | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/simulators/circuit_executor.hpp b/src/simulators/circuit_executor.hpp index ddfee144c1..4244a547fe 100644 --- a/src/simulators/circuit_executor.hpp +++ b/src/simulators/circuit_executor.hpp @@ -428,7 +428,7 @@ uint_t Executor::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) { diff --git a/test/terra/backends/aer_simulator/test_save_matrix_product_state.py b/test/terra/backends/aer_simulator/test_save_matrix_product_state.py index 79584ca136..0de39fa30a 100644 --- a/test/terra/backends/aer_simulator/test_save_matrix_product_state.py +++ b/test/terra/backends/aer_simulator/test_save_matrix_product_state.py @@ -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 @@ -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) From 0f3bce35ac9332ebccc1bada1a50ca313d5e3fc4 Mon Sep 17 00:00:00 2001 From: Gadi Aleksandrowicz Date: Wed, 30 Oct 2024 11:07:54 +0200 Subject: [PATCH 2/2] Release note --- .../fix_mps_save_without_memory_limit-64d927c4b4e1e2d4.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 releasenotes/notes/fix_mps_save_without_memory_limit-64d927c4b4e1e2d4.yaml diff --git a/releasenotes/notes/fix_mps_save_without_memory_limit-64d927c4b4e1e2d4.yaml b/releasenotes/notes/fix_mps_save_without_memory_limit-64d927c4b4e1e2d4.yaml new file mode 100644 index 0000000000..2aaeabb3f2 --- /dev/null +++ b/releasenotes/notes/fix_mps_save_without_memory_limit-64d927c4b4e1e2d4.yaml @@ -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`.