-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix serde inconsistencies #2812
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
iamtrask
merged 6 commits into
OpenMined:master
from
vvmnnnkv:fix-serde-inconsistencies
Dec 16, 2019
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f026b76
Fix serde inconsistencies
e181902
Merge remote-tracking branch 'upstream/master' into fix-serde-inconsi…
8a54d51
Use describe() method to set description
22f4616
Merge branch 'master' into fix-serde-inconsistencies
iamtrask a0a6bd6
Make serde of ID to follow constructor or documentation
277162a
Merge branch 'master' into fix-serde-inconsistencies
gmuraru 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
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
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
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
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 |
|---|---|---|
|
|
@@ -74,16 +74,30 @@ def update_ids( | |
| from_worker: The previous worker that built the plan. | ||
| to_worker: The new worker that is running the plan. | ||
| """ | ||
|
|
||
| # We operate on simplified content of Operation, hence all values should be simplified | ||
| from_workers_simplified = None | ||
| to_workers_simplified = None | ||
| if from_worker and to_worker: | ||
| from_workers_simplified = [sy.serde._simplify(None, from_worker)] | ||
| to_workers_simplified = [sy.serde._simplify(None, to_worker)] | ||
|
|
||
| from_ids_simplified = None | ||
| to_ids_simplified = None | ||
| if len(from_ids) and len(to_ids): | ||
|
Member
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. Q: The same case as above for here
Member
Author
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. Same as above :) |
||
| from_ids_simplified = [sy.serde._simplify(None, id) for id in from_ids] | ||
| to_ids_simplified = [sy.serde._simplify(None, id) for id in to_ids] | ||
|
|
||
| for idx, operation in enumerate(self.operations): | ||
| if from_worker and to_worker: | ||
| from_workers, to_workers = [from_worker], [to_worker] | ||
| if isinstance(from_worker, str): | ||
| from_workers.append(from_worker.encode("utf-8")) | ||
| to_workers.append(to_worker) | ||
| operation = Procedure.replace_operation_ids(operation, from_workers, to_workers) | ||
| if from_workers_simplified and to_workers_simplified: | ||
| operation = Procedure.replace_operation_ids( | ||
| operation, from_workers_simplified, to_workers_simplified | ||
| ) | ||
|
|
||
| if len(from_ids) and len(to_ids): | ||
| operation = Procedure.replace_operation_ids(operation, from_ids, to_ids) | ||
| if from_ids_simplified and to_ids_simplified: | ||
| operation = Procedure.replace_operation_ids( | ||
| operation, from_ids_simplified, to_ids_simplified | ||
| ) | ||
|
|
||
| self.operations[idx] = operation | ||
|
|
||
|
|
@@ -106,7 +120,8 @@ def replace_operation_ids(operation, from_ids, to_ids): | |
| type_obj = type(operation) | ||
| operation = list(operation) | ||
| for i, item in enumerate(operation): | ||
| if isinstance(item, (int, str, bytes)) and item in from_ids: | ||
| # Since this is simplified content, id can be int or simplified str (tuple) | ||
| if isinstance(item, (int, tuple)) and item in from_ids: | ||
| operation[i] = to_ids[from_ids.index(item)] | ||
| elif isinstance(item, (list, tuple)): | ||
| operation[i] = Procedure.replace_operation_ids( | ||
|
|
@@ -125,9 +140,8 @@ def copy(self) -> "Procedure": | |
| @staticmethod | ||
| def simplify(worker: AbstractWorker, procedure: "Procedure") -> tuple: | ||
| return ( | ||
| tuple( | ||
| procedure.operations | ||
| ), # We're not simplifying because operations are already simplified | ||
| # We're not simplifying fully because operations are already simplified | ||
| sy.serde._simplify(worker, procedure.operations, shallow=True), | ||
| sy.serde._simplify(worker, procedure.arg_ids), | ||
| sy.serde._simplify(worker, procedure.result_ids), | ||
| sy.serde._simplify(worker, procedure.promise_out_id), | ||
|
|
@@ -136,7 +150,8 @@ def simplify(worker: AbstractWorker, procedure: "Procedure") -> tuple: | |
| @staticmethod | ||
| def detail(worker: AbstractWorker, procedure_tuple: tuple) -> "State": | ||
| operations, arg_ids, result_ids, promise_out_id = procedure_tuple | ||
| operations = list(operations) | ||
|
|
||
| operations = sy.serde._detail(worker, operations, shallow=True) | ||
| arg_ids = sy.serde._detail(worker, arg_ids) | ||
| result_ids = sy.serde._detail(worker, result_ids) | ||
|
|
||
|
|
||
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.
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.
Q: Will we always have
from_workerandto_worker. Is there any case only one is!= None?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.
I think replacement doesn't make sense when any of them are
None.This was existing code, I just moved it out of the loop to avoid making simplification each time.