Quam classes
ParentDescriptor
Descriptor for the parent attribute of QuamBase.
This descriptor is used to ensure that the parent attribute of a QuamBase object is not overwritten. This is to prevent the following situation:
parent1 = QuamBase()
parent2 = QuamBase()
child = QuamBase()
child.parent = parent1 # This is fine
child.parent = parent2 # This raises an AttributeError
Source code in quam/core/quam_classes.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
QuamBase
Bases: ReferenceClass
Base class for any QuAM component class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent
|
The parent of this object. This is automatically set when adding this object to another QuamBase object. |
required | |
_root
|
The QuamRoot object. This is automatically set when instantiating a QuamRoot object. |
required | |
config_settings
|
A dictionary of configuration settings for this object.
This is used by |
required |
Note
This class should not be used directly, but should generally be subclassed. The subclasses should be dataclasses.
Source code in quam/core/quam_classes.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
|
get_attr_name(attr_val)
Get the name of an attribute that matches the value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr_val
|
Any
|
The value of the attribute. |
required |
Returns:
Type | Description |
---|---|
str
|
The name of the attribute. |
Source code in quam/core/quam_classes.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
|
get_attrs(follow_references=False, include_defaults=True)
Get all attributes and corresponding values of this object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
follow_references
|
bool
|
Whether to follow references when getting the value. If False, the reference will be returned as a string. |
False
|
include_defaults
|
bool
|
Whether to include attributes that have the default value. |
True
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
A dictionary of attribute names and values. |
Source code in quam/core/quam_classes.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
|
get_reference(attr=None)
Get the reference path of this object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr
|
The attribute to get the reference path for. If None, the reference path of the object itself is returned. |
None
|
Returns:
Type | Description |
---|---|
Optional[str]
|
The reference path of this object. |
Source code in quam/core/quam_classes.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
|
iterate_components(skip_elems=None)
Iterate over all QuamBase objects in this object, including nested objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
skip_elems
|
bool
|
A list of QuamBase objects to skip. This is used to prevent infinite loops when iterating over nested objects. |
None
|
Returns:
Type | Description |
---|---|
None
|
A generator of QuamBase objects. |
Source code in quam/core/quam_classes.py
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
|
print_summary(indent=0)
Print a summary of the QuamBase object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indent
|
int
|
The number of spaces to indent the summary. |
0
|
Source code in quam/core/quam_classes.py
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
|
to_dict(follow_references=False, include_defaults=False)
Convert this object to a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
follow_references
|
bool
|
Whether to follow references when getting the value. If False, the reference will be returned as a string. |
False
|
include_defaults
|
bool
|
Whether to include attributes that have the default |
False
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
A dictionary representation of this object. |
Dict[str, Any]
|
Any QuamBase objects will be recursively converted to dictionaries. |
Note
If the value of an attribute does not match the annotation, the
"__class__"
key will be added to the dictionary. This is to ensure
that the object can be reconstructed when loading from a file.
Source code in quam/core/quam_classes.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
|
QuamComponent
Bases: QuamBase
Base class for any QuAM component class.
Examples of QuamComponent classes are Mixer
,
LocalOscillator
,
Pulse
, etc.
Note
This class should be subclassed and made a dataclass.
Source code in quam/core/quam_classes.py
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 |
|
apply_to_config(config)
Add information to the QUA configuration, such as pulses and waveforms.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
The QUA configuration dictionary. Initially this is a nearly empty dictionary, but |
required |
Note
This function is called by
QuamRoot.generate_config
.
Note
The config has a starting template, defined at quam.core.qua_config_template
Source code in quam/core/quam_classes.py
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 |
|
QuamDict
Bases: UserDict
, QuamBase
A QuAM dictionary class.
Any dict added to a QuamBase
object is automatically converted to a QuamDict
.
The QuamDict
adds the following functionalities to a dict:
- Values can be references (see below)
- Keys can also be accessed through attributes (e.g. d.a
instead of d["a"]
)
QuamDict references
QuamDict values can be references, which are strings that start with #
. See the
documentation for details on references. An example is shown here:
d = QuamDict({"a": 1, "b": "#./a"})
assert d["b"] == 1
Warning
This class is a subclass of QuamBase
, but also of UserDict
. As a result,
it can be used as a normal dictionary, but it is not a subclass of dict
.
Source code in quam/core/quam_classes.py
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 |
|
get_attr_name(attr_val)
Get the name of an attribute that matches the value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr_val
|
Any
|
The value of the attribute. |
required |
Returns:
Type | Description |
---|---|
Union[str, int]
|
The name of the attribute. This can also be an int depending on the dict key |
Source code in quam/core/quam_classes.py
818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 |
|
get_unreferenced_value(attr)
Get the value of an attribute without following references.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr
|
str
|
The name of the attribute. |
required |
Returns:
Type | Description |
---|---|
bool
|
The value of the attribute. If the value is a reference, it returns the |
bool
|
reference string instead of the value it is referencing. |
Source code in quam/core/quam_classes.py
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 |
|
iterate_components(skip_elems=None)
Iterate over all QuamBase objects in this object, including nested objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
skip_elems
|
Sequence[QuamBase]
|
A list of QuamBase objects to skip. This is used to prevent infinite loops when iterating over nested objects. |
None
|
Returns:
Type | Description |
---|---|
None
|
A generator of QuamBase objects. |
Source code in quam/core/quam_classes.py
887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 |
|
QuamList
Bases: UserList
, QuamBase
A QuAM list class.
Any list added to a QuamBase
object is automatically converted to a QuamList
.
The QuamList
adds the following functionalities to a list:
- Elements can be references (see below)
QuamList references
QuamList values can be references, which are strings that start with #
. See the
documentation for details on references. An example is shown here:
d = QuamList([1, "#./0"]])
assert d[1] == 1
Warning
This class is a subclass of QuamBase
, but also of UserList
. As a result,
it can be used as a normal list, but it is not a subclass of list
.
Source code in quam/core/quam_classes.py
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 |
|
iterate_components(skip_elems=None)
Iterate over all QuamBase objects in this object, including nested objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
skip_elems
|
List[QuamBase]
|
A list of QuamBase objects to skip. This is used to prevent infinite loops when iterating over nested objects. |
None
|
Returns:
Type | Description |
---|---|
None
|
A generator of QuamBase objects. |
Source code in quam/core/quam_classes.py
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 |
|
print_summary(indent=0)
Print a summary of the QuamBase object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indent
|
int
|
The number of spaces to indent the summary. |
0
|
Source code in quam/core/quam_classes.py
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 |
|
to_dict(follow_references=False, include_defaults=False)
Convert this object to a list, usually as part of a dictionary representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
follow_references
|
bool
|
Whether to follow references when getting the value. If False, the reference will be returned as a string. |
False
|
include_defaults
|
bool
|
Whether to include attributes that have the default value. |
False
|
Returns:
Type | Description |
---|---|
list
|
A list with the values of this object. Any QuamBase objects will be |
list
|
recursively converted to dictionaries. |
Note
If the value of an attribute does not match the annotation of
QuamList._value_annotation
, the "__class__"
key will be added to the
dictionary. This is to ensure that the object can be reconstructed when
loading from a file.
Source code in quam/core/quam_classes.py
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 |
|
QuamRoot
Bases: QuamBase
Base class for the root of a QuAM object.
This class should be subclassed and made a dataclass.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
serialiser
|
The serialiser class to use for saving and loading.
The default is to use the |
required |
Note
This class should not be used directly, but should generally be subclassed and made a dataclass. The dataclass fields should correspond to the QuAM root structure.
Note
Upon instantiating a QuamRoot
object, it sets the class attribute
QuamBase._root
to itself. This is used such that any references with an
absolute path are resolved from the root.
Source code in quam/core/quam_classes.py
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 |
|
generate_config()
Generate the QUA configuration from the QuAM object.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
A dictionary with the QUA configuration. |
Note
This function collects all the nested QuamComponent objects and calls
QuamComponent.apply_to_config
on them.
Source code in quam/core/quam_classes.py
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 |
|
load(filepath_or_dict, validate_type=True, fix_attrs=True)
classmethod
Load a QuamRoot object from a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath_or_dict
|
Union[str, Path, dict]
|
The path to the file/folder to load, or a dictionary.
The dictionary would be the result from a call to |
required |
validate_type
|
bool
|
Whether to validate the type of all attributes while loading. |
True
|
fix_attrs
|
bool
|
Whether attributes can be added to QuamBase objects that are not defined as dataclass fields. |
True
|
Returns:
Type | Description |
---|---|
QuamRootType
|
A QuamRoot object instantiated from the file/folder/dict. |
Source code in quam/core/quam_classes.py
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 |
|
save(path=None, content_mapping=None, include_defaults=False, ignore=None)
Save the entire QuamRoot object to a file. This includes nested objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Union[Path, str]
|
The path to save the file to. If None, the path will be saved to
|
None
|
content_mapping
|
Dict[str, str]
|
A dictionary of paths to save to and a list of attributes to save to that path. This can be used to save different parts of the QuamRoot object to different files. |
None
|
include_defaults
|
bool
|
Whether to include attributes that have the default value. |
False
|
ignore
|
Sequence[str]
|
A list of attributes to ignore. |
None
|
Source code in quam/core/quam_classes.py
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 |
|
to_dict(follow_references=False, include_defaults=False)
Convert this object to a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
follow_references
|
bool
|
Whether to follow references when getting the value. If False, the reference will be returned as a string. |
False
|
include_defaults
|
bool
|
Whether to include attributes that have the default value. |
False
|
Source code in quam/core/quam_classes.py
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 |
|
convert_dict_and_list(value, cls_or_obj=None, attr=None)
Convert a dict or list to a QuamDict or QuamList if possible.
Source code in quam/core/quam_classes.py
72 73 74 75 76 77 78 79 80 81 |
|
sort_quam_components(components, max_attempts=5)
Sort QuamComponent objects based on their config_settings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
components
|
List[QuamComponent]
|
A list of QuamComponent objects. |
required |
max_attempts
|
The maximum number of attempts to sort the components. If the components aren't yet properly sorted after all these attempts, a warning is raised and the components are returned in the final attempted ordering. |
5
|
Returns:
Type | Description |
---|---|
List[QuamComponent]
|
A sorted list of QuamComponent objects. |
Note
This function is used by
QuamRoot.generate_config
to determine the order in which to add the components to the QUA config.
This sorting isn't guaranteed to be successful.
Source code in quam/core/quam_classes.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|