-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle an optional symengine and sympy in qpy (#13917)
* Document that symengine is optional for qpy.load This commit changes the API for qpy.load() to make it explicit that symengine may not be installed in the future but is a requirement for deserializing certain payloads that were generated using symengine. We're expecting to drop symengine as a requirement with #13278 which should improve Qiskit's installation story and also will facilitate adding a C api for circuits. But the qpy v10, v11, and v13 have a hard requirement on symengine (specifically 0.11.0 and 0.13.0) to be able to deserialize `ParameterExpression` if the symbolic encoding was set to use it. Since the function needs to support being able to deserialize these payloads symengine will need to be installed. This commit adds the document and release note to indicate this change in behavior. * Raise QPY compatibility version to remove symengine and sympy dependency This commit raises the qpy compatibility version to QPY format version 13. As the larger PR is planning for a world without symengine installed by default this becomes a problem for the generation side too. This becomes a blocker for using QPY < 13 in the future so this commit opts to just raise the minimum verison to get ahead of any potential issues. * Add HAS_SYMENGINE check on load function * Correct logic for ucr*_dg gates name changing * Add feature string to optional decorator * Prepare for an optional sympy In addition to making symengine optional #13278 should also enable us to make sympy optional. It would only be potentially needed for loading QPY payloads that were generated using sympy encoding, but also some visualization functions. This commit lays the groundwork for removing it as a dependency by outlining the API changes for the functions that will optionally depend on sympy and raise an exception if it's not installed. It won't be possible to trigger the exception with sympy in the requirements list, but when we do remove it the API is prepared for it. * Fix release note categorization * Add missing optional on template substitution
- Loading branch information
Showing
13 changed files
with
128 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
releasenotes/notes/qpy-missing-symengine-ee8265348c992ef3.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
upgrade_qpy: | ||
- | | ||
The :func:`.qpy.load` function can now raise a | ||
:class:`.MissingOptionalLibrary` exception if a QPY v10, v11, or v12 | ||
payload is passed in that is using symengine symbolic expressions | ||
and symengine is not installed. Or if sympy is not installed for any | ||
other QPY payload < v13. In the Qiskit 1.x releases symengine and sympy | ||
were always guaranteed to be installed, but starting in 2.x this is no | ||
longer a hard requirement and may only be needed if you're deserializing a QPY | ||
file that was generated using symengine. Parsing these QPY payloads | ||
requires symengine (0.11.0 or 0.13.0) as it's usage is baked into the | ||
format specification for QPY v10, v11, and v12 so if the payload requires | ||
it there is no option but to install a compatible version of symengine. | ||
Similarly, sympy was was used for :class:`.ParameterExpression` encoding | ||
for all QPY versions from 1 through 12. | ||
- | | ||
The minimum QPY compatibility version, :attr:`.QPY_COMPATIBILITY_VERSION`, | ||
has been raised to 13 from 10 in the 1.x release. This version controls | ||
the minimum version of QPY that can be emitted by the :func:`.qpy.dump` | ||
function. This means :func:`.qpy.dump` can only emit QPY v13 and v14 | ||
in this release. QPY v13 is still compatible with Qiskit 1.3.x and 1.4.x | ||
which means payloads can be generated in Qiskit 2.x that can be loaded | ||
with the Qiskit 1.x release series still. | ||
This change was necessary as QPY versions 10 through 12 requires either | ||
the sympy and symengine libraries to generate a serialization for | ||
:class:`.ParameterExpression` objects, but in Qiskit 2.x neither library | ||
is required for the :class:`.ParameterExpression` object. | ||
upgrade_circuits: | ||
- | | ||
The :meth:`.ParameterExpression.sympify` method can now raise a | ||
:class:`.MissingOptionalLibrary` exception if ``sympy`` is not installed. | ||
In the Qiskit 1.x releases sympy was always guaranteed to be installed, | ||
but starting in 2.x this is no longer a hard requirement and may only be | ||
needed if you are using this method. As this functionality explicitly | ||
requires ``sympy`` you will need to ensure you have ``sympy`` installed | ||
to use the method. | ||
upgrade_visualization: | ||
- | | ||
The :func:`.array_to_latex` and :meth:`.Operator.draw` methods can now | ||
raise a :class:`.MissingOptionalLibrary` exception if the ``sympy`` | ||
library is not installed. In the Qiskit 1.x releases symengine and sympy | ||
were always guaranteed to be installed, but starting in 2.x this is no | ||
longer a hard requirement. The latex visualization for a matrix relies | ||
on the sympy library, so if you're using this functionality you should | ||
ensure that you have sympy installed. |
Oops, something went wrong.