Merge pull request #15 from microsoft/anpaz/clean-json

Clean min json
This commit is contained in:
Raphael Koh 2021-05-31 13:43:43 -04:00 коммит произвёл GitHub
Родитель 6ab235364b 5ea82bfa7f
Коммит 10cb992216
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 1388 добавлений и 321 удалений

Просмотреть файл

@ -2002,7 +2002,7 @@ describe('Testing processOperations', () => {
isControlled: false,
isAdjoint: false,
controls: [],
targets: [{ type: RegisterType.Qubit, qId: 0 }],
targets: [{ qId: 0 }],
},
{
gate: 'H',
@ -2011,7 +2011,7 @@ describe('Testing processOperations', () => {
isControlled: false,
isAdjoint: false,
controls: [],
targets: [{ type: RegisterType.Qubit, qId: 0 }],
targets: [{ qId: 0 }],
},
{
gate: 'H',
@ -2020,7 +2020,7 @@ describe('Testing processOperations', () => {
isControlled: false,
isAdjoint: false,
controls: [],
targets: [{ type: RegisterType.Qubit, qId: 1 }],
targets: [{ qId: 1 }],
},
{
gate: 'RX',
@ -2030,7 +2030,7 @@ describe('Testing processOperations', () => {
isControlled: false,
isAdjoint: false,
controls: [],
targets: [{ type: RegisterType.Qubit, qId: 1 }],
targets: [{ qId: 1 }],
},
];
const registers: RegisterMap = {

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -62,7 +62,7 @@ export interface Operation {
/** Whether gate is an adjoint operation. */
isAdjoint: boolean;
/** Control registers the gate acts on. */
controls: Register[];
controls?: Register[];
/** Target registers the gate acts on. */
targets: Register[];
/** Specify conditions on when to render operation. */

Просмотреть файл

@ -102,9 +102,14 @@ const _groupOperations = (operations: Operation[], registers: RegisterMap): numb
const numRegs: number = Math.max(-1, ...Object.keys(registers).map(Number)) + 1;
const groupedOps: number[][] = Array.from(Array(numRegs), () => new Array(0));
operations.forEach(({ targets, controls }, instrIdx) => {
const qRegs: Register[] = [...controls, ...targets].filter(({ type }) => type === RegisterType.Qubit);
const ctrls: Register[] = controls || [];
const qRegs: Register[] = [...ctrls, ...targets].filter(
({ type }) => (type || RegisterType.Qubit) === RegisterType.Qubit,
);
const qRegIdxList: number[] = qRegs.map(({ qId }) => qId);
const clsControls: Register[] = controls.filter(({ type }) => type === RegisterType.Classical);
const clsControls: Register[] = ctrls.filter(
({ type }) => (type || RegisterType.Qubit) === RegisterType.Classical,
);
const isClassicallyControlled: boolean = clsControls.length > 0;
if (!isClassicallyControlled && qRegs.length === 0) return;
// If operation is classically-controlled, pad all qubit registers. Otherwise, only pad
@ -219,7 +224,7 @@ const _opToMetadata = (op: Operation | null, registers: RegisterMap): Metadata =
} = op;
// Set y coords
metadata.controlsY = controls.map((reg) => _getRegY(reg, registers));
metadata.controlsY = controls?.map((reg) => _getRegY(reg, registers)) || [];
metadata.targetsY = targets.map((reg) => _getRegY(reg, registers));
if (isConditional) {
@ -301,6 +306,7 @@ const _getRegY = (reg: Register, registers: RegisterMap): number => {
if (!registers.hasOwnProperty(qId)) throw new Error(`ERROR: Qubit register with ID ${qId} not found.`);
const { y, children } = registers[qId];
switch (type) {
case undefined:
case RegisterType.Qubit:
return y;
case RegisterType.Classical:

Просмотреть файл

@ -13,8 +13,8 @@ export enum RegisterType {
* Represents a register resource.
*/
export interface Register {
/** Type of register. */
type: RegisterType;
/** Type of register. If missing defaults to Qubit. */
type?: RegisterType;
/** Qubit register ID. */
qId: number;
/** Classical register ID (if classical register). */