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
Currently, noisy simulations do not support user-defined custom operations. Specifically, adding noise channels (e.g., cudaq.BitFlipChannel, cudaq.PhaseFlipChannel, cudaq.KrausChannel) to cudaq.NoiseModel() with a custom op will result in an error:
RuntimeError: Invalid quantum op for noise_model::add_channel
Steps to reproduce the bug
importcudaqimportnumpyasnp# Identity matrix as a custom unitary operatormatrix=np.array([[1, 0, 0, 1]])
cudaq.register_operation("id", matrix)
# Let's define a simple kernel that we will add noise to.qubit_count=1@cudaq.kerneldefkernel(qubit_count: int):
qvector=cudaq.qvector(qubit_count)
id(qvector)
print(cudaq.draw(kernel, qubit_count))
# Define the Kraus Error Operator as a complex ndarray.error_probability=0.2kraus_0=np.array([[1.0, 0.0], [0.0, np.sqrt(1-error_probability)]], dtype=np.complex128)
kraus_1=np.array([[0.0, np.sqrt(error_probability)], [0.0, 0.0]], dtype=np.complex128)
# Add the two channels to our Noise Model.noise_model=cudaq.NoiseModel()
# Add the Kraus Operator to create a quantum noise channel.damping_channel=cudaq.KrausChannel([kraus_0, kraus_1])
# Apply the damping channel to the custom op specified as "id" on the 1st qubit.noise_model.add_channel("id", [0], damping_channel)
Expected behavior
cudaq.NoiseModel() should accept custom operator: [str], like "id" defined above by users, as a valid unitary quantum operator, and a subsequent cudaq.sample call can return SampleResult accordingly.
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
CUDA Quantum version: 0.8.0
Python version: 3.10
Suggestions
No response
The text was updated successfully, but these errors were encountered:
The noise for custom op feature will be available in the next release (0.9). It is available now in the nightly docker image.
An example to test:
import cudaq
import numpy as np
cudaq.set_target("density-matrix-cpu")
# Identity matrix as a custom unitary operator
matrix = np.array([[1, 0, 0, 1]])
cudaq.register_operation("id", matrix)
# Let's define a simple kernel that we will add noise to.
qubit_count = 1
@cudaq.kernel
def kernel(qubit_count: int):
qvector = cudaq.qvector(qubit_count)
x(qvector)
id(qvector)
# Define the Kraus Error Operator as a complex ndarray.
error_probability = 0.2
kraus_0 = np.array([[1.0, 0.0], [0.0, np.sqrt(1 - error_probability)]], dtype=np.complex128)
kraus_1 = np.array([[0.0, np.sqrt(error_probability)], [0.0, 0.0]], dtype=np.complex128)
# Add the two channels to our Noise Model.
noise_model = cudaq.NoiseModel()
# Add the Kraus Operator to create a quantum noise channel.
damping_channel = cudaq.KrausChannel([kraus_0, kraus_1])
# Apply the damping channel to the custom op specified as "id" on the 1st qubit.
noise_model.add_channel("id", [0], damping_channel)
sample = cudaq.sample(kernel, qubit_count, noise_model=noise_model)
print(sample)
This will print a noisy result like { 0:211 1:789 }.
Note: in the kernel, I added an X operation to set the qubit to 1 so that the noise effect can be observed as we are using an amplitude damping channel which only affects excited states.
Required prerequisites
Describe the bug
Currently, noisy simulations do not support user-defined custom operations. Specifically, adding noise channels (e.g.,
cudaq.BitFlipChannel
,cudaq.PhaseFlipChannel
,cudaq.KrausChannel
) tocudaq.NoiseModel()
with a custom op will result in an error:Steps to reproduce the bug
Expected behavior
cudaq.NoiseModel()
should accept customoperator: [str]
, like"id"
defined above by users, as a valid unitary quantum operator, and a subsequentcudaq.sample
call can returnSampleResult
accordingly.Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
Suggestions
No response
The text was updated successfully, but these errors were encountered: