Skip to content

Commit 225e10b

Browse files
authored
Merge branch 'dev' into padawan-contrib-10
2 parents dd47228 + 259f67d commit 225e10b

15 files changed

Lines changed: 270 additions & 87 deletions

File tree

notebooks/tutorials/version-upgrades/0-prepare-migration-data.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969
" name=\"test_upgradability\",\n",
7070
" dev_mode=True,\n",
7171
" reset=True,\n",
72-
" local_db=True,\n",
7372
" n_consumers=2,\n",
7473
" create_producer=True,\n",
74+
" port=\"auto\",\n",
7575
")"
7676
]
7777
},
@@ -251,7 +251,7 @@
251251
"name": "python",
252252
"nbconvert_exporter": "python",
253253
"pygments_lexer": "ipython3",
254-
"version": "3.12.2"
254+
"version": "3.10.13"
255255
}
256256
},
257257
"nbformat": 4,

notebooks/tutorials/version-upgrades/1-dump-database-to-file.ipynb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"outputs": [],
99
"source": [
1010
"# stdlib\n",
11+
"import os\n",
1112
"from pathlib import Path\n",
1213
"\n",
1314
"# syft absolute\n",
@@ -24,9 +25,8 @@
2425
"server = sy.orchestra.launch(\n",
2526
" name=\"test_upgradability\",\n",
2627
" dev_mode=True,\n",
27-
" local_db=True,\n",
28-
" n_consumers=2,\n",
29-
" create_producer=True,\n",
28+
" reset=False,\n",
29+
" port=\"auto\",\n",
3030
" migrate=False,\n",
3131
")\n",
3232
"\n",
@@ -83,8 +83,11 @@
8383
"metadata": {},
8484
"outputs": [],
8585
"source": [
86-
"blob_path = Path(\"./migration.blob\")\n",
87-
"yaml_path = Path(\"migration.yaml\")\n",
86+
"migration_data_dir = Path(os.getenv(\"MIGRATION_DATA_DIR\", \".\"))\n",
87+
"migration_data_dir.mkdir(exist_ok=True)\n",
88+
"\n",
89+
"blob_path = migration_data_dir / \"migration.blob\"\n",
90+
"yaml_path = migration_data_dir / \"migration.yaml\"\n",
8891
"\n",
8992
"blob_path.unlink(missing_ok=True)\n",
9093
"yaml_path.unlink(missing_ok=True)"
@@ -141,7 +144,7 @@
141144
"name": "python",
142145
"nbconvert_exporter": "python",
143146
"pygments_lexer": "ipython3",
144-
"version": "3.12.2"
147+
"version": "3.10.13"
145148
}
146149
},
147150
"nbformat": 4,

