-
Notifications
You must be signed in to change notification settings - Fork 108
Avoid mutating input parameters during target submission #745
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
23e4d1f
shallow copy of input_params
s-ddavydenko 6f1dc1d
deep_copy
s-ddavydenko fce7460
unit test
s-ddavydenko ea00de4
nested structure unit test
s-ddavydenko 8c175ba
move unit test to its own file
s-ddavydenko d8bb73e
Merge branch 'main' into main
s-ddavydenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,53 @@ | ||
| ## | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| ## | ||
|
|
||
| import copy | ||
| from unittest import mock | ||
| from azure.quantum.target.target import Target | ||
|
|
||
| from mock_client import WorkspaceMock | ||
| from common import ( | ||
| SUBSCRIPTION_ID, | ||
| RESOURCE_GROUP, | ||
| WORKSPACE, | ||
| ) | ||
|
|
||
| def test_target_submit_does_not_mutate_input_params(): | ||
| ws = WorkspaceMock( | ||
| subscription_id=SUBSCRIPTION_ID, | ||
| resource_group=RESOURCE_GROUP, | ||
| name=WORKSPACE, | ||
| ) | ||
| target = Target( | ||
| workspace=ws, | ||
| name="fake.target", | ||
| provider_id="fake-provider", | ||
| input_data_format="fake-input-format", | ||
| output_data_format="fake-output-format", | ||
| ) | ||
| input_params = { | ||
| "someOption": "someValue", | ||
| "nested": { | ||
| "innerOption": "innerValue", | ||
| "list": [1, 2, 3], | ||
| }, | ||
| } | ||
| original = copy.deepcopy(input_params) | ||
|
|
||
| with mock.patch( | ||
| "azure.quantum.job.base_job.BaseJob.upload_input_data", | ||
| return_value="https://example.com/blob", | ||
| ): | ||
| target.submit( | ||
| name="test-job", | ||
| shots=10, | ||
| input_data=b"fake-ir", | ||
| input_params=input_params, | ||
| ) | ||
|
|
||
| assert input_params == original | ||
| assert "shots" not in input_params | ||
| assert input_params["nested"]["innerOption"] == "innerValue" | ||
| assert input_params["nested"]["list"] == [1, 2, 3] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.