Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Core/ExecutionPathTracer/ExecutionPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,23 @@ public class Operation
[JsonProperty("children")]
public IEnumerable<IEnumerable<Operation>>? Children { get; set; }

/// <summary>
/// True if operation is a measurement operations.
/// </summary>
[JsonProperty("isMeasurement")]
public bool IsMeasurement { get; set; }

/// <summary>
/// True if operation is a controlled operations.
/// </summary>
[JsonProperty("controlled")]
public bool Controlled { get; set; }
[JsonProperty("isControlled")]
public bool IsControlled { get; set; }

/// <summary>
/// True if operation is an adjoint operations.
/// </summary>
[JsonProperty("adjoint")]
public bool Adjoint { get; set; }
[JsonProperty("isAdjoint")]
public bool IsAdjoint { get; set; }

/// <summary>
/// List of control registers.
Expand Down
7 changes: 3 additions & 4 deletions src/Core/ExecutionPathTracer/ExecutionPathTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ private ClassicalRegister GetClassicalRegister(Qubit controlQubit)
Gate = metadata.Label,
DisplayArgs = displayArgs,
Children = metadata.Children?.Select(child => child.Select(this.MetadataToOperation).WhereNotNull()),
Controlled = metadata.IsControlled,
Adjoint = metadata.IsAdjoint,
IsControlled = metadata.IsControlled,
IsAdjoint = metadata.IsAdjoint,
Controls = this.GetQubitRegisters(metadata.Controls),
Targets = this.GetQubitRegisters(metadata.Targets),
};
Expand All @@ -159,8 +159,7 @@ private ClassicalRegister GetClassicalRegister(Qubit controlQubit)
{
var measureQubit = metadata.Targets.ElementAt(0);
var clsReg = this.CreateClassicalRegister(measureQubit);
// TODO: Change this to using IsMeasurement
op.Gate = "measure";
op.IsMeasurement = true;
op.Controls = op.Targets;
op.Targets = new List<Register>() { clsReg };
}
Expand Down
6 changes: 4 additions & 2 deletions src/Kernel/client/ExecutionPathVisualizer/executionPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ export interface Operation {
* - children[1]: gates when classical control bit is 1.
*/
children?: Operation[][];
/** Whether gate is a measurement operation. */
isMeasurement: boolean;
/** Whether gate is a controlled operation. */
controlled: boolean;
isControlled: boolean;
/** Whether gate is an adjoint operation. */
adjoint: boolean;
isAdjoint: boolean;
/** Control registers the gate acts on. */
controls: Register[];
/** Target registers the gate acts on. */
Expand Down
17 changes: 13 additions & 4 deletions src/Kernel/client/ExecutionPathVisualizer/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,16 @@ const _opToMetadata = (op: Operation | null, registers: RegisterMap): Metadata =

if (op == null) return metadata;

let { gate, displayArgs, controlled, adjoint, controls, targets, children } = op;
let {
gate,
displayArgs,
isMeasurement,
isControlled,
isAdjoint,
controls,
targets,
children
} = op;

// Set y coords
metadata.controlsY = controls.map(reg => _getRegY(reg, registers));
Expand Down Expand Up @@ -216,11 +225,11 @@ const _opToMetadata = (op: Operation | null, registers: RegisterMap): Metadata =
// around all quantum registers.
const qubitsY: number[] = Object.values(registers).map(({ y }) => y);
metadata.targetsY = [Math.min(...qubitsY), Math.max(...qubitsY)];
} else if (gate === 'measure') {
} else if (isMeasurement) {
metadata.type = GateType.Measure;
} else if (gate === 'SWAP') {
metadata.type = GateType.Swap;
} else if (controlled) {
} else if (isControlled) {
metadata.type = (gate === 'X') ? GateType.Cnot : GateType.ControlledUnitary;
metadata.label = gate;
} else {
Expand All @@ -230,7 +239,7 @@ const _opToMetadata = (op: Operation | null, registers: RegisterMap): Metadata =
}

// If adjoint, add ' to the end of gate label
if (adjoint && metadata.label.length > 0) metadata.label += "'";
if (isAdjoint && metadata.label.length > 0) metadata.label += "'";

// If gate has extra arguments, display them
if (displayArgs != null) metadata.displayArgs = displayArgs;
Expand Down
Loading