notebooks/tutorials/version-upgrades/2-migrate-from-file.ipynb

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"outputs": [],
99
"source": [
1010
"# stdlib\n",
11+
"import os\n",
1112
"from pathlib import Path\n",
1213
"\n",
1314
"# syft absolute\n",
@@ -70,16 +71,37 @@
7071
"metadata": {},
7172
"outputs": [],
7273
"source": [
73-
"blob_path = Path(\"./migration.blob\")\n",
74-
"print(f\"Loading migration data from {str(blob_path.resolve())}\")\n",
74+
"migration_data_dir = Path(os.getenv(\"MIGRATION_DATA_DIR\", \".\"))\n",
75+
"blob_path = migration_data_dir / \"migration.blob\"\n",
76+
"yaml_path = migration_data_dir / \"migration.yaml\"\n",
7577
"\n",
78+
"print(f\"Loading migration data from {str(blob_path.resolve())}\")"
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": null,
84+
"id": "6",
85+
"metadata": {},
86+
"outputs": [],
87+
"source": [
7688
"res = client.load_migration_data(blob_path)\n",
77-
"assert isinstance(res, sy.SyftSuccess)"
89+
"assert isinstance(res, sy.SyftSuccess), res.message"
90+
]
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": null,
95+
"id": "7",
96+
"metadata": {},
97+
"outputs": [],
98+
"source": [
99+
"res"
78100
]
79101
},
80102
{
81103
"cell_type": "markdown",
82-
"id": "6",
104+
"id": "8",
83105
"metadata": {},
84106
"source": [
85107
"# Post migration tests"
@@ -88,7 +110,7 @@
88110
{
89111
"cell_type": "code",
90112
"execution_count": null,
91-
"id": "7",
113+
"id": "9",
92114
"metadata": {},
93115
"outputs": [],
94116
"source": [
@@ -98,7 +120,7 @@
98120
{
99121
"cell_type": "code",
100122
"execution_count": null,
101-
"id": "8",
123+
"id": "10",
102124
"metadata": {},
103125
"outputs": [],
104126
"source": [
@@ -108,15 +130,15 @@
108130
{
109131
"cell_type": "code",
110132
"execution_count": null,
111-
"id": "9",
133+
"id": "11",
112134
"metadata": {},
113135
"outputs": [],
114136
"source": []
115137
},
116138
{
117139
"cell_type": "code",
118140
"execution_count": null,
119-
"id": "10",
141+
"id": "12",
120142
"metadata": {},
121143
"outputs": [],
122144
"source": [
@@ -127,7 +149,7 @@
127149
{
128150
"cell_type": "code",
129151
"execution_count": null,
130-
"id": "11",
152+
"id": "13",
131153
"metadata": {},
132154
"outputs": [],
133155
"source": [
@@ -137,7 +159,7 @@
137159
{
138160
"cell_type": "code",
139161
"execution_count": null,
140-
"id": "12",
162+
"id": "14",
141163
"metadata": {},
142164
"outputs": [],
143165
"source": [
@@ -147,7 +169,7 @@
147169
{
148170
"cell_type": "code",
149171
"execution_count": null,
150-
"id": "13",
172+
"id": "15",
151173
"metadata": {},
152174
"outputs": [],
153175
"source": [
@@ -157,7 +179,7 @@
157179
{
158180
"cell_type": "code",
159181
"execution_count": null,
160-
"id": "14",
182+
"id": "16",
161183
"metadata": {},
162184
"outputs": [],
163185
"source": [
@@ -171,7 +193,7 @@
171193
{
172194
"cell_type": "code",
173195
"execution_count": null,
174-
"id": "15",
196+
"id": "17",
175197
"metadata": {},
176198
"outputs": [],
177199
"source": [
@@ -182,7 +204,7 @@
182204
{
183205
"cell_type": "code",
184206
"execution_count": null,
185-
"id": "16",
207+
"id": "18",
186208
"metadata": {},
187209
"outputs": [],
188210
"source": [
@@ -193,7 +215,7 @@
193215
{
194216
"cell_type": "code",
195217
"execution_count": null,
196-
"id": "17",
218+
"id": "19",
197219
"metadata": {},
198220
"outputs": [],
199221
"source": [
@@ -203,7 +225,7 @@
203225
{
204226
"cell_type": "code",
205227
"execution_count": null,
206-
"id": "18",
228+
"id": "20",
207229
"metadata": {},
208230
"outputs": [],
209231
"source": [
@@ -213,7 +235,7 @@
213235
{
214236
"cell_type": "code",
215237
"execution_count": null,
216-
"id": "19",
238+
"id": "21",
217239
"metadata": {},
218240
"outputs": [],
219241
"source": [
@@ -223,7 +245,7 @@
223245
{
224246
"cell_type": "code",
225247
"execution_count": null,
226-
"id": "20",
248+
"id": "22",
227249
"metadata": {},
228250
"outputs": [],
229251
"source": [
@@ -233,7 +255,7 @@
233255
{
234256
"cell_type": "code",
235257
"execution_count": null,
236-
"id": "21",
258+
"id": "23",
237259
"metadata": {},
238260
"outputs": [],
239261
"source": [
@@ -243,7 +265,7 @@
243265
{
244266
"cell_type": "code",
245267
"execution_count": null,
246-
"id": "22",
268+
"id": "24",
247269
"metadata": {},
248270
"outputs": [],
249271
"source": [
@@ -254,7 +276,7 @@
254276
{
255277
"cell_type": "code",
256278
"execution_count": null,
257-
"id": "23",
279+
"id": "25",
258280
"metadata": {},
259281
"outputs": [],
260282
"source": [
@@ -265,7 +287,7 @@
265287
{
266288
"cell_type": "code",
267289
"execution_count": null,
268-
"id": "24",
290+
"id": "26",
269291
"metadata": {},
270292
"outputs": [],
271293
"source": []
@@ -287,7 +309,7 @@
287309
"name": "python",
288310
"nbconvert_exporter": "python",
289311
"pygments_lexer": "ipython3",
290-
"version": "3.12.2"
312+
"version": "3.10.13"
291313
}
292314
},
293315
"nbformat": 4,

packages/syft/src/syft/service/code/user_code.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,8 @@ def assets(self) -> DictTuple[str, Asset] | SyftError:
724724
all_inputs = {}
725725
inputs = self.input_policy_init_kwargs or {}
726726
for vals in inputs.values():
727-
all_inputs.update(vals)
727+
# Only keep UIDs, filter out Constants
728+
all_inputs.update({k: v for k, v in vals.items() if isinstance(v, UID)})
728729

729730
# map the action_id to the asset
730731
used_assets: list[Asset] = []
@@ -753,20 +754,47 @@ def action_objects(self) -> dict:
753754
action_objects = {
754755
arg_name: str(uid)
755756
for arg_name, uid in all_inputs.items()
756-
if arg_name not in self.assets.keys()
757+
if arg_name not in self.assets.keys() and isinstance(uid, UID)
757758
}
758759

759760
return action_objects
760761

762+
@property
763+
def constants(self) -> dict[str, Constant]:
764+
if not self.input_policy_init_kwargs:
765+
return {}
766+
767+
all_inputs = {}
768+
for vals in self.input_policy_init_kwargs.values():
769+
all_inputs.update(vals)
770+
771+
# filter out the assets
772+
constants = {
773+
arg_name: item
774+
for arg_name, item in all_inputs.items()
775+
if isinstance(item, Constant)
776+
}
777+
778+
return constants
779+
761780
@property
762781
def inputs(self) -> dict:
763782
inputs = {}
764-
if self.action_objects:
765-
inputs["action_objects"] = self.action_objects
766-
if self.assets:
783+
784+
assets = self.assets
785+
action_objects = self.action_objects
786+
constants = self.constants
787+
if action_objects:
788+
inputs["action_objects"] = action_objects
789+
if assets:
767790
inputs["assets"] = {
768791
argument: asset._get_dict_for_user_code_repr()
769-
for argument, asset in self.assets.items()
792+
for argument, asset in assets.items()
793+
}
794+
if self.constants:
795+
inputs["constants"] = {
796+
argument: constant._get_dict_for_user_code_repr()
797+
for argument, constant in constants.items()
770798
}
771799
return inputs
772800

packages/syft/src/syft/service/dataset/dataset.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from ...util.misc_objs import MarkdownDescription
3939
from ...util.notebook_ui.icons import Icon
4040
from ...util.table import itable_template_from_df
41+
from ...util.util import repr_truncation
4142
from ..action.action_data_empty import ActionDataEmpty
4243
from ..action.action_object import ActionObject
4344
from ..data_subject.data_subject import DataSubject
@@ -135,19 +136,26 @@ def _repr_html_(self) -> Any:
135136
if isinstance(private_data_obj, ActionObject):
136137
df = pd.DataFrame(self.data.syft_action_data)
137138
data_table_line = itable_template_from_df(df=private_data_obj.head(5))
138-
139139
elif isinstance(private_data_obj, pd.DataFrame):
140140
data_table_line = itable_template_from_df(df=private_data_obj.head(5))
141141
else:
142-
data_table_line = private_data_res.ok_value
142+
try:
143+
data_table_line = repr_truncation(private_data_obj)
144+
except Exception as e:
145+
logger.debug(f"Failed to truncate private data repr. {e}")
146+
data_table_line = private_data_res.ok_value
143147

144148
if isinstance(self.mock, ActionObject):
145149
df = pd.DataFrame(self.mock.syft_action_data)
146150
mock_table_line = itable_template_from_df(df=df.head(5))
147151
elif isinstance(self.mock, pd.DataFrame):
148152
mock_table_line = itable_template_from_df(df=self.mock.head(5))
149153
else:
150-
mock_table_line = self.mock
154+
try:
155+
mock_table_line = repr_truncation(self.mock)
156+
except Exception as e:
157+
logger.debug(f"Failed to truncate mock data repr. {e}")
158+
mock_table_line = self.mock
151159
if isinstance(mock_table_line, SyftError):
152160
mock_table_line = mock_table_line.message
153161

packages/syft/src/syft/service/job/job_stash.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ def check_user_code_id(self) -> Self:
156156

157157
@property
158158
def result_id(self) -> UID | None:
159-
if self.result is None:
160-
return None
161-
return self.result.id.id
159+
if isinstance(self.result, ActionObject):
160+
return self.result.id.id
161+
return None
162162

163163
@property
164164
def action_display_name(self) -> str:

0 commit comments

Comments
 (0)