From a9c57a6570092b5729e6d9c96bd19f5e5137807a Mon Sep 17 00:00:00 2001 From: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com> Date: Mon, 9 Jun 2025 19:15:52 +0100 Subject: [PATCH 01/10] Update serialising methods and instructions --- .../algorithms/classifiers/qsvc.py | 21 +++++-- .../algorithms/serializable_model.py | 60 ++++++++++++++++--- ...st_fidelity_quantum_kernel_pegasos_qsvc.py | 6 +- .../test_fidelity_quantum_kernel_qsvc.py | 6 +- .../test_neural_network_classifier.py | 6 +- .../classifiers/test_pegasos_qsvc.py | 6 +- test/algorithms/classifiers/test_qsvc.py | 6 +- .../test_fidelity_quantum_kernel_qsvr.py | 6 +- .../test_neural_network_regressor.py | 6 +- test/algorithms/regressors/test_qsvr.py | 6 +- 10 files changed, 92 insertions(+), 37 deletions(-) diff --git a/qiskit_machine_learning/algorithms/classifiers/qsvc.py b/qiskit_machine_learning/algorithms/classifiers/qsvc.py index 292316965..9b5f97ba2 100644 --- a/qiskit_machine_learning/algorithms/classifiers/qsvc.py +++ b/qiskit_machine_learning/algorithms/classifiers/qsvc.py @@ -34,13 +34,24 @@ class QSVC(SVC, SerializableModelMixin): Read more in the `scikit-learn user guide `_. - **Example** + Examples: + .. code-block:: - .. code-block:: + from qiskit_machine_learning.kernels import FidelityQuantumKernel + from qiskit_machine_learning.algorithms import QSVC + + kernel = FidelityQuantumKernel() + qsvc = QSVC(quantum_kernel=kernel) + qsvc.fit(X_train, y_train) + y_pred = qsvc.predict(X_test) + + # Save the trained model + qsvc.to_dill('qsvc_model.dill') + + # Load the model for later use + loaded_qsvc = QSVC.from_dill('qsvc_model.dill') + score = loaded_qsvc.score(X_test, y_test) - qsvc = QSVC(quantum_kernel=qkernel) - qsvc.fit(sample_train,label_train) - qsvc.predict(sample_test) """ def __init__(self, *, quantum_kernel: Optional[BaseKernel] = None, **kwargs): diff --git a/qiskit_machine_learning/algorithms/serializable_model.py b/qiskit_machine_learning/algorithms/serializable_model.py index ff670665d..dde91ebf7 100644 --- a/qiskit_machine_learning/algorithms/serializable_model.py +++ b/qiskit_machine_learning/algorithms/serializable_model.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2021, 2023. +# (C) Copyright IBM 2021, 2025. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -15,37 +15,70 @@ import dill +from ..utils.deprecation import issue_deprecation_msg + class SerializableModelMixin: """ - Provides convenient methods for saving and loading models. + Provides convenient methods for saving and loading models via dill serialization. + + .. warning:: + The legacy :meth:`save` and :meth:`load` methods are deprecated in v0.9.0 + and will be removed in a future release. Please use :meth:`to_dill` + and :meth:`from_dill` respectively. + """ - def save(self, file_name: str) -> None: + def to_dill(self, file_name: str) -> None: """ Saves this model to the specified file. Internally, the model is serialized via ``dill``. All parameters are saved, including a primitive instance that is referenced by internal objects. That means if a model is loaded from a file and is used, for instance, for inference, the same primitive will be used even if a cloud primitive was used. + .. warning:: + Replaces the deprecated :meth:`save` method. + Args: - file_name: a file name or path where to save the model. + file_name: Path where the serialized model will be written. + + Example: + .. code-block:: + + model.to_dill('model_state.dill') """ with open(file_name, "wb") as handler: dill.dump(self, handler) + def save(self, *args) -> None: + """Backwards compatibility with :meth:`to_dill`, deprecated in v0.9.0.""" + issue_deprecation_msg( + msg="SerializableModelMixin.save() is deprecated.", + version="0.9.0", + remedy="Use the to_dill() method instead.", + period="4 months", + ) + self.to_dill(*args) + @classmethod - def load(cls, file_name: str) -> Any: + def from_dill(cls, file_name: str) -> Any: """ - Loads a model from the file. If the loaded model is not an instance of the class whose + Loads a model from a file. If the loaded model is not an instance of the class whose method was called, then a warning is raised. Nevertheless, the loaded model may be a valid model. + Replaces the deprecated :meth:`load` method. + Args: - file_name: a file name or path to load a model from. + file_name: Path to the dill file containing the serialized model. Returns: - A loaded model. + An instance of the model loaded from disk. + + Example: + .. code-block:: + + loaded = MyModel.from_dill('model_state.dill') Raises: TypeError: if a loaded model is not an instance of the expected class. @@ -55,3 +88,14 @@ def load(cls, file_name: str) -> Any: if not isinstance(model, cls): raise TypeError(f"Loaded model is of class {type(model)}. Expected class: {cls}.") return model + + @classmethod + def load(cls, *args) -> Any: + """Backwards compatibility with :meth:`from_dill`, deprecated in v0.9.0.""" + issue_deprecation_msg( + msg="SerializableModelMixin.load() is deprecated.", + version="0.9.0", + remedy="Use the from_dill() classmethod instead.", + period="4 months", + ) + return cls.from_dill(*args) diff --git a/test/algorithms/classifiers/test_fidelity_quantum_kernel_pegasos_qsvc.py b/test/algorithms/classifiers/test_fidelity_quantum_kernel_pegasos_qsvc.py index e5ce4efc5..5de951b31 100644 --- a/test/algorithms/classifiers/test_fidelity_quantum_kernel_pegasos_qsvc.py +++ b/test/algorithms/classifiers/test_fidelity_quantum_kernel_pegasos_qsvc.py @@ -208,9 +208,9 @@ def test_save_load(self): # save/load, change the quantum instance and check if predicted values are the same file_name = os.path.join(tempfile.gettempdir(), "pegasos.model") - regressor.save(file_name) + regressor.to_dill(file_name) try: - regressor_load = PegasosQSVC.load(file_name) + regressor_load = PegasosQSVC.from_dill(file_name) loaded_model_predicts = regressor_load.predict(test_features) np.testing.assert_array_almost_equal(original_predicts, loaded_model_predicts) @@ -222,7 +222,7 @@ class FakeModel(SerializableModelMixin): pass with self.assertRaises(TypeError): - FakeModel.load(file_name) + FakeModel.from_dill(file_name) finally: os.remove(file_name) diff --git a/test/algorithms/classifiers/test_fidelity_quantum_kernel_qsvc.py b/test/algorithms/classifiers/test_fidelity_quantum_kernel_qsvc.py index 8ebe01f77..e9d0f3fc7 100644 --- a/test/algorithms/classifiers/test_fidelity_quantum_kernel_qsvc.py +++ b/test/algorithms/classifiers/test_fidelity_quantum_kernel_qsvc.py @@ -105,9 +105,9 @@ def test_save_load(self): # save/load, change the quantum instance and check if predicted values are the same file_name = os.path.join(tempfile.gettempdir(), "qsvc.model") - classifier.save(file_name) + classifier.to_dill(file_name) try: - classifier_load = QSVC.load(file_name) + classifier_load = QSVC.from_dill(file_name) loaded_model_predicts = classifier_load.predict(test_features) np.testing.assert_array_almost_equal(original_predicts, loaded_model_predicts) @@ -119,7 +119,7 @@ class FakeModel(SerializableModelMixin): pass with self.assertRaises(TypeError): - FakeModel.load(file_name) + FakeModel.from_dill(file_name) finally: os.remove(file_name) diff --git a/test/algorithms/classifiers/test_neural_network_classifier.py b/test/algorithms/classifiers/test_neural_network_classifier.py index 428915f90..06062cb19 100644 --- a/test/algorithms/classifiers/test_neural_network_classifier.py +++ b/test/algorithms/classifiers/test_neural_network_classifier.py @@ -390,9 +390,9 @@ def test_save_load(self, qnn_type): # save/load, change the quantum instance and check if predicted values are the same with tempfile.TemporaryDirectory() as dir_name: file_name = os.path.join(dir_name, "classifier.model") - classifier.save(file_name) + classifier.to_dill(file_name) - classifier_load = NeuralNetworkClassifier.load(file_name) + classifier_load = NeuralNetworkClassifier.from_dill(file_name) loaded_model_predicts = classifier_load.predict(test_features) np.testing.assert_array_almost_equal(original_predicts, loaded_model_predicts) @@ -404,7 +404,7 @@ class FakeModel(SerializableModelMixin): pass with self.assertRaises(TypeError): - FakeModel.load(file_name) + FakeModel.from_dill(file_name) @idata((True, False)) def test_num_classes_data(self, one_hot): diff --git a/test/algorithms/classifiers/test_pegasos_qsvc.py b/test/algorithms/classifiers/test_pegasos_qsvc.py index 49ddcc255..7d8e02756 100644 --- a/test/algorithms/classifiers/test_pegasos_qsvc.py +++ b/test/algorithms/classifiers/test_pegasos_qsvc.py @@ -227,9 +227,9 @@ def test_save_load(self): # save/load, change the quantum instance and check if predicted values are the same file_name = os.path.join(tempfile.gettempdir(), "pegasos.model") - regressor.save(file_name) + regressor.to_dill(file_name) try: - regressor_load = PegasosQSVC.load(file_name) + regressor_load = PegasosQSVC.from_dill(file_name) loaded_model_predicts = regressor_load.predict(test_features) np.testing.assert_array_almost_equal(original_predicts, loaded_model_predicts) @@ -241,7 +241,7 @@ class FakeModel(SerializableModelMixin): pass with self.assertRaises(TypeError): - FakeModel.load(file_name) + FakeModel.from_dill(file_name) finally: os.remove(file_name) diff --git a/test/algorithms/classifiers/test_qsvc.py b/test/algorithms/classifiers/test_qsvc.py index 5d7489873..ecbc2abb2 100644 --- a/test/algorithms/classifiers/test_qsvc.py +++ b/test/algorithms/classifiers/test_qsvc.py @@ -107,9 +107,9 @@ def test_save_load(self): # save/load, change the quantum instance and check if predicted values are the same file_name = os.path.join(tempfile.gettempdir(), "qsvc.model") - classifier.save(file_name) + classifier.to_dill(file_name) try: - classifier_load = QSVC.load(file_name) + classifier_load = QSVC.from_dill(file_name) loaded_model_predicts = classifier_load.predict(test_features) np.testing.assert_array_almost_equal(original_predicts, loaded_model_predicts) @@ -121,7 +121,7 @@ class FakeModel(SerializableModelMixin): pass with self.assertRaises(TypeError): - FakeModel.load(file_name) + FakeModel.from_dill(file_name) finally: os.remove(file_name) diff --git a/test/algorithms/regressors/test_fidelity_quantum_kernel_qsvr.py b/test/algorithms/regressors/test_fidelity_quantum_kernel_qsvr.py index 548308cb6..f9fbde184 100644 --- a/test/algorithms/regressors/test_fidelity_quantum_kernel_qsvr.py +++ b/test/algorithms/regressors/test_fidelity_quantum_kernel_qsvr.py @@ -136,9 +136,9 @@ def test_save_load(self): with tempfile.TemporaryDirectory() as dir_name: file_name = os.path.join(dir_name, "qsvr.model") - regressor.save(file_name) + regressor.to_dill(file_name) - regressor_load = QSVR.load(file_name) + regressor_load = QSVR.from_dill(file_name) loaded_model_predicts = regressor_load.predict(test_features) np.testing.assert_array_almost_equal(original_predicts, loaded_model_predicts) @@ -149,7 +149,7 @@ class FakeModel(SerializableModelMixin): pass with self.assertRaises(TypeError): - FakeModel.load(file_name) + FakeModel.from_dill(file_name) if __name__ == "__main__": diff --git a/test/algorithms/regressors/test_neural_network_regressor.py b/test/algorithms/regressors/test_neural_network_regressor.py index 10c16dc09..8e71203eb 100644 --- a/test/algorithms/regressors/test_neural_network_regressor.py +++ b/test/algorithms/regressors/test_neural_network_regressor.py @@ -189,9 +189,9 @@ def test_save_load(self): # save/load, change the quantum instance and check if predicted values are the same with tempfile.TemporaryDirectory() as dir_name: file_name = os.path.join(dir_name, "regressor.model") - regressor.save(file_name) + regressor.to_dill(file_name) - regressor_load = NeuralNetworkRegressor.load(file_name) + regressor_load = NeuralNetworkRegressor.from_dill(file_name) loaded_model_predicts = regressor_load.predict(test_features) np.testing.assert_array_almost_equal(original_predicts, loaded_model_predicts) @@ -203,7 +203,7 @@ class FakeModel(SerializableModelMixin): pass with self.assertRaises(TypeError): - FakeModel.load(file_name) + FakeModel.from_dill(file_name) def test_untrained(self): """Test untrained regressor.""" diff --git a/test/algorithms/regressors/test_qsvr.py b/test/algorithms/regressors/test_qsvr.py index f4cb2f6ad..cc6a4d764 100644 --- a/test/algorithms/regressors/test_qsvr.py +++ b/test/algorithms/regressors/test_qsvr.py @@ -131,9 +131,9 @@ def test_save_load(self): with tempfile.TemporaryDirectory() as dir_name: file_name = os.path.join(dir_name, "qsvr.model") - regressor.save(file_name) + regressor.to_dill(file_name) - regressor_load = QSVR.load(file_name) + regressor_load = QSVR.from_dill(file_name) loaded_model_predicts = regressor_load.predict(test_features) np.testing.assert_array_almost_equal(original_predicts, loaded_model_predicts) @@ -144,7 +144,7 @@ class FakeModel(SerializableModelMixin): pass with self.assertRaises(TypeError): - FakeModel.load(file_name) + FakeModel.from_dill(file_name) if __name__ == "__main__": From cfcc7edcad43126f8e5f4a6c0e86cbb2140bcaaf Mon Sep 17 00:00:00 2001 From: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com> Date: Mon, 9 Jun 2025 19:27:50 +0100 Subject: [PATCH 02/10] Fix copyright year --- qiskit_machine_learning/algorithms/classifiers/qsvc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit_machine_learning/algorithms/classifiers/qsvc.py b/qiskit_machine_learning/algorithms/classifiers/qsvc.py index 9b5f97ba2..81a407df5 100644 --- a/qiskit_machine_learning/algorithms/classifiers/qsvc.py +++ b/qiskit_machine_learning/algorithms/classifiers/qsvc.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2021, 2024. +# (C) Copyright IBM 2021, 2025. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory From 9a78cd2757d9e8d1ecc0b5ab7b5dec8b40736755 Mon Sep 17 00:00:00 2001 From: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com> Date: Wed, 11 Jun 2025 11:06:49 +0100 Subject: [PATCH 03/10] Add reno --- .../serializable-model-update-io-b708094e41edeb35.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml diff --git a/releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml b/releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml new file mode 100644 index 000000000..d347240b6 --- /dev/null +++ b/releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml @@ -0,0 +1,10 @@ +--- +upgrade: + - | + Added new methods :meth:`to_dill` and :meth:`from_dill`, with improved docstrings and examples. + Deprecated :meth:`save` and :meth:`load` in favor of the `{to/from}_dill`. +deprecations: + - | + The methods :meth:`SerializableModelMixin.save` and :meth:`SerializableModelMixin.load` have + been deprecated and will be removed (target v.0.9.0). Please use + :meth:`SerializableModelMixin.to_dill` and :meth:`SerializableModelMixin.from_dill` instead. From 27875de53a32a57e9c4133dc79a12ff8db9125cc Mon Sep 17 00:00:00 2001 From: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com> Date: Wed, 11 Jun 2025 13:32:10 +0100 Subject: [PATCH 04/10] Fix spelling --- .pylintdict | 1 + .../notes/serializable-model-update-io-b708094e41edeb35.yaml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.pylintdict b/.pylintdict index 7e77dafdf..c33511de9 100644 --- a/.pylintdict +++ b/.pylintdict @@ -500,6 +500,7 @@ sdg seealso semidefinite serializable +serializablemodelmixin shalev shanno shende diff --git a/releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml b/releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml index d347240b6..dd551de68 100644 --- a/releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml +++ b/releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml @@ -2,9 +2,9 @@ upgrade: - | Added new methods :meth:`to_dill` and :meth:`from_dill`, with improved docstrings and examples. - Deprecated :meth:`save` and :meth:`load` in favor of the `{to/from}_dill`. + Deprecated :meth:`save` and :meth:`load` in favor of the `{to/from}_dill` methods. deprecations: - | The methods :meth:`SerializableModelMixin.save` and :meth:`SerializableModelMixin.load` have - been deprecated and will be removed (target v.0.9.0). Please use + been deprecated and will be removed (target v0.9.0). Please use :meth:`SerializableModelMixin.to_dill` and :meth:`SerializableModelMixin.from_dill` instead. From 4631bffa220deba39d220bee00566692237ae9c7 Mon Sep 17 00:00:00 2001 From: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com> Date: Wed, 11 Jun 2025 13:44:19 +0100 Subject: [PATCH 05/10] Fix spelling --- .pylintdict | 1 + 1 file changed, 1 insertion(+) diff --git a/.pylintdict b/.pylintdict index c33511de9..5517b4478 100644 --- a/.pylintdict +++ b/.pylintdict @@ -109,6 +109,7 @@ deterministically diag dicts diederik +dill dimensionality dir discretization From c0fd6f8e70b44dbef5fe60a6558d2ccb887b627b Mon Sep 17 00:00:00 2001 From: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com> Date: Wed, 11 Jun 2025 13:55:40 +0100 Subject: [PATCH 06/10] Fix spelling --- .../notes/serializable-model-update-io-b708094e41edeb35.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml b/releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml index dd551de68..340396341 100644 --- a/releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml +++ b/releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml @@ -2,7 +2,7 @@ upgrade: - | Added new methods :meth:`to_dill` and :meth:`from_dill`, with improved docstrings and examples. - Deprecated :meth:`save` and :meth:`load` in favor of the `{to/from}_dill` methods. + Deprecated :meth:`save` and :meth:`load` in favor of :meth:`to_dill` and :meth:`from_dill`. deprecations: - | The methods :meth:`SerializableModelMixin.save` and :meth:`SerializableModelMixin.load` have From 7e91ce53cf8c61d27ab2bc484179beaa48333ae0 Mon Sep 17 00:00:00 2001 From: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com> Date: Wed, 11 Jun 2025 14:35:44 +0100 Subject: [PATCH 07/10] Fix spelling --- .pylintdict | 1 + 1 file changed, 1 insertion(+) diff --git a/.pylintdict b/.pylintdict index 5517b4478..d1d3d6af9 100644 --- a/.pylintdict +++ b/.pylintdict @@ -120,6 +120,7 @@ disp distro dobsicek docstring +docstrings doi dok dp From 5ed7213858ee82edc5b173f3902329dd8d789a9a Mon Sep 17 00:00:00 2001 From: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com> Date: Wed, 11 Jun 2025 14:56:18 +0100 Subject: [PATCH 08/10] Update tutorial 09 and remove upgrade reno --- docs/tutorials/09_saving_and_loading_models.ipynb | 2 +- .../notes/serializable-model-update-io-b708094e41edeb35.yaml | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/docs/tutorials/09_saving_and_loading_models.ipynb b/docs/tutorials/09_saving_and_loading_models.ipynb index 01e4773d8..c7f0c7ef2 100644 --- a/docs/tutorials/09_saving_and_loading_models.ipynb +++ b/docs/tutorials/09_saving_and_loading_models.ipynb @@ -555,7 +555,7 @@ "metadata": {}, "outputs": [], "source": [ - "loaded_classifier = VQC.load(\"vqc_classifier.model\")" + "loaded_classifier = VQC.from_dill(\"vqc_classifier.model\")" ] }, { diff --git a/releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml b/releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml index 340396341..50f105ca3 100644 --- a/releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml +++ b/releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml @@ -1,8 +1,4 @@ --- -upgrade: - - | - Added new methods :meth:`to_dill` and :meth:`from_dill`, with improved docstrings and examples. - Deprecated :meth:`save` and :meth:`load` in favor of :meth:`to_dill` and :meth:`from_dill`. deprecations: - | The methods :meth:`SerializableModelMixin.save` and :meth:`SerializableModelMixin.load` have From 32bad346e5b0b6eb30c5da6642350fba00a8d2d6 Mon Sep 17 00:00:00 2001 From: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com> Date: Wed, 11 Jun 2025 16:03:46 +0100 Subject: [PATCH 09/10] Update removal version --- docs/tutorials/09_saving_and_loading_models.ipynb | 2 +- qiskit_machine_learning/algorithms/serializable_model.py | 4 ++-- .../notes/serializable-model-update-io-b708094e41edeb35.yaml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/tutorials/09_saving_and_loading_models.ipynb b/docs/tutorials/09_saving_and_loading_models.ipynb index c7f0c7ef2..aeba46840 100644 --- a/docs/tutorials/09_saving_and_loading_models.ipynb +++ b/docs/tutorials/09_saving_and_loading_models.ipynb @@ -535,7 +535,7 @@ "metadata": {}, "outputs": [], "source": [ - "original_classifier.save(\"vqc_classifier.model\")" + "original_classifier.to_dill(\"vqc_classifier.model\")" ] }, { diff --git a/qiskit_machine_learning/algorithms/serializable_model.py b/qiskit_machine_learning/algorithms/serializable_model.py index dde91ebf7..7bfed734f 100644 --- a/qiskit_machine_learning/algorithms/serializable_model.py +++ b/qiskit_machine_learning/algorithms/serializable_model.py @@ -54,7 +54,7 @@ def save(self, *args) -> None: """Backwards compatibility with :meth:`to_dill`, deprecated in v0.9.0.""" issue_deprecation_msg( msg="SerializableModelMixin.save() is deprecated.", - version="0.9.0", + version="0.10.0", remedy="Use the to_dill() method instead.", period="4 months", ) @@ -94,7 +94,7 @@ def load(cls, *args) -> Any: """Backwards compatibility with :meth:`from_dill`, deprecated in v0.9.0.""" issue_deprecation_msg( msg="SerializableModelMixin.load() is deprecated.", - version="0.9.0", + version="0.10.0", remedy="Use the from_dill() classmethod instead.", period="4 months", ) diff --git a/releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml b/releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml index 50f105ca3..b43ca68ce 100644 --- a/releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml +++ b/releasenotes/notes/serializable-model-update-io-b708094e41edeb35.yaml @@ -2,5 +2,5 @@ deprecations: - | The methods :meth:`SerializableModelMixin.save` and :meth:`SerializableModelMixin.load` have - been deprecated and will be removed (target v0.9.0). Please use + been deprecated and will be removed (target v0.10.0). Please use :meth:`SerializableModelMixin.to_dill` and :meth:`SerializableModelMixin.from_dill` instead. From 685a271721f88a6143d86395940472b9220c476e Mon Sep 17 00:00:00 2001 From: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com> Date: Thu, 12 Jun 2025 13:31:14 +0100 Subject: [PATCH 10/10] Update removal version --- qiskit_machine_learning/algorithms/serializable_model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qiskit_machine_learning/algorithms/serializable_model.py b/qiskit_machine_learning/algorithms/serializable_model.py index 7bfed734f..dde91ebf7 100644 --- a/qiskit_machine_learning/algorithms/serializable_model.py +++ b/qiskit_machine_learning/algorithms/serializable_model.py @@ -54,7 +54,7 @@ def save(self, *args) -> None: """Backwards compatibility with :meth:`to_dill`, deprecated in v0.9.0.""" issue_deprecation_msg( msg="SerializableModelMixin.save() is deprecated.", - version="0.10.0", + version="0.9.0", remedy="Use the to_dill() method instead.", period="4 months", ) @@ -94,7 +94,7 @@ def load(cls, *args) -> Any: """Backwards compatibility with :meth:`from_dill`, deprecated in v0.9.0.""" issue_deprecation_msg( msg="SerializableModelMixin.load() is deprecated.", - version="0.10.0", + version="0.9.0", remedy="Use the from_dill() classmethod instead.", period="4 months", )