qsharp-lang 1.8.6-dev → 1.9.1-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,6 +14,11 @@ interface DumpMsg {
14
14
  state: Dump;
15
15
  stateLatex: string | null;
16
16
  }
17
+ interface MatrixMsg {
18
+ type: "Matrix";
19
+ matrix: number[][][];
20
+ matrixLatex: string;
21
+ }
17
22
  interface MessageMsg {
18
23
  type: "Message";
19
24
  message: string;
@@ -22,11 +27,11 @@ interface ResultMsg {
22
27
  type: "Result";
23
28
  result: Result;
24
29
  }
25
- type EventMsg = ResultMsg | DumpMsg | MessageMsg;
30
+ type EventMsg = ResultMsg | DumpMsg | MatrixMsg | MessageMsg;
26
31
  export declare function eventStringToMsg(msg: string): EventMsg | null;
27
32
  export type ShotResult = {
28
33
  success: boolean;
29
34
  result: string | VSDiagnostic;
30
- events: Array<MessageMsg | DumpMsg>;
35
+ events: Array<MessageMsg | DumpMsg | MatrixMsg>;
31
36
  };
32
37
  export {};
@@ -42,6 +42,21 @@ function outputAsDump(msg) {
42
42
  }
43
43
  return null;
44
44
  }
45
+ function outputAsMatrix(msg) {
46
+ try {
47
+ const obj = JSON.parse(msg);
48
+ if (obj?.type == "Matrix" && Array.isArray(obj.matrix)) {
49
+ return obj;
50
+ }
51
+ }
52
+ catch {
53
+ return null;
54
+ }
55
+ return null;
56
+ }
45
57
  export function eventStringToMsg(msg) {
46
- return outputAsResult(msg) || outputAsMessage(msg) || outputAsDump(msg);
58
+ return (outputAsResult(msg) ||
59
+ outputAsMessage(msg) ||
60
+ outputAsDump(msg) ||
61
+ outputAsMatrix(msg));
47
62
  }
@@ -109,6 +109,12 @@ export function onCompilerEvent(msg, eventTarget) {
109
109
  case "Result":
110
110
  qscEvent = makeEvent("Result", qscMsg.result);
111
111
  break;
112
+ case "Matrix":
113
+ qscEvent = makeEvent("Matrix", {
114
+ matrix: qscMsg.matrix,
115
+ matrixLatex: qscMsg.matrixLatex,
116
+ });
117
+ break;
112
118
  default:
113
119
  log.never(msgType);
114
120
  throw "Unexpected message type";
@@ -130,5 +136,5 @@ export const compilerProtocol = {
130
136
  run: "requestWithProgress",
131
137
  checkExerciseSolution: "requestWithProgress",
132
138
  },
133
- eventNames: ["DumpMachine", "Message", "Result"],
139
+ eventNames: ["DumpMachine", "Matrix", "Message", "Result"],
134
140
  };
@@ -9,6 +9,12 @@ export type QscEventData = {
9
9
  state: Dump;
10
10
  stateLatex: string | null;
11
11
  };
