Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempting to use cudaq.kernels.uccsd kernel with hardware backend fails at compilation #2357

Open
3 of 4 tasks
ColemanCollins opened this issue Nov 5, 2024 · 3 comments
Open
3 of 4 tasks
Labels
needs triage Marks items that require a follow up for proper processing python-lang Anything related to the Python CUDA Quantum language implementation

Comments

@ColemanCollins
Copy link

Required prerequisites

  • 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

Any program that utilizes cudaq.kernels.uccsd against a hardware backend fails during what looks like a MLIR rewrite pass, per the failure output.

Steps to reproduce the bug

The following repro case, as written, runs successfully. If you uncomment line 3 or 4 (i.e. set target to a hardware backend), it fails with the output below.

import cudaq

# cudaq.set_target('ionq', emulate="true")
# cudaq.set_target('iqm', emulate=True, **{"qpu-architecture": "Adonis"})
repro_num_electrons = 2
repro_num_qubits = 4
repro_thetas = [-0.00037043841404585794, 0.0003811110195084151, 0.2286823796532558]

@cudaq.kernel
def repro_trial_state(qubits: cudaq.qvector, num_electrons:int, num_qubits:int, thetas:list[float]):
    for i in range(num_electrons):
        x(qubits[i])
    cudaq.kernels.uccsd(qubits, thetas, num_electrons, num_qubits)

# minimal repro case to play with IonQ submission issues
repro_kernel = cudaq.make_kernel()
repro_qubits = repro_kernel.qalloc(repro_num_qubits)
repro_kernel.apply_call(repro_trial_state, repro_qubits, repro_num_electrons, repro_num_qubits, repro_thetas)
repro_meas = cudaq.sample(repro_kernel, shots_count=100)
print(repro_meas)

healthy case

[2024-11-05 18:59:15.212] [info] [CircuitSimulator.h:1123] Setting current circuit name to
[2024-11-05 18:59:15.212] [info] [CircuitSimulator.h:1123] Setting current circuit name to
[2024-11-05 18:59:17.868] [info] [CircuitSimulator.h:901] Allocating 4 new qubits.
[2024-11-05 18:59:17.868] [info] [CircuitSimulator.h:1192] (apply) x(0)
[2024-11-05 18:59:17.868] [info] [CircuitSimulator.h:1192] (apply) x(1)
... more gate (apply) calls for x, h, rx, rz, ctrl -x gates
[2024-11-05 18:59:17.868] [info] [CircuitSimulator.h:1192] (apply) rx(-1.570796, 1)
[2024-11-05 18:59:17.868] [info] [CircuitSimulator.h:1192] (apply) rx(-1.570796, 0)
[2024-11-05 18:59:17.868] [info] [CircuitSimulator.h:968] Deferring qubit 0 deallocation
[2024-11-05 18:59:17.869] [info] [CircuitSimulator.h:968] Deferring qubit 1 deallocation
[2024-11-05 18:59:17.869] [info] [CircuitSimulator.h:968] Deferring qubit 2 deallocation
[2024-11-05 18:59:17.869] [info] [CircuitSimulator.h:968] Deferring qubit 3 deallocation
[2024-11-05 18:59:17.877] [info] [CircuitSimulator.h:656] Sampling the current state, with measure qubits = [0, 1, 2, 3]
[2024-11-05 18:59:17.877] [info] [CircuitSimulator.h:1108] Deallocated all qubits, reseting state vector.
{ 1100:100 }

failure case output - IonQ

