Skip to content

Ionq results differ from quantinuum results with multiple measurements #2758

Open
@annagrin

Description

@annagrin

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

The following test produces different results on Ionq emulation and Ionq simulation in CI due to mz instructions and extra mz-related registers we create in QIR.

Questions:

  • Is this code valid?
    • should we emit an error on get_state on a kernel that contains a measurement?
  • If the code is valid, what results do we expect for various platforms?

Steps to reproduce the bug

# ============================================================================ #
# Copyright (c) 2022 - 2025 NVIDIA Corporation & Affiliates.                   #
# All rights reserved.                                                         #
#                                                                              #
# This source code and the accompanying materials are made available under     #
# the terms of the Apache License 2.0 which accompanies this distribution.     #
# ============================================================================ #

def test_state_synthesis():
    
        @cudaq.kernel
        def init(n: int):
            q = cudaq.qvector(n)
            h(q[0]
            x(q[1])
            mz(q)
    
        @cudaq.kernel
        def kernel(s: cudaq.State):
            q = cudaq.qvector(s)
            x(q[1])
            mz(q)
    
        s = cudaq.get_state(init, 2)
        s = cudaq.get_state(kernel, s)
        print(counts)
        counts = cudaq.sample(kernel, s)

cudaq.set_target("ionq", emulate=True)
test_state_synthesis()

cudaq.set_target("ionq", emulate=False)
test_state_synthesis()

Tests with emulation enabled on a local simulator give following results:

{ 01:521 11:479 }

Tests against IonQ simulator in CI give different results:

   __global__ : { 000111:479 111111:521 }
   r00000 : { 0:479 1:521 }
   r00001 : { 1:1000 }
   r00002 : { 0:479 1:521 }
   r00003 : { 1:1000 }
   r00004 : { 0:479 1:521 }
   r00005 : { 1:1000 }
}
 =========================== short test summary info ============================
 FAILED python/tests/backends/test_IonQ.py::test_Ionq_state_synthesis - Assert...
 =================== 1 failed, 12 passed, 1 warning in 6.34s ====================

QIR for ionq (note that we create 6 registers)

; ModuleID = 'LLVMDialectModule'
source_filename = "LLVMDialectModule"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%Qubit = type opaque

define void @__nvqpp__mlirgen__kernel() local_unnamed_addr #0 {
"0":
  tail call void @__quantum__qis__h__body(%Qubit* null)
  tail call void @__quantum__qis__x__body(%Qubit* nonnull inttoptr (i64 1 to %Qubit*))
  tail call void @__quantum__qis__x__body(%Qubit* nonnull inttoptr (i64 1 to %Qubit*))
  tail call void @__quantum__qis__x__body(%Qubit* nonnull inttoptr (i64 1 to %Qubit*))
  ret void
}

declare void @__quantum__qis__h__body(%Qubit*) local_unnamed_addr

declare void @__quantum__qis__x__body(%Qubit*) local_unnamed_addr

attributes #0 = { "entry_point" "output_labeling_schema"="schema_id" "output_names"="[[[0,[0,\22r00000\22]],[1,[1,\22r00001\22]],[2,[0,\22r00002\22]],[3,[1,\22r00003\22]],[4,[0,\22r00004\22]],[5,[1,\22r00005\22]]]]" "qir_profiles"="base_profile" "requiredQubits"="2" "requiredResults"="6" }

!llvm.module.flags = !{!0, !1, !2, !3, !4}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 1, !"qir_major_version", i32 1}
!2 = !{i32 7, !"qir_minor_version", i32 0}
!3 = !{i32 1, !"dynamic_qubit_management", i1 false}
!4 = !{i32 1, !"dynamic_result_management", i1 false}
WARNING: this kernel invocation produced 0 shots worth of results when executed. Exiting shot loop to avoid infinite loop.
{ }

Expected behavior

Same results in both executions (or an error if this code is invalid)

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

Not a regression

Environment

  • CUDA-Q version:
  • Python version:
  • C++ compiler:
  • Operating system:

Suggestions

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions