MCPcopy Create free account
hub / github.com/NVIDIA/cuda-quantum / test_create_and_modify_struct

Function test_create_and_modify_struct

python/tests/kernel/test_run_kernel.py:1050–1087  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1048
1049
1050def test_create_and_modify_struct():
1051
1052 @dataclass(slots=True)
1053 class MyClass:
1054 x: int
1055 y: bool
1056
1057 @cudaq.kernel
1058 def simple_strucC() -> MyClass:
1059 q = cudaq.qubit()
1060 t = MyClass(-13, True)
1061 t.x = 42
1062 return t
1063
1064 results = cudaq.run(simple_strucC, shots_count=2)
1065 print(results)
1066 assert len(results) == 2
1067 assert results[0] == MyClass(42, True)
1068 assert results[1] == MyClass(42, True)
1069
1070 @dataclass(slots=True)
1071 class Bar:
1072 x: bool
1073 y: bool
1074 z: float
1075
1076 @cudaq.kernel
1077 def kerneD(n: int) -> Bar:
1078 q = cudaq.qvector(n)
1079 t = Bar(False, False, 4.14)
1080 t.x = True
1081 t.y = True
1082 return t
1083
1084 results = cudaq.run(kerneD, 2, shots_count=1)
1085 print(results)
1086 assert len(results) == 1
1087 assert results[0] == Bar(True, True, 4.14)
1088
1089
1090@pytest.mark.skip_macos_arm64_jit

Callers

nothing calls this directly

Calls 4

MyClassClass · 0.70
BarClass · 0.70
printFunction · 0.50
runMethod · 0.45

Tested by

no test coverage detected