qukit
Version:
[](https://www.npmjs.com/package/qukit) [](https://crates.io/crates/qukit) [](https://opensource.org/lice
63 lines (62 loc) • 2.47 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.rotationSwap = void 0;
const WasmLib = __importStar(require("../pkg/qukit"));
function rotationSwap(theta, qbits0, qbits1, cControl, sameStep = false) {
if (Array.isArray(qbits0) && Array.isArray(qbits1)) {
const minLen = Math.min(qbits0.length, qbits1.length);
if (minLen > 0) {
rotationSwap(theta, qbits0[0], qbits1[0], cControl, sameStep);
}
for (let i = 1; i < minLen; i++) {
rotationSwap(theta, qbits0[i], qbits1[i], cControl, sameStep);
}
}
else {
if (!Array.isArray(qbits0) && !Array.isArray(qbits1)) {
if (cControl !== null && cControl !== undefined) {
if (sameStep) {
WasmLib.rotation_swap_same_step_classically_controlled(theta, qbits0, qbits1, cControl);
}
else {
WasmLib.rotation_swap_classically_controlled(theta, qbits0, qbits1, cControl);
}
}
else {
if (sameStep) {
WasmLib.rotation_swap_same_step(theta, qbits0, qbits1);
}
else {
WasmLib.rotation_swap(theta, qbits0, qbits1);
}
}
}
else {
throw new Error("type mismatch");
}
}
}
exports.rotationSwap = rotationSwap;