12
+ } | {
13
+ type: "Matrix";
14
+ detail: {
15
+ matrix: number[][][];
16
+ matrixLatex: string;
17
+ };
12
18
  } | {
13
19
  type: "Result";
14
20
  detail: Result;
@@ -40,6 +46,7 @@ export declare class QscEventTarget implements IQscEventTarget {
40
46
  */
41
47
  constructor(captureEvents: boolean);
42
48
  private onMessage;
49
+ private onMatrix;
43
50
  private onDumpMachine;
44
51
  private onResult;
45
52
  private ensureActiveShot;
@@ -35,6 +35,7 @@ export class QscEventTarget {
35
35
  this.addEventListener("Message", (ev) => this.onMessage(ev.detail));
36
36
  this.addEventListener("DumpMachine", (ev) => this.onDumpMachine(ev.detail));
37
37
  this.addEventListener("Result", (ev) => this.onResult(ev.detail));
38
+ this.addEventListener("Matrix", (ev) => this.onMatrix(ev.detail));
38
39
  }
39
40
  }
40
41
  onMessage(msg) {
@@ -43,6 +44,16 @@ export class QscEventTarget {
43
44
  this.results[shotIdx].events.push({ type: "Message", message: msg });
44
45
  this.queueUiRefresh();
45
46
  }
47
+ onMatrix(detail) {
48
+ this.ensureActiveShot();
49
+ const shotIdx = this.results.length - 1;
50
+ this.results[shotIdx].events.push({
51
+ type: "Matrix",
52
+ matrix: detail.matrix,
53
+ matrixLatex: detail.matrixLatex,
54
+ });
55
+ this.queueUiRefresh();
56
+ }
46
57
  onDumpMachine(detail) {
47
58
  this.ensureActiveShot();
48
59
  const shotIdx = this.results.length - 1;
@@ -75,6 +75,12 @@ export function onCompilerEvent(msg, eventTarget) {
75
75
  case "Result":
76
76
  qscEvent = makeEvent("Result", qscMsg.result);
77
77
  break;
78
+ case "Matrix":
79
+ qscEvent = makeEvent("Matrix", {
80
+ matrix: qscMsg.matrix,
81
+ matrixLatex: qscMsg.matrixLatex,
82
+ });
83
+ break;
78
84
  default:
79
85
  log.never(msgType);
80
86
  throw "Unexpected message type";
@@ -98,5 +104,5 @@ export const debugServiceProtocol = {
98
104
  evalStepOut: "requestWithProgress",
99
105
  dispose: "request",
100
106
  },
101
- eventNames: ["DumpMachine", "Message", "Result"],
107
+ eventNames: ["DumpMachine", "Message", "Matrix", "Result"],
102
108
  };
@@ -0,0 +1,43 @@
1
+ ---
2
+ uid: Qdk.Std.Diagnostics.DumpOperation
3
+ title: DumpOperation operation
4
+ ms.date: 09/30/2024 12:00:00 AM
5
+ ms.topic: managed-reference
6
+ qsharp.kind: operation
7
+ qsharp.namespace: Std.Diagnostics
8
+ qsharp.name: DumpOperation
9
+ qsharp.summary: "Given an operation, dumps the matrix representation of the operation action on the given number of qubits."
10
+ ---
11
+
12
+ # DumpOperation operation
13
+
14
+ Fully qualified name: Std.Diagnostics.DumpOperation
15
+
16
+ ```qsharp
17
+ operation DumpOperation(nQubits : Int, op : (Qubit[] => Unit is Adj)) : Unit
18
+ ```
19
+
20
+ ## Summary
21
+ Given an operation, dumps the matrix representation of the operation action on the given
22
+ number of qubits.
23
+
24
+ ## Input
25
+ ### nQubits
26
+ The number of qubits on which the given operation acts.
27
+ ### op
28
+ The operation that is to be diagnosed.
29
+
30
+ ## Remarks
31
+ When run on the sparse-state simulator, the following snippet
32
+ will output the matrix
33
+ $\left(\begin{matrix} 0.0 & 0.707 \\\\ 0.707 & 0.0\end{matrix}\right)$:
34
+
35
+ ```qsharp
36
+ operation DumpH() : Unit {
37
+ DumpOperation(1, qs => H(qs[0]));
38
+ }
39
+ ```
40
+ Calling this operation has no observable effect from within Q#.
41
+ Note that if `DumpOperation` is called when there are other qubits allocated,
42
+ the matrix displayed may reflect any global phase that has accumulated from operations
43
+ on those other qubits.
package/docs/toc.yml CHANGED
@@ -140,6 +140,7 @@
140
140
  uid: Qdk.Std.Core
141
141
  - items:
142
142
  - {name: DumpMachine, uid: Qdk.Std.Diagnostics.DumpMachine}
143
+ - {name: DumpOperation, uid: Qdk.Std.Diagnostics.DumpOperation}
143
144
  - {name: DumpRegister, uid: Qdk.Std.Diagnostics.DumpRegister}
144
145
  - {name: Fact, uid: Qdk.Std.Diagnostics.Fact}
145
146
  name: Std.Diagnostics
@@ -1537,8 +1537,8 @@ module.exports.__wbindgen_memory = function() {
1537
1537
  return addHeapObject(ret);
1538
1538
  };
1539
1539
 
1540
- module.exports.__wbindgen_closure_wrapper902 = function(arg0, arg1, arg2) {
1541
- const ret = makeMutClosure(arg0, arg1, 363, __wbg_adapter_52);
1540
+ module.exports.__wbindgen_closure_wrapper905 = function(arg0, arg1, arg2) {
1541
+ const ret = makeMutClosure(arg0, arg1, 364, __wbg_adapter_52);
1542
1542
  return addHeapObject(ret);
1543
1543
  };
1544
1544
 
Binary file
@@ -1475,8 +1475,8 @@ function __wbg_get_imports() {
1475
1475
  const ret = wasm.memory;
1476
1476
  return addHeapObject(ret);
1477
1477
  };
1478
- imports.wbg.__wbindgen_closure_wrapper902 = function(arg0, arg1, arg2) {
1479
- const ret = makeMutClosure(arg0, arg1, 363, __wbg_adapter_52);
1478
+ imports.wbg.__wbindgen_closure_wrapper905 = function(arg0, arg1, arg2) {
1479
+ const ret = makeMutClosure(arg0, arg1, 364, __wbg_adapter_52);
1480
1480
  return addHeapObject(ret);
1481
1481
  };
1482
1482
 
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "qsharp-lang",
3
3
  "description": "qsharp language package for quantum development",
4
- "version": "1.8.6-dev",
4
+ "version": "1.9.1-dev",
5
5
  "license": "MIT",
6
6
  "engines": {
7
7
  "node": ">=16.17.0"