Skip to content

Commit b9e87fa

Browse files
committed
[refactor] GroupRegistry with a Metaclass and class properties
1 parent 5ff87a9 commit b9e87fa

File tree

6 files changed

+220
-197
lines changed

6 files changed

+220
-197
lines changed

examples/custom_group.ipynb

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 15,
5+
"execution_count": 1,
66
"metadata": {},
77
"outputs": [],
88
"source": [
@@ -11,7 +11,7 @@
1111
"import numpy as np\n",
1212
"from rich.pretty import pprint\n",
1313
"\n",
14-
"from oqd_dataschema.base import Dataset, Group, GroupRegistry\n",
14+
"from oqd_dataschema.base import Dataset, GroupBase, GroupRegistry\n",
1515
"from oqd_dataschema.datastore import Datastore\n",
1616
"from oqd_dataschema.groups import (\n",
1717
" SinaraRawDataGroup,\n",
@@ -20,20 +20,11 @@
2020
},
2121
{
2222
"cell_type": "code",
23-
"execution_count": null,
23+
"execution_count": 2,
2424
"metadata": {},
25-
"outputs": [
26-
{
27-
"name": "stderr",
28-
"output_type": "stream",
29-
"text": [
30-
"/Users/benjamin/Desktop/1 - Projects/Open Quantum Design/repos/oqd-dataschema/src/oqd_dataschema/base.py:66: UserWarning: Group type 'YourCustomGroup' is already registered. Overwriting <class '__main__.YourCustomGroup'> with <class '__main__.YourCustomGroup'>.\n",
31-
" GroupRegistry.register(cls)\n"
32-
]
33-
}
34-
],
25+
"outputs": [],
3526
"source": [
36-
"class YourCustomGroup(Group):\n",
27+
"class YourCustomGroup(GroupBase):\n",
3728
" \"\"\"\n",
3829
" Here we define a custom Group, which is automatically added at runtime to the GroupRegistry.\n",
3930
" \"\"\"\n",
@@ -43,31 +34,31 @@
4334
},
4435
{
4536
"cell_type": "code",
46-
"execution_count": 18,
37+
"execution_count": 3,
4738
"metadata": {},
4839
"outputs": [
4940
{
5041
"data": {
5142
"text/plain": [
52-
"['SinaraRawDataGroup',\n",
53-
" 'MeasurementOutcomesDataGroup',\n",
54-
" 'ExpectationValueDataGroup',\n",
55-
" 'OQDTestbenchDataGroup',\n",
56-
" 'YourCustomGroup']"
43+
"{'SinaraRawDataGroup': oqd_dataschema.groups.SinaraRawDataGroup,\n",
44+
" 'MeasurementOutcomesDataGroup': oqd_dataschema.groups.MeasurementOutcomesDataGroup,\n",
45+
" 'ExpectationValueDataGroup': oqd_dataschema.groups.ExpectationValueDataGroup,\n",
46+
" 'OQDTestbenchDataGroup': oqd_dataschema.groups.OQDTestbenchDataGroup,\n",
47+
" 'YourCustomGroup': __main__.YourCustomGroup}"
5748
]
5849
},
59-
"execution_count": 18,
50+
"execution_count": 3,
6051
"metadata": {},
6152
"output_type": "execute_result"
6253
}
6354
],
6455
"source": [
65-
"GroupRegistry.list_types()"
56+
"GroupRegistry.groups"
6657
]
6758
},
6859
{
6960
"cell_type": "code",
70-
"execution_count": 11,
61+
"execution_count": 4,
7162
"metadata": {},
7263
"outputs": [],
7364
"source": [
@@ -82,7 +73,7 @@
8273
},
8374
{
8475
"cell_type": "code",
85-
"execution_count": 13,
76+
"execution_count": 5,
8677
"metadata": {},
8778
"outputs": [
8879
{
@@ -193,7 +184,7 @@
193184
},
194185
{
195186
"cell_type": "code",
196-
"execution_count": 14,
187+
"execution_count": 6,
197188
"metadata": {},
198189
"outputs": [
199190
{
@@ -321,7 +312,7 @@
321312
"name": "python",
322313
"nbconvert_exporter": "python",
323314
"pygments_lexer": "ipython3",
324-
"version": "3.12.1"
315+
"version": "3.13.2"
325316
}
326317
},
327318
"nbformat": 4,

0 commit comments

Comments
 (0)