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

Temporary fix of PA Notebook #334

Closed
wants to merge 1 commit into from
Closed
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
112 changes: 82 additions & 30 deletions docs/source/examples/02 Intro to Physical Architecture API.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"id": "4c181cfb",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -43,7 +43,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 2,
"id": "1386d2f7",
"metadata": {
"scrolled": true
Expand Down Expand Up @@ -78,7 +78,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 3,
"id": "8b555976",
"metadata": {
"scrolled": false
Expand Down Expand Up @@ -113,7 +113,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 4,
"id": "711574aa",
"metadata": {
"scrolled": true
Expand Down Expand Up @@ -163,7 +163,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 5,
"id": "21ef5c4d",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -197,7 +197,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 6,
"id": "63ff286c",
"metadata": {},
"outputs": [],
Expand All @@ -221,7 +221,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 7,
"id": "6d8ff25c",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -434,38 +434,54 @@
"\n",
"Now lets assume that components of node nature are hardware things and behavior corresponds to software components. Assuming that lets identify leaf hardware components (lowest replaceable units) and for each of those indicate which software components they have.\n",
"\n",
"To get there lets first filter out the list of components of Node nature that have at least on subcomponent of Behavior nature. To get to the end result quicker we'll use the `._filter` method of our object list. To use that method we'll need to provide a function that selects attribute of interest and a value (or list of values) that this attribute should have to be selected. To shorten the expression we'll use `lambda` functions - a way to define new function in place."
"To get there lets first filter out the list of components of Node nature that have at least on subcomponent of Behavior nature. To get to the end result quicker we'll use the `._filter` method of our object list (using python built-in filter method for now). To use that method we'll need to provide a function that selects attribute of interest and a value (or list of values) that this attribute should have to be selected. To shorten the expression we'll use `lambda` functions - a way to define new function in place."
]
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 63,
"id": "01644c9d",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<ol start=\"0\" style=\"text-align: left;\"><li><strong>PhysicalComponent</strong> &quot;Sub PC&quot; (793e6da2-d019-4716-a5c5-af8ad550ca5e)</li><li><strong>PhysicalComponent</strong> &quot;Deploy Sub PC&quot; (8a6c6ec9-095d-4d8b-9728-69bc79af5f27)</li><li><strong>PhysicalComponent</strong> &quot;Compute Card 1&quot; (63be604e-883e-41ea-9023-fc74f29906fe)</li><li><strong>PhysicalComponent</strong> &quot;Compute Card 2&quot; (3a982128-3281-4d37-8838-a6058b7a25d9)</li><li><strong>PhysicalComponent</strong> &quot;Network Switch&quot; (b51ccc6f-5f96-4e28-b90e-72463a3b50cf)</li><li><strong>PhysicalComponent</strong> &quot;Camera Assembly&quot; (5bfc516b-c20d-4007-9a38-5ba0e889d0a4)</li></ol>"
"<ol start=\"0\" style=\"text-align: left;\"><li><strong>PhysicalComponent</strong> &quot;Sub PC&quot; (793e6da2-d019-4716-a5c5-af8ad550ca5e)</li><li><strong>PhysicalComponent</strong> &quot;Deploy Sub PC&quot; (8a6c6ec9-095d-4d8b-9728-69bc79af5f27)</li><li><strong>PhysicalComponent</strong> &quot;Compute Card 1&quot; (63be604e-883e-41ea-9023-fc74f29906fe)</li><li><strong>PhysicalComponent</strong> &quot;Compute Card 2&quot; (3a982128-3281-4d37-8838-a6058b7a25d9)</li><li><strong>PhysicalComponent</strong> &quot;Network Switch&quot; (b51ccc6f-5f96-4e28-b90e-72463a3b50cf)</li><li><strong>PhysicalComponent</strong> &quot;Camera Assembly&quot; (5bfc516b-c20d-4007-9a38-5ba0e889d0a4)</li><li><strong>PhysicalComponent</strong> &quot;Computer&quot; (b14ff190-9198-4d05-95db-b121c11e9f17)</li><li><strong>PhysicalComponent</strong> &quot;ISP Network&quot; (221cef9f-0582-419c-b67e-96ddb678dd4c)</li></ol>"
],
"text/plain": [
"<ElementList at 0x00007F0728631210 [<PhysicalComponent 'Sub PC' (793e6da2-d019-4716-a5c5-af8ad550ca5e)>, <PhysicalComponent 'Deploy Sub PC' (8a6c6ec9-095d-4d8b-9728-69bc79af5f27)>, <PhysicalComponent 'Compute Card 1' (63be604e-883e-41ea-9023-fc74f29906fe)>, <PhysicalComponent 'Compute Card 2' (3a982128-3281-4d37-8838-a6058b7a25d9)>, <PhysicalComponent 'Network Switch' (b51ccc6f-5f96-4e28-b90e-72463a3b50cf)>, <PhysicalComponent 'Camera Assembly' (5bfc516b-c20d-4007-9a38-5ba0e889d0a4)>]>"
"[0] <PhysicalComponent 'Sub PC' (793e6da2-d019-4716-a5c5-af8ad550ca5e)>\n",
"[1] <PhysicalComponent 'Deploy Sub PC' (8a6c6ec9-095d-4d8b-9728-69bc79af5f27)>\n",
"[2] <PhysicalComponent 'Compute Card 1' (63be604e-883e-41ea-9023-fc74f29906fe)>\n",
"[3] <PhysicalComponent 'Compute Card 2' (3a982128-3281-4d37-8838-a6058b7a25d9)>\n",
"[4] <PhysicalComponent 'Network Switch' (b51ccc6f-5f96-4e28-b90e-72463a3b50cf)>\n",
"[5] <PhysicalComponent 'Camera Assembly' (5bfc516b-c20d-4007-9a38-5ba0e889d0a4)>\n",
"[6] <PhysicalComponent 'Computer' (b14ff190-9198-4d05-95db-b121c11e9f17)>\n",
"[7] <PhysicalComponent 'ISP Network' (221cef9f-0582-419c-b67e-96ddb678dd4c)>"
]
},
"execution_count": 19,
"execution_count": 63,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from capellambse.model.common import ElementList\n",
"\n",
"def select_nature(component):\n",
" return component.nature\n",
"\n",
"#cmps_with_sw = cmps._filter(lambda x: any(x.components._filter(select_nature, \"BEHAVIOR\")), True)\n",
"\n",
"cmps = model.pa.all_components[1:]._filter(select_nature, \"NODE\")\n",
"cmps = model.pa.all_components[1:].by_nature(\"NODE\")\n",
"# Note: the above [1:] assumes that 0th component is the root component and is not of interest (+ see issue #41)\n",
"cmps_with_sw = cmps._filter(lambda x: any(x.components._filter(select_nature, \"BEHAVIOR\")), True)\n",
"cmps_with_sw"
"\n",
"l_cmps = list(cmps)\n",
"l_cmps_with_sw = list(filter(lambda x: any(x.components.by_nature(\"BEHAVIOR\")), l_cmps))\n",
"cmps_with_sw = ElementList(model, [])\n",
"for elem in l_cmps_with_sw:\n",
" cmps_with_sw.append(elem)\n",
"cmps_with_sw\n",
"\n"
]
},
{
Expand All @@ -480,7 +496,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 64,
"id": "70abf6f9",
"metadata": {},
"outputs": [
Expand All @@ -490,17 +506,17 @@
"<ol start=\"0\" style=\"text-align: left;\"><li><strong>PhysicalComponent</strong> &quot;PC 16&quot; (8bc4b7a6-1f90-4f5f-a6b4-08fd300fc927)</li></ol>"
],
"text/plain": [
"<ElementList at 0x00007F0754EE80E0 [<PhysicalComponent 'PC 16' (8bc4b7a6-1f90-4f5f-a6b4-08fd300fc927)>]>"
"[0] <PhysicalComponent 'PC 16' (8bc4b7a6-1f90-4f5f-a6b4-08fd300fc927)>"
]
},
"execution_count": 20,
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def get_sw_components(sw_component):\n",
" subcmp = sw_component.components._filter(select_nature, \"BEHAVIOR\")\n",
" subcmp = sw_component.components.by_nature(\"BEHAVIOR\")\n",
" for cmp in subcmp:\n",
" subcmp += get_sw_components(cmp)\n",
" return subcmp\n",
Expand All @@ -518,7 +534,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 65,
"id": "faa00eb0",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -578,6 +594,16 @@
" <td>Camera Assembly</td>\n",
" <td>Camera Firmware</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Computer</td>\n",
" <td>Mail client</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>ISP Network</td>\n",
" <td>Mail server</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
Expand All @@ -589,10 +615,12 @@
"2 Compute Card 1 Card 1 OS; Camera Driver SWC; App 1 SWC\n",
"3 Compute Card 2 Card 2 OS; App 2 SWC\n",
"4 Network Switch Switch Firmware; Switch Configuration\n",
"5 Camera Assembly Camera Firmware"
"5 Camera Assembly Camera Firmware\n",
"6 Computer Mail client\n",
"7 ISP Network Mail server"
]
},
"execution_count": 21,
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -618,35 +646,59 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 67,
"id": "e48d4998",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<ol start=\"0\" style=\"text-align: left;\"><li><strong>PhysicalComponent</strong> &quot;PC 1&quot; (8a6d68c8-ac3d-4654-a07e-ada7adeed09f)</li><li><strong>PhysicalComponent</strong> &quot;PC 3&quot; (f5d7980d-e1e9-4515-8bb0-be7e80ac5839)</li><li><strong>PhysicalComponent</strong> &quot;Vehicle&quot; (a2c7f619-b38a-4b92-94a5-cbaa631badfc)</li><li><strong>PhysicalComponent</strong> &quot;Vehicle&quot; (b327d900-abd2-4138-a111-9ff0684739d8)</li><li><strong>PhysicalComponent</strong> &quot;Equipment compartment&quot; (3d68852d-fcc0-452c-af12-a2fbe22f81fa)</li><li><strong>PhysicalComponent</strong> &quot;Server&quot; (9137f463-7497-40c2-b20a-897158fdba9a)</li><li><strong>PhysicalComponent</strong> &quot;Cooling Fan&quot; (65e82f3f-c5b7-44c1-bfea-8e20bb0230be)</li><li><strong>PhysicalComponent</strong> &quot;Sensor compartment&quot; (3f416925-9d8a-4e9c-99f3-e912efb23d2f)</li><li><strong>PhysicalComponent</strong> &quot;PA 1&quot; (a0847e9c-8b82-407d-8143-e908e2db97a1)</li></ol>"
"<ol start=\"0\" style=\"text-align: left;\"><li><strong>PhysicalComponent</strong> &quot;PC 1&quot; (8a6d68c8-ac3d-4654-a07e-ada7adeed09f)</li><li><strong>PhysicalComponent</strong> &quot;PC 3&quot; (f5d7980d-e1e9-4515-8bb0-be7e80ac5839)</li><li><strong>PhysicalComponent</strong> &quot;Vehicle&quot; (a2c7f619-b38a-4b92-94a5-cbaa631badfc)</li><li><strong>PhysicalComponent</strong> &quot;Vehicle&quot; (b327d900-abd2-4138-a111-9ff0684739d8)</li><li><strong>PhysicalComponent</strong> &quot;Equipment compartment&quot; (3d68852d-fcc0-452c-af12-a2fbe22f81fa)</li><li><strong>PhysicalComponent</strong> &quot;Server&quot; (9137f463-7497-40c2-b20a-897158fdba9a)</li><li><strong>PhysicalComponent</strong> &quot;Cooling Fan&quot; (65e82f3f-c5b7-44c1-bfea-8e20bb0230be)</li><li><strong>PhysicalComponent</strong> &quot;Sensor compartment&quot; (3f416925-9d8a-4e9c-99f3-e912efb23d2f)</li><li><strong>PhysicalComponent</strong> &quot;Router&quot; (69bfe48d-78f0-4b1f-89c0-917dc2339ff9)</li><li><strong>PhysicalComponent</strong> &quot;PA 1&quot; (a0847e9c-8b82-407d-8143-e908e2db97a1)</li></ol>"
],
"text/plain": [
"<ElementList at 0x00007F0754EE8FE0 [<PhysicalComponent 'PC 1' (8a6d68c8-ac3d-4654-a07e-ada7adeed09f)>, <PhysicalComponent 'PC 3' (f5d7980d-e1e9-4515-8bb0-be7e80ac5839)>, <PhysicalComponent 'Vehicle' (a2c7f619-b38a-4b92-94a5-cbaa631badfc)>, <PhysicalComponent 'Vehicle' (b327d900-abd2-4138-a111-9ff0684739d8)>, <PhysicalComponent 'Equipment compartment' (3d68852d-fcc0-452c-af12-a2fbe22f81fa)>, <PhysicalComponent 'Server' (9137f463-7497-40c2-b20a-897158fdba9a)>, <PhysicalComponent 'Cooling Fan' (65e82f3f-c5b7-44c1-bfea-8e20bb0230be)>, <PhysicalComponent 'Sensor compartment' (3f416925-9d8a-4e9c-99f3-e912efb23d2f)>, <PhysicalComponent 'PA 1' (a0847e9c-8b82-407d-8143-e908e2db97a1)>]>"
"[0] <PhysicalComponent 'PC 1' (8a6d68c8-ac3d-4654-a07e-ada7adeed09f)>\n",
"[1] <PhysicalComponent 'PC 3' (f5d7980d-e1e9-4515-8bb0-be7e80ac5839)>\n",
"[2] <PhysicalComponent 'Vehicle' (a2c7f619-b38a-4b92-94a5-cbaa631badfc)>\n",
"[3] <PhysicalComponent 'Vehicle' (b327d900-abd2-4138-a111-9ff0684739d8)>\n",
"[4] <PhysicalComponent 'Equipment compartment' (3d68852d-fcc0-452c-af12-a2fbe22f81fa)>\n",
"[5] <PhysicalComponent 'Server' (9137f463-7497-40c2-b20a-897158fdba9a)>\n",
"[6] <PhysicalComponent 'Cooling Fan' (65e82f3f-c5b7-44c1-bfea-8e20bb0230be)>\n",
"[7] <PhysicalComponent 'Sensor compartment' (3f416925-9d8a-4e9c-99f3-e912efb23d2f)>\n",
"[8] <PhysicalComponent 'Router' (69bfe48d-78f0-4b1f-89c0-917dc2339ff9)>\n",
"[9] <PhysicalComponent 'PA 1' (a0847e9c-8b82-407d-8143-e908e2db97a1)>"
]
},
"execution_count": 22,
"execution_count": 67,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cmps_without_sw = cmps._filter(lambda x: any(x.components._filter(select_nature, \"BEHAVIOR\")), False)\n",
"#cmps_without_sw = cmps._filter(lambda x: any(x.components._filter(select_nature, \"BEHAVIOR\")), False)\n",
"cmps_without_sw = ElementList(model, [])\n",
"\n",
"l_cmps_without_sw = list(filter(lambda x: not any(x.components.by_nature(\"BEHAVIOR\")), l_cmps))\n",
"\n",
"for elem in l_cmps_without_sw:\n",
" cmps_without_sw.append(elem)\n",
"\n",
"cmps_without_sw"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "86b58bc7-bbd7-4f19-8437-0c48c47c8f29",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "venv"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -658,7 +710,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down