Skip to content
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
40 changes: 40 additions & 0 deletions test/qpy_compat/compare_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python3
# This code is part of Qiskit.
#
# (C) Copyright IBM 2023.
#
# 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
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Compare Qiskit versions to determine if we should run qpy compat tests."""

import argparse
import sys

from qiskit.qpy.interface import VERSION_PATTERN_REGEX


def main():
"""Main function."""
parser = argparse.ArgumentParser(prog="compare_version", description="Compare version strings")
parser.add_argument(
"source_version", help="Source version of Qiskit that is generating the payload"
)
parser.add_argument("test_version", help="Version under test that will load the QPY payload")
args = parser.parse_args()
source_match = VERSION_PATTERN_REGEX.search(args.source_version)
target_match = VERSION_PATTERN_REGEX.search(args.test_version)
source_version = tuple(int(x) for x in source_match.group("release").split("."))
target_version = tuple(int(x) for x in target_match.group("release").split("."))
if source_version > target_version:
sys.exit(1)
sys.exit(0)


if __name__ == "__main__":
main()
18 changes: 17 additions & 1 deletion test/qpy_compat/process_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,25 @@
set -e
set -x

# version is the source version, this is the release with which to generate
# qpy files with to load with the version under test
version=$1
parts=( ${version//./ } )
if [[ ${parts[1]} -lt 18 ]] ; then
# qiskit_version is the version under test, We're testing that we can correctly
# read the qpy files generated with source version with this version.
qiskit_version=`./qiskit_venv/bin/python -c "import qiskit;print(qiskit.__version__)"`
qiskit_parts=( ${qiskit_version//./ } )


# If source version is less than 0.18 QPY didn't exist yet so exit fast
if [[ ${parts[0]} -eq 0 && ${parts[1]} -lt 18 ]] ; then
exit 0
fi

# If the source version is newer than the version under test exit fast because
# there is no QPY compatibility for loading a qpy file generated from a newer
# release with an older release of Qiskit.
if ! ./qiskit_venv/bin/python ./compare_versions.py "$version" "$qiskit_version" ; then
exit 0
fi

Expand Down