-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add get_feedback_groups #162
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -887,6 +887,51 @@ def get_dynamic_quantum_architecture( | |
|
||
return dqa | ||
|
||
def get_feedback_groups(self, *, timeout_secs: float = REQUESTS_TIMEOUT) -> tuple[frozenset[str], ...]: | ||
"""Retrieve groups of qubits that can receive real-time feedback signals from each other. | ||
Real-time feedback enables conditional gates such as `cc_prx`. | ||
Some hardware configurations support routing real-time feedback only between certain qubits. | ||
This method is only supported for the API variant V2. | ||
Returns: | ||
Feedback groups. Within a group, any qubit can receive real-time feedback from any other qubit in | ||
the same group. A qubit can belong to multiple groups. | ||
If there is only one group, there are no restrictions regarding feedback routing. | ||
Raises: | ||
ClientAuthenticationError: if no valid authentication is provided | ||
HTTPException: HTTP exceptions | ||
""" | ||
result = requests.get( | ||
self._api.url(APIEndpoint.CHANNEL_PROPERTIES), | ||
headers=self._default_headers(), | ||
timeout=timeout_secs, | ||
) | ||
self._check_authentication_errors(result) | ||
result.raise_for_status() | ||
try: | ||
channel_properties = result.json() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No model for channel properties like we have e.g. for DynamicQuantumArchitecture? |
||
except (json.decoder.JSONDecodeError, KeyError) as e: | ||
raise HTTPError(f'Invalid response: {result.text}, {e}') from e | ||
|
||
all_qubits = self.get_quantum_architecture().qubits | ||
groups: dict[str, set[str]] = {} | ||
# All qubits that can read from the same source belong to the same group. | ||
# A qubit may belong to multiple groups. | ||
for channel_name, properties in channel_properties.items(): | ||
# Relying on naming convention because we don't have proper mapping available: | ||
qubit = channel_name.split("__")[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I run |
||
if qubit not in all_qubits: | ||
continue | ||
for source in properties.get("fast_feedback_sources", ()): | ||
groups.setdefault(source, set()).add(qubit) | ||
# Merge identical groups | ||
unique_groups: set[frozenset[str]] = {frozenset(group) for group in groups.values()} | ||
Comment on lines
+928
to
+931
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's in the fast_feedback_sources? Why do we get identical groups? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Multiple probe lines per group? |
||
# Sort by group size | ||
return tuple(sorted(unique_groups, key=len, reverse=True)) | ||
|
||
def close_auth_session(self) -> bool: | ||
"""Terminate session with authentication server if there was one created. | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -26,6 +26,7 @@ | |||||||||||||||||||
|
||||||||||||||||||||
from iqm.iqm_client import ( | ||||||||||||||||||||
APIEndpoint, | ||||||||||||||||||||
APIVariant, | ||||||||||||||||||||
ArchitectureRetrievalError, | ||||||||||||||||||||
Circuit, | ||||||||||||||||||||
CircuitCompilationOptions, | ||||||||||||||||||||
|
@@ -588,6 +589,25 @@ def test_get_quantum_architecture( | |||||||||||||||||||
unstub() | ||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
def test_get_feedback_groups( | ||||||||||||||||||||
channel_properties_url, channel_properties_success, static_architecture_success | ||||||||||||||||||||
): | ||||||||||||||||||||
"""Test retrieving the feedback groups.""" | ||||||||||||||||||||
base_url = "https://example.com" | ||||||||||||||||||||
when(requests).get(f"{base_url}/info/client-libraries", headers=ANY, timeout=ANY).thenReturn( | ||||||||||||||||||||
Comment on lines
+593
to
+597
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not important, but a bit simpler and more consistent with the other tests:
Suggested change
|
||||||||||||||||||||
mock_supported_client_libraries_response() | ||||||||||||||||||||
) | ||||||||||||||||||||
expect(requests, times=1).get(f"{base_url}/cocos/quantum-architecture", ...).thenReturn( | ||||||||||||||||||||
static_architecture_success) | ||||||||||||||||||||
iqm_client = IQMClient(base_url, api_variant=APIVariant.V2) | ||||||||||||||||||||
expect(requests, times=1).get(channel_properties_url, ...).thenReturn(channel_properties_success) | ||||||||||||||||||||
|
||||||||||||||||||||
assert iqm_client.get_feedback_groups() == (frozenset({"QB1", "QB2"}), frozenset({"QB3"})) | ||||||||||||||||||||
|
||||||||||||||||||||
verifyNoUnwantedInteractions() | ||||||||||||||||||||
unstub() | ||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
def test_user_warning_is_emitted_when_warnings_in_response( | ||||||||||||||||||||
sample_client, existing_job_url, job_result_with_warnings, existing_run_id | ||||||||||||||||||||
): | ||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to get more helpful error message when trying to use this on a station which has older QCCSW version without the
channel-properties
endpoint.