@@ -684,3 +684,70 @@ func.func public @test_adjoint_with_allocation(%arg0: i64) attributes {quantum.n
684684 quantum.dealloc %8 : !quantum.reg
685685 return
686686}
687+
688+
689+ // -----
690+
691+ // CHECK-LABEL: test_operator_qubits
692+ func.func @test_operator_qubits (%arg0: f64 , %cv: i1 , %fwd: i64 ) attributes {quantum.node } {
693+ // CHECK: [[qreg:%.+]] = qref.alloc( 2) : !qref.reg<2>
694+ %0 = quantum.alloc ( 2 ) : !quantum.reg
695+
696+ // CHECK: [[q0:%.+]] = qref.get [[qreg]][ 0] : !qref.reg<2> -> !qref.bit
697+ // CHECK: [[q1:%.+]] = qref.get [[qreg]][ 1] : !qref.reg<2> -> !qref.bit
698+ %1 = quantum.extract %0 [ 0 ] : !quantum.reg -> !quantum.bit
699+ %2 = quantum.extract %0 [ 1 ] : !quantum.reg -> !quantum.bit
700+
701+ // CHECK: qref.operator "MyOp"(%arg0: f64) adj qubits([[q0]], [[q1]])
702+ // CHECK-NEXT: static_data = {pauli_word = "XY"}
703+ // CHECK-NEXT: param_map = {theta = [0]} qubit_map = {pair = [0, 1]}
704+ %out1:2 = quantum.operator " MyOp" (%arg0: f64 ) adj qubits (%1 , %2 )
705+ static_data = {pauli_word = " XY" }
706+ param_map = {theta = [0 ]} qubit_map = {pair = [0 , 1 ]}
707+
708+ // CHECK: qref.operator "MyOp"() qubits([[q0]])
709+ // CHECK-NEXT: ctrls([[q1]]) ctrl_vals(%arg1)
710+ %oq , %ocq = quantum.operator " MyOp" () qubits (%out1#0 )
711+ ctrls (%out1#1 ) ctrl_vals (%cv )
712+
713+ // CHECK: qref.operator "MyOp"() qubits([[q0]], [[q1]])
714+ // CHECK-NEXT: UID(42) forward(%arg2: i64)
715+ %out3:2 = quantum.operator " MyOp" () qubits (%oq , %ocq )
716+ UID (42 ) forward (%fwd : i64 )
717+
718+ // CHECK-NOT: quantum.insert
719+ %3 = quantum.insert %0 [ 0 ], %out3#0 : !quantum.reg , !quantum.bit
720+ %4 = quantum.insert %3 [ 1 ], %out3#1 : !quantum.reg , !quantum.bit
721+
722+ // CHECK: qref.dealloc [[qreg]] : !qref.reg<2>
723+ quantum.dealloc %4 : !quantum.reg
724+ return
725+ }
726+
727+
728+ // -----
729+
730+
731+ // CHECK-LABEL: test_operator_register
732+ func.func @test_operator_register (%idx0: tensor <2 xi64 >, %idx1: tensor <1 xi64 >, %cidx: tensor <2 xi64 >, %cval: tensor <2 xi1 >) attributes {quantum.node } {
733+ // CHECK: [[qreg:%.+]] = qref.alloc( 4) : !qref.reg<4>
734+ %0 = quantum.alloc ( 4 ) : !quantum.reg
735+
736+ // CHECK: qref.operator "MyOp"()
737+ // CHECK-NEXT: quregs([[qreg]] : !qref.reg<4>) indices(%arg0: tensor<2xi64>, %arg1: tensor<1xi64>)
738+ // CHECK-NEXT: qubit_map = {qi0 = [0], qi1 = [1]}
739+ %out1 = quantum.operator " MyOp" ()
740+ quregs (%0 ) indices (%idx0 : tensor <2 xi64 >, %idx1 : tensor <1 xi64 >)
741+ qubit_map = {qi0 = [0 ], qi1 = [1 ]}
742+
743+ // CHECK: qref.operator "MyOp"()
744+ // CHECK-NEXT: quregs([[qreg]] : !qref.reg<4>) indices(%arg0: tensor<2xi64>)
745+ // CHECK-NEXT: ctrls(%arg2: tensor<2xi64>) ctrl_vals(%arg3: tensor<2xi1>)
746+ %out2 = quantum.operator " MyOp" ()
747+ quregs (%out1 ) indices (%idx0 : tensor <2 xi64 >)
748+ ctrls (%cidx : tensor <2 xi64 >) ctrl_vals (%cval : tensor <2 xi1 >)
749+
750+ // CHECK: qref.dealloc [[qreg]] : !qref.reg<4>
751+ quantum.dealloc %out2 : !quantum.reg
752+ return
753+ }
0 commit comments