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

Remove prefix hardcoding in validate_target() #960

Merged
merged 3 commits into from
Jun 7, 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
28 changes: 3 additions & 25 deletions general-superstaq/general_superstaq/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,14 @@ def validate_integer_param(integer_param: object, min_val: int = 1) -> None:


def validate_target(target: str) -> None:
"""Checks that a target contains a valid format, vendor prefix, and device type.
"""Checks that `target` conforms to a valid Superstaq format and device type.

Args:
target: A string containing the name of a target device.

Raises:
ValueError: If `target` has an invalid format, vendor prefix, or device type.
ValueError: If `target` has an invalid format or device type.
"""
vendor_prefixes = [
"aqt",
"aws",
"cq",
"qtm",
"ibmq",
"ionq",
"oxford",
"quera",
"rigetti",
"qscout",
"ss",
"toshiba",
]

target_device_types = ["qpu", "simulator"]

# Check valid format
Expand All @@ -61,14 +46,7 @@ def validate_target(target: str) -> None:
"the form '<provider>_<device>_<type>', e.g. 'ibmq_brisbane_qpu'."
)

prefix, _, device_type = match.groups()

# Check valid prefix
if prefix not in vendor_prefixes:
raise ValueError(
f"{target!r} does not have a valid target prefix. Valid prefixes are: "
f"{vendor_prefixes}."
)
_, _, device_type = match.groups()

# Check for valid device type
if device_type not in target_device_types:
Expand Down
3 changes: 0 additions & 3 deletions general-superstaq/general_superstaq/validation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ def test_validate_target() -> None:
with pytest.raises(ValueError, match="does not have a valid target device type"):
gss.validation.validate_target("ibmq_invalid_device")

with pytest.raises(ValueError, match="does not have a valid target prefix"):
gss.validation.validate_target("invalid_test_qpu")


def test_validate_integer_param() -> None:
# Tests for valid inputs -> Pass
Expand Down
Loading