[2024-11-05 18:59:37.151] [info] [DefaultQuantumPlatform.cpp:85] Backend string is ionq;emulate;true
[2024-11-05 18:59:37.151] [info] [DefaultQuantumPlatform.cpp:102] Config file path = /home/epifanovsky/miniconda3/envs/cudaq/lib/python3.11/site-packages/cudaq/mlir/_mlir_libs/../../../targets/ionq.yml
[2024-11-05 18:59:37.151] [info] [DefaultQuantumPlatform.cpp:120] Default platform QPU subtype name: remote_rest
[2024-11-05 18:59:37.151] [info] [BaseRemoteRESTQPU.h:205] Remote REST platform is targeting ionq;emulate;true.
[2024-11-05 18:59:37.151] [info] [BaseRemoteRESTQPU.h:260] Config file path = /home/epifanovsky/miniconda3/envs/cudaq/lib/python3.11/site-packages/cudaq/mlir/_mlir_libs/../../../targets/ionq.yml
[2024-11-05 18:59:37.151] [info] [BaseRemoteRESTQPU.h:270] Appending lowering pipeline: const-prop-complex,canonicalize,cse,lift-array-value,state-prep,expand-measurements,unrolling-pipeline,decomposition{enable-patterns=U3ToRotations},func.func(lower-to-cfg),canonicalize,func.func(multicontrol-decomposition),ionq-gate-set-mapping
[2024-11-05 18:59:37.151] [info] [BaseRemoteRESTQPU.h:276] Set codegen translation: qir-base
[2024-11-05 18:59:37.151] [info] [BaseRemoteRESTQPU.h:281] Adding post-codegen lowering pipeline: remove-measurements
[2024-11-05 18:59:37.151] [info] [IonQServerHelper.cpp:95] Initializing IonQ Backend.
[2024-11-05 18:59:37.151] [info] [quantum_platform.cpp:37] external caller setting the platform.
[2024-11-05 18:59:37.320] [info] [BaseRemoteRESTQPU.h:188] Remote Rest QPU setting execution context to sample
[2024-11-05 18:59:37.320] [info] [BaseRemoteRESTQPU.h:188] Remote Rest QPU setting execution context to sample
[2024-11-05 18:59:40.005] [info] [BaseRemoteRESTQPU.h:524] launching remote rest kernel (__nvqppBuilderKernel_LS0ORN02T4)
[2024-11-05 18:59:41.264] [info] [cudaq.cpp:226] Replacing code for kernel __nvqppBuilderKernel_LS0ORN02T4
[2024-11-05 18:59:41.266] [info] [BaseRemoteRESTQPU.h:392] Pass pipeline for __nvqppBuilderKernel_LS0ORN02T4 = cc-loop-unroll{allow-early-exit=0},canonicalize,const-prop-complex,canonicalize,cse,lift-array-value,state-prep,expand-measurements,unrolling-pipeline,decomposition{enable-patterns=U3ToRotations},func.func(lower-to-cfg),canonicalize,func.func(multicontrol-decomposition),ionq-gate-set-mapping
python: /llvm-project/mlir/lib/IR/PatternMatch.cpp:276: virtual void mlir::RewriterBase::eraseOp(mlir::Operation*): Assertion `op->use_empty() && "expected 'op' to have no uses"' failed.
Aborted

failure case output - IQM

[2024-11-05 19:23:12.356] [info] [BaseRemoteRESTQPU.h:270] Appending lowering pipeline: const-prop-complex,canonicalize,cse,lift-array-value,state-prep,expand-measurements,unrolling-pipeline,decomposition{enable-patterns=U3ToRotations},func.func(lower-to-cfg),canonicalize,func.func(multicontrol-decomposition),iqm-gate-set-mapping,func.func(add-dealloc,combine-quantum-alloc,canonicalize,factor-quantum-alloc,memtoreg,qubit-mapping{device=file(%QPU_ARCH%)},delay-measurements,regtomem),iqm-gate-set-mapping
[2024-11-05 19:23:12.356] [info] [BaseRemoteRESTQPU.h:276] Set codegen translation: iqm
[2024-11-05 19:23:12.356] [info] [IQMServerHelper.cpp:119] Emulation is enabled, ignore tokens file and IQM Server URL
[2024-11-05 19:23:12.356] [info] [quantum_platform.cpp:37] external caller setting the platform.
[2024-11-05 19:23:12.519] [info] [BaseRemoteRESTQPU.h:188] Remote Rest QPU setting execution context to sample
[2024-11-05 19:23:12.519] [info] [BaseRemoteRESTQPU.h:188] Remote Rest QPU setting execution context to sample
[2024-11-05 19:23:15.180] [info] [BaseRemoteRESTQPU.h:524] launching remote rest kernel (__nvqppBuilderKernel_3NA4U8G38W)
[2024-11-05 19:23:16.423] [info] [cudaq.cpp:226] Replacing code for kernel __nvqppBuilderKernel_3NA4U8G38W
[2024-11-05 19:23:16.425] [info] [BaseRemoteRESTQPU.h:392] Pass pipeline for __nvqppBuilderKernel_3NA4U8G38W = cc-loop-unroll{allow-early-exit=0},canonicalize,const-prop-complex,canonicalize,cse,lift-array-value,state-prep,expand-measurements,unrolling-pipeline,decomposition{enable-patterns=U3ToRotations},func.func(lower-to-cfg),canonicalize,func.func(multicontrol-decomposition),iqm-gate-set-mapping,func.func(add-dealloc,combine-quantum-alloc,canonicalize,factor-quantum-alloc,memtoreg,qubit-mapping{device=file('/home/epifanovsky/miniconda3/envs/cudaq/lib/python3.11/site-packages/cudaq/mlir/_mlir_libs/../../../targets/mapping/iqm/Adonis.txt')},delay-measurements,regtomem),iqm-gate-set-mapping
python: /llvm-project/mlir/lib/IR/PatternMatch.cpp:276: virtual void mlir::RewriterBase::eraseOp(mlir::Operation*): Assertion `op->use_empty() && "expected 'op' to have no uses"' failed.
Aborted

Expected behavior

successful compilation and execution

Is this a regression? If it is, put the last known working version (or commit) here.

Unknown

Environment

  • CUDA Quantum version: 0.8.0
  • Python version: Python 3.10.12
  • C++ compiler: g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
  • Operating system: Ubuntu 22.04.3 LTS (Jammy Jellyfish)

Suggestions

No response

@ColemanCollins
Copy link
Author

additional context: I believe this to be unique to the uccsd kernel because other simple examples like the below run successfully

import cudaq
cudaq.set_target('ionq', emulate=True)

repro_kernel = cudaq.make_kernel()
repro_qubits = repro_kernel.qalloc(2)

repro_kernel.h(repro_qubits[0])
repro_kernel.cx(repro_qubits[0], repro_qubits[1])

repro_meas = cudaq.sample(repro_kernel, shots_count=100)
print(repro_meas)

@zohimchandani
Copy link
Collaborator

Cleaning up the code snippet a little from above:

import cudaq

num_qubits = 4
num_electrons = 2
thetas = [1,2,3]

@cudaq.kernel
def kernel(num_qubits: int, num_electrons:int, thetas:list[float]):
    
    qubits = cudaq.qvector(num_qubits)
    
    for i in range(num_electrons):
        x(qubits[i])
        
    cudaq.kernels.uccsd(qubits, thetas, num_electrons, num_qubits)
    
# cudaq.set_target('qpp-cpu')   
# cudaq.set_target('nvidia')

cudaq.set_target('ionq', emulate="true")
#cudaq.set_target('iqm', emulate=True, **{"qpu-architecture": "Adonis"})

results = cudaq.sample(kernel, num_qubits, num_electrons, thetas, shots_count=100)

print(results)

It works fine for the cpu and nvidia targets however the uccsd line throws the following error for the hardware targets:

python3: /root/.llvm-project/mlir/lib/IR/PatternMatch.cpp:276: virtual void mlir::RewriterBase::eraseOp(mlir::Operation*): Assertion `op->use_empty() && "expected 'op' to have no uses"' failed.
Aborted (core dumped)

@schweitzpgi
Copy link
Collaborator

schweitzpgi commented Nov 19, 2024

My bad. I misread "uncomment".

Both the original code and Zohim's modified code have issues.

...
error: 'cc.loop' op not a constant upper bound loop
error: 'cc.loop' op not a constant upper bound loop
error: 'cc.loop' op not a constant upper bound loop
error: 'cc.loop' op loop bounds exceed iteration threshold
error: 'cc.loop' op not a constant upper bound loop
error: 'cc.loop' op not a constant upper bound loop
error: 'cc.loop' op not a constant upper bound loop
error: 'cc.loop' op loop bounds exceed iteration threshold
error: 'cc.loop' op not a constant upper bound loop
error: 'cc.loop' op not a constant upper bound loop
...

@schweitzpgi schweitzpgi added verify and close python-lang Anything related to the Python CUDA Quantum language implementation needs triage Marks items that require a follow up for proper processing and removed verify and close labels Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Marks items that require a follow up for proper processing python-lang Anything related to the Python CUDA Quantum language implementation
Projects
None yet
Development

No branches or pull requests

3 participants