File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,13 @@ void quantum_program::add(ql::quantum_kernel &k)
97
97
}
98
98
}
99
99
100
+ for (auto kernel : kernels)
101
+ {
102
+ if (kernel.name == k.name )
103
+ {
104
+ FATAL (" Cannot add kernel. Duplicate kernel name: " << k.name );
105
+ }
106
+ }
100
107
// if sane, now add kernel to list of kernels
101
108
kernels.push_back (k);
102
109
}
Original file line number Diff line number Diff line change @@ -111,6 +111,32 @@ def test_multi_kernel(self):
111
111
112
112
p .compile ()
113
113
114
+ def test_duplicate_kernel_name (self ):
115
+ nqubits = 3
116
+
117
+ p = ql .Program ("aProgram" , platf , nqubits )
118
+ k1 = ql .Kernel ("aKernel1" , platf , nqubits )
119
+ k2 = ql .Kernel ("aKernel2" , platf , nqubits )
120
+ k3 = ql .Kernel ("aKernel1" , platf , nqubits )
121
+
122
+ k1 .gate ('x' , [0 ])
123
+ k2 .gate ('x' , [0 ])
124
+ k3 .gate ('x' , [0 ])
125
+
126
+ # add the kernel to the program
127
+ p .add_kernel (k1 )
128
+ p .add_kernel (k2 )
129
+
130
+ # following call to add_kernel should fail as k3 has duplicate name
131
+ try :
132
+ p .add_kernel (k3 )
133
+ raise
134
+ except :
135
+ pass
136
+
137
+ # compile the program
138
+ p .compile ()
139
+
114
140
115
141
if __name__ == '__main__' :
116
142
unittest .main ()
You can’t perform that action at this time.
0 commit comments