|
| 1 | +// Copyright 2025 Xanadu Quantum Technologies Inc. |
| 2 | + |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | + |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include <catch2/catch_approx.hpp> |
| 16 | +#include <catch2/catch_test_macros.hpp> |
| 17 | + |
| 18 | +#include "RuntimeCAPI.h" |
| 19 | + |
| 20 | +// -------------------------------------------------------------------------- // |
| 21 | +// MBQC Runtime Tests |
| 22 | +// -------------------------------------------------------------------------- // |
| 23 | + |
| 24 | +TEST_CASE("Test __catalyst__mbqc__measure_in_basis, device=null.qubit", "[MBQC]") |
| 25 | +{ |
| 26 | + __catalyst__rt__initialize(nullptr); |
| 27 | + |
| 28 | + const std::string rtd_name{"null.qubit"}; |
| 29 | + __catalyst__rt__device_init((int8_t *)rtd_name.c_str(), nullptr, nullptr, 0); |
| 30 | + |
| 31 | + const size_t num_qubits = 1; |
| 32 | + QirArray *qs = __catalyst__rt__qubit_allocate_array(num_qubits); |
| 33 | + |
| 34 | + QUBIT **q0 = (QUBIT **)__catalyst__rt__array_get_element_ptr_1d(qs, 0); |
| 35 | + |
| 36 | + CHECK(reinterpret_cast<QubitIdType>(*q0) == 0); |
| 37 | + |
| 38 | + // Recall that the basis states for arbitrary-basis measurements are parameterized by a plane |
| 39 | + // (either XY, YZ or ZX) and a rotation angle about that plane. See the `mbqc.measure_in_basis` |
| 40 | + // op definition in mlir/include/MBQC/IR/MBQCOps.td for details on these parameters and how they |
| 41 | + // are encoded. |
| 42 | + RESULT *mres = __catalyst__mbqc__measure_in_basis(*q0, 0U /*plane*/, 0.0 /*angle*/, -1); |
| 43 | + |
| 44 | + CHECK(*mres == false); // For null.qubit, measurement result is always 0 (false) |
| 45 | + |
| 46 | + __catalyst__rt__device_release(); |
| 47 | + __catalyst__rt__finalize(); |
| 48 | +} |
0 commit comments