You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consult the security policy. If reporting a security vulnerability, do not report the bug using this form. Use the process described in the policy to report the issue.
Make sure you've read the documentation. Your issue may be addressed there.
Search the issue tracker to verify that this hasn't already been reported. +1 or comment there if it has.
If possible, make a PR with a failing test to give us a starting point to work on!
Describe the bug
I am trying to create controlled versions of X gate. For the CX (1 control qubit), the code works correctly, but for CCX (2 control qubits) or more, I get an error.
When I try to add more control qubits, I get an error, no matter the syntax:
nqubits=3kernel=cudaq.make_kernel()
qubits=kernel.qalloc(nqubits)
target_kernel, qubit=cudaq.make_kernel(cudaq.qubit)
target_kernel.x(qubit)
kernel.control(target_kernel, [qubits[0], qubits[1]], qubits[2]) # This raises an errorkernel.control(target_kernel, qubits[0], qubits[1], qubits[2]) # This raises an error as well
In the first case the error is:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[7], line 10
7 target_kernel.x(qubit)
9 kernel.h(qubits[0])
---> 10 kernel.control(target_kernel, [qubits[0], qubits[1]], qubits[nqubits - 1]) # This raises an error
11 # kernel.control(target_kernel, qubits[0], qubits[1], qubits[nqubits - 1]) # This raises an error as well
File ~/projects/qilisdk/.venv/lib/python3.10/site-packages/cudaq/kernel/kernel_builder.py:1239, in PyKernel.control(self, target, control, *target_arguments)
1205 def control(self, target, control, *target_arguments):
1206 """
1207 Apply the `target` kernel as a controlled operation in-place to
1208 `self`.Uses the provided `control` as control qubit/s for the operation.
(...)
1237 ```
1238 """
-> 1239 self.__applyControlOrAdjoint(target, False, [control.mlirValue],
1240 *target_arguments)
1241 return
AttributeError: 'list' object has no attribute 'mlirValue'
In the second case the error is:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Cell In[6], line 11
9 kernel.h(qubits[0])
10 # kernel.control(target_kernel, [qubits[0], qubits[1]], qubits[nqubits - 1]) # This raises an error
---> 11 kernel.control(target_kernel, qubits[0], qubits[1], qubits[nqubits - 1]) # This raises an error as well
File ~/projects/qilisdk/.venv/lib/python3.10/site-packages/cudaq/kernel/kernel_builder.py:1239, in PyKernel.control(self, target, control, *target_arguments)
1205 def control(self, target, control, *target_arguments):
1206 """
1207 Apply the `target` kernel as a controlled operation in-place to
1208 `self`.Uses the provided `control` as control qubit/s for the operation.
(...)
1237 ```
1238 """
-> 1239 self.__applyControlOrAdjoint(target, False, [control.mlirValue],
1240 *target_arguments)
1241 return
File ~/projects/qilisdk/.venv/lib/python3.10/site-packages/cudaq/kernel/kernel_builder.py:666, in PyKernel.__applyControlOrAdjoint(self, target, isAdjoint, controls, *args)
664 mlirValues = []
665 for i, v in enumerate(args):
--> 666 argTy = otherFTy[i].type
667 if not isinstance(v, QuakeValue):
668 # here we have to map constant Python data
669 # to an MLIR Value
670 value = self.__getMLIRValueFromPythonArg(v, argTy)
IndexError: index out of range
Expected behavior
I would expect the correct CCX gate to be created as is the case with the decorator syntax:
Required prerequisites
Describe the bug
I am trying to create controlled versions of
X
gate. For theCX
(1 control qubit), the code works correctly, but forCCX
(2 control qubits) or more, I get an error.Steps to reproduce the bug
The following works correcty:
When I try to add more control qubits, I get an error, no matter the syntax:
In the first case the error is:
In the second case the error is:
Expected behavior
I would expect the correct
CCX
gate to be created as is the case with the decorator syntax:Is this a regression? If it is, put the last known working version (or commit) here.
I haven't tested it with older versions.
Environment
Suggestions
The error probably lies within how
kernel_builder.__applyControlOrAdjoint()
handles the QuakeValue ofcontrol
argument.The text was updated successfully, but these errors were encountered: