diff --git a/src/CHPSimulator.csproj b/src/CHPSimulator.csproj
index 9e51015..ca36b07 100644
--- a/src/CHPSimulator.csproj
+++ b/src/CHPSimulator.csproj
@@ -5,6 +5,14 @@
AnyCPU;x64
+
+
+
+
+
+
+
+
@@ -19,6 +27,7 @@
MIT
https://github.com/qsharp-community/chp-sim.git
git
+ CHPSimulator.xml
diff --git a/src/CHPSimulator.xml b/src/CHPSimulator.xml
new file mode 100644
index 0000000..9ba93c3
--- /dev/null
+++ b/src/CHPSimulator.xml
@@ -0,0 +1,399 @@
+
+
+
+ CHPSimulator
+
+
+
+
+ Message to show in debugging.
+
+
+
+
+ Gets or sets the message to show for debugging.
+
+
+
+
+ Extension methods for the simulators.
+
+
+
+
+ Set the diagonal line of the matix to the value.
+
+ Matrix type.
+ The matrix.
+ The value to set it at.
+
+
+
+ Swapped the collumns.
+
+ The matrix.
+ Collum to swap with idx2.
+ Collum to swap with idx1.
+
+
+
+ Returns the row of the matrix.
+
+ the matrix type.
+ The matrix.
+ The row that needs to be returned.
+ The row highlighted by idxRow.
+
+
+
+ Returns the column of the matrix.
+
+ the matrix type.
+ The matrix.
+ The column that needs to be returned.
+ The row highlighted by idxColumn.
+
+
+
+ Represents the Row including the phase.
+
+ Row represented as a vector.
+ The rendered row including the phase.
+
+
+
+ Renders the row to a text string.
+
+ The Matrix.
+ Row index.
+ A rendered string of the row.
+
+
+
+ Renders the row to a latex usable text string.
+
+ The Matrix.
+ Row index.
+ A rendered string of the row.
+
+
+
+ Renders the matrix to a text string.
+
+ The Matrix.
+ Include the stabilizers in the string.
+ A rendered string of the table.
+
+
+
+ Renders the matrixto a latex usable text string.
+
+ The Matrix.
+ Include the stabilizers in the string.
+ A rendered string of the table.
+
+
+
+ Split the row into; stabalizers, destabilzers, and phase.
+
+ Boolean representation of the row.
+ 3-Element Tuple with seperated stabalizers, destabilzers, and phase.
+
+
+
+ Calculate the product of the phase.
+
+ Left vector.
+ Right vector.
+ PhaseProduct.
+
+
+
+ Set the row sum for the Matrix.
+
+ The Matrix.
+ Index of vector to.
+ Index of vector from.
+
+
+
+ Set the row sum for the Matrix.
+
+ The vector.
+ The Matrix.
+ Index of vector from.
+
+
+
+ Search the matrix.
+
+ Type of the matrix.
+ Source list to check.
+ Predicate to check.
+ Indices of where predicate is true.
+
+
+
+ Try to find the PauliZ that it can be measured on (if there isn't a measurement on X or Y.).
+
+ The Pauli axis being measured on.
+ The index of the PauliX. -1 otherwise.
+ If it can be measured on a single PauliZ.
+
+
+
+ Runs a given function or operation on the ChpSimulator target machine.
+
+
+
+
+ Initializes a new instance of the class.
+ Default constructor.
+
+ Symbol resolver.
+ Source for confirgarion settings.
+
+
+
+ Gets the ISumbolResolver used to find the function/operation to simulate.
+
+
+
+
+
+
+
+ Simulates a function/operation using the ChpSimulator as target machine.
+ It expects a single input: the name of the function/operation to simulate.
+
+ current parameters for the fuinction.
+ channal connecting up with jupiter.
+ funtion result.
+
+
+
+ Representation of the Tableau.
+
+
+
+
+ Gets or sets the data to be shown in the Tableau format.
+
+
+
+
+ Encodes the Tableau in HTML so it can be rendered by jupiter.
+
+
+
+
+ Initializes a new instance of the class.
+
+ Settings to be used.
+
+
+
+ Gets the mimetype used for rendering that its html.
+
+
+
+
+ Returns the StabilizerTableau into the text as encoded data.
+
+ Should be the StabilizerTableau.
+ Text encoded table.
+
+
+
+ Encodes the Tableau in text so it can be rendered by jupiter.
+
+
+
+
+ Gets the mimetype used for rendering that its text.
+
+
+
+
+ Returns the StabilizerTableau into the text as encoded data.
+
+ Should be the StabilizerTableau.
+ Text encoded table.
+
+
+
+ CHP Simulator class.
+
+
+
+
+ Current allocated qubit count.
+
+
+
+
+ Initializes a new instance of the class.
+
+ Amount of qubits to simulate.
+
+
+
+ Gets or sets the simulator used in this run.
+
+
+
+
+ Temporary check to give a more readable exception as long as there is no dynamic allocations.
+
+ qubits to allocate.
+
+
+
+ Temporary check to give a more readable exception as long as there is no dynamic allocations.
+
+ qubits to allocate.
+ count of qubits to reserve for borrowing.
+
+
+
+ Temporary check to give a more readable exception as long as there is no dynamic allocations.
+
+ qubits to deallocate.
+
+
+
+ Temporary check to give a more readable exception as long as there is no dynamic allocations.
+
+ qubits to deallocate.
+ count of qubits being released.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ CHP Simulator.
+
+
+
+
+ Initializes a new instance of the class.
+
+ Qubits to use for simulation.
+
+
+
+ If diagnostic is enabled, show diagnostic information.
+
+ Diagnostic displayable information.
+
+
+
diff --git a/src/DebugMessage.cs b/src/DebugMessage.cs
index 93073b7..ff5aaa9 100644
--- a/src/DebugMessage.cs
+++ b/src/DebugMessage.cs
@@ -1,5 +1,5 @@
-//
-// Copyright (c) PlaceholderCompany. All rights reserved.
+//
+// Copyright (c) Sarah Kaiser. Licensed under the MIT License.
//
#nullable enable
diff --git a/src/Extensions.cs b/src/Extensions.cs
index fefe8d4..9227717 100644
--- a/src/Extensions.cs
+++ b/src/Extensions.cs
@@ -1,6 +1,5 @@
//
-// Copyright (c) Sarah Kaiser. All rights reserved.
-// Licensed under the MIT License.
+// Copyright (c) Sarah Kaiser. Licensed under the MIT License.
//
// This C# project is based on a Python implementation by @Strilanc here:
@@ -17,6 +16,12 @@ namespace QSharpCommunity.Simulators.Chp
///
internal static class Extensions
{
+ ///
+ /// Set the diagonal line of the matix to the value.
+ ///
+ /// Matrix type.
+ /// The matrix.
+ /// The value to set it at.
internal static void SetDiagonal(this T[,] matrix, T value)
{
// TODO: better safety checking for the num rows
@@ -26,6 +31,12 @@ internal static void SetDiagonal(this T[,] matrix, T value)
}
}
+ ///
+ /// Swapped the collumns.
+ ///
+ /// The matrix.
+ /// Collum to swap with idx2.
+ /// Collum to swap with idx1.
internal static void SwapColumns(this bool[,] matrix, int idx1, int idx2)
{
foreach (var idxRow in Enumerable.Range(0, matrix.GetLength(0)))
@@ -36,6 +47,13 @@ internal static void SwapColumns(this bool[,] matrix, int idx1, int idx2)
}
}
+ ///
+ /// Returns the row of the matrix.
+ ///
+ /// the matrix type.
+ /// The matrix.
+ /// The row that needs to be returned.
+ /// The row highlighted by idxRow.
internal static IEnumerable Row(this T[,] matrix, int idxRow)
{
foreach (var idxColumn in Enumerable.Range(0, matrix.GetLength(1)))
@@ -44,6 +62,13 @@ internal static IEnumerable Row(this T[,] matrix, int idxRow)
}
}
+ ///
+ /// Returns the column of the matrix.
+ ///
+ /// the matrix type.
+ /// The matrix.
+ /// The column that needs to be returned.
+ /// The row highlighted by idxColumn.
internal static IEnumerable Column(this T[,] matrix, int idxColumn)
{
foreach (var idxRow in Enumerable.Range(0, matrix.GetLength(0)))
@@ -52,6 +77,11 @@ internal static IEnumerable Column(this T[,] matrix, int idxColumn)
}
}
+ ///
+ /// Represents the Row including the phase.
+ ///
+ /// Row represented as a vector.
+ /// The rendered row including the phase.
internal static string RowToString(this bool[] vector)
{
var (xs, zs, r) = vector.SplitRow();
@@ -67,17 +97,41 @@ internal static string RowToString(this bool[] vector)
}));
}
+ ///
+ /// Renders the row to a text string.
+ ///
+ /// The Matrix.
+ /// Row index.
+ /// A rendered string of the row.
internal static string RowToString(this bool[,] matrix, int idx) => matrix.Row(idx).ToArray().RowToString();
+ ///
+ /// Renders the row to a latex usable text string.
+ ///
+ /// The Matrix.
+ /// Row index.
+ /// A rendered string of the row.
internal static string RowToLatex(this bool[,] matrix, int idx) =>
string.Join(" & ", matrix.Row(idx).ToArray().Select(val => val ? 1 : 0));
+ ///
+ /// Renders the matrix to a text string.
+ ///
+ /// The Matrix.
+ /// Include the stabilizers in the string.
+ /// A rendered string of the table.
internal static string MatrixToString(this bool[,] matrix, bool showDestabilizers = false) =>
"<" + string.Join(", ", Enumerable.Range(matrix.GetLength(0) / 2, matrix.GetLength(0) / 2).Select(idx => matrix.RowToString(idx))) + ">" +
(showDestabilizers ?
"| >" + string.Join(", ", Enumerable.Range(0, matrix.GetLength(0) / 2).Select(idx => matrix.RowToString(idx))) + "<" :
">");
+ ///
+ /// Renders the matrixto a latex usable text string.
+ ///
+ /// The Matrix.
+ /// Include the stabilizers in the string.
+ /// A rendered string of the table.
internal static string MatrixToLatexString(this bool[,] matrix, bool showDestabilizers = false) =>
(
showDestabilizers
@@ -86,13 +140,24 @@ internal static string MatrixToLatexString(this bool[,] matrix, bool showDestabi
: string.Empty) +
string.Join(@" \\", Enumerable.Range(matrix.GetLength(0) / 2, matrix.GetLength(0) / 2).Select(idx => matrix.RowToLatex(idx)));
- internal static (bool[] Stabilzers, bool[] DeStabilzers, bool Phase) SplitRow(this IEnumerable row)
+ ///
+ /// Split the row into; stabalizers, destabilzers, and phase.
+ ///
+ /// Boolean representation of the row.
+ /// 3-Element Tuple with seperated stabalizers, destabilzers, and phase.
+ internal static (bool[] Stabalizers, bool[] DeStabilzers, bool Phase) SplitRow(this IEnumerable row)
{
var vector = row.ToArray();
var nQubits = (vector.Length - 1) / 2;
return (vector[0..nQubits], vector[nQubits..^1], vector[^1]);
}
+ ///
+ /// Calculate the product of the phase.
+ ///
+ /// Left vector.
+ /// Right vector.
+ /// PhaseProduct.
internal static bool PhaseProduct(this IEnumerable row1, IEnumerable row2)
{
static int G(bool x1, bool z1, bool x2, bool z2) =>
@@ -116,6 +181,12 @@ static int G(bool x1, bool z1, bool x2, bool z2) =>
return ((r1 ? 2 : 0) + (r2 ? 2 : 0) + acc) % 4 == 2;
}
+ ///
+ /// Set the row sum for the Matrix.
+ ///
+ /// The Matrix.
+ /// Index of vector to.
+ /// Index of vector from.
internal static void SetToRowSum(this bool[,] matrix, int idxTarget, int idxSource)
{
foreach (var idxColumn in Enumerable.Range(0, matrix.GetLength(1) - 1))
@@ -126,6 +197,12 @@ internal static void SetToRowSum(this bool[,] matrix, int idxTarget, int idxSour
matrix[idxTarget, matrix.GetLength(1) - 1] = matrix.Row(idxTarget).PhaseProduct(matrix.Row(idxSource));
}
+ ///
+ /// Set the row sum for the Matrix.
+ ///
+ /// The vector.
+ /// The Matrix.
+ /// Index of vector from.
internal static void SetToRowSum(this bool[] vector, bool[,] matrix, int idxSource)
{
foreach (var idxColumn in Enumerable.Range(0, matrix.GetLength(1) - 1))
@@ -136,6 +213,13 @@ internal static void SetToRowSum(this bool[] vector, bool[,] matrix, int idxSour
vector[matrix.GetLength(1) - 1] = vector.PhaseProduct(matrix.Row(idxSource));
}
+ ///
+ /// Search the matrix.
+ ///
+ /// Type of the matrix.
+ /// Source list to check.
+ /// Predicate to check.
+ /// Indices of where predicate is true.
internal static IEnumerable IndicesWhere(this IEnumerable source, Func predicate)
{
foreach (var item in source.Select((element, idx) => (element, idx)))
@@ -147,6 +231,12 @@ internal static IEnumerable IndicesWhere(this IEnumerable source, Fun
}
}
+ ///
+ /// Try to find the PauliZ that it can be measured on (if there isn't a measurement on X or Y.).
+ ///
+ /// The Pauli axis being measured on.
+ /// The index of the PauliX. -1 otherwise.
+ /// If it can be measured on a single PauliZ.
internal static bool TryGetSingleZ(this IEnumerable paulis, out int idx)
{
if (paulis.Any(basis => basis == Pauli.PauliX || basis == Pauli.PauliY))
diff --git a/src/StabilizerProcessor.cs b/src/StabilizerProcessor.cs
index 56b33a1..d2636c1 100644
--- a/src/StabilizerProcessor.cs
+++ b/src/StabilizerProcessor.cs
@@ -1,6 +1,5 @@
//
-// Copyright (c) Sarah Kaiser. All rights reserved.
-// Licensed under the MIT License.
+// Copyright (c) Sarah Kaiser. Licensed under the MIT License.
//
#nullable enable
@@ -322,6 +321,7 @@ public override void AssertProb(IQArray bases, IQArray qubits, dou
}
}
+ ///
public override Result M(Qubit qubit) => this.MeasureByIndex(qubit.Id);
///
diff --git a/src/StabilizerSimulator.cs b/src/StabilizerSimulator.cs
index bcc507b..8b6b118 100644
--- a/src/StabilizerSimulator.cs
+++ b/src/StabilizerSimulator.cs
@@ -1,6 +1,5 @@
//
-// Copyright (c) Sarah Kaiser. All rights reserved.
-// Licensed under the MIT License.
+// Copyright (c) Sarah Kaiser. Licensed under the MIT License.
//
// This C# project is based on a Python implementation by @Strilanc here:
// https://github.com/Strilanc/python-chp-stabilizer-simulator
@@ -11,14 +10,25 @@ namespace QSharpCommunity.Simulators.Chp
using Microsoft.Quantum.Simulation.Common;
using Microsoft.Quantum.Simulation.QuantumProcessor;
+ ///
+ /// CHP Simulator.
+ ///
public class StabilizerSimulator : QuantumProcessorDispatcher
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Qubits to use for simulation.
public StabilizerSimulator(int? nQubits = null)
: base(new StabilizerProcessor(nQubits))
{
(this.QuantumProcessor as StabilizerProcessor).Simulator = this;
}
+ ///
+ /// If diagnostic is enabled, show diagnostic information.
+ ///
+ /// Diagnostic displayable information.
internal new void MaybeDisplayDiagnostic(object displayable) =>
base.MaybeDisplayDiagnostic(displayable);
}
diff --git a/src/jupyter/ChpMagic.cs b/src/jupyter/ChpMagic.cs
index 01ade12..46c74c3 100644
--- a/src/jupyter/ChpMagic.cs
+++ b/src/jupyter/ChpMagic.cs
@@ -1,6 +1,5 @@
//
-// Copyright (c) Sarah Kaiser. All rights reserved.
-// Licensed under the MIT License.
+// Copyright (c) Sarah Kaiser. Licensed under the MIT License.
//
// Adapted from Toffoli magic command in the IQSharp project here:
// https://github.com/microsoft/iqsharp/blob/master/src/Kernel/Magic/ToffoliMagic.cs
diff --git a/src/jupyter/StabilizerTableau.cs b/src/jupyter/StabilizerTableau.cs
index 1a1fd1f..0ce12a5 100644
--- a/src/jupyter/StabilizerTableau.cs
+++ b/src/jupyter/StabilizerTableau.cs
@@ -1,5 +1,5 @@
//
-// Copyright (c) PlaceholderCompany. All rights reserved.
+// Copyright (c) Sarah Kaiser. Licensed under the MIT License.
//
// Adapted from State display encoders in the IQSharp project here:
// https://github.com/microsoft/iqsharp/blob/master/src/Jupyter/Visualization/StateDisplayEncoders.cs
diff --git a/src/jupyter/TableauToHtmlEncoder.cs b/src/jupyter/TableauToHtmlEncoder.cs
index fc96249..d8519ca 100644
--- a/src/jupyter/TableauToHtmlEncoder.cs
+++ b/src/jupyter/TableauToHtmlEncoder.cs
@@ -1,6 +1,5 @@
//
-// Copyright (c) Sarah Kaiser. All rights reserved.
-// Licensed under the MIT License.
+// Copyright (c) Sarah Kaiser. Licensed under the MIT License.
//
// Adapted from State display encoders in the IQSharp project here:
// https://github.com/microsoft/iqsharp/blob/master/src/Jupyter/Visualization/StateDisplayEncoders.cs
@@ -13,19 +12,31 @@ namespace QSharpCommunity.Simulators.Chp
using Microsoft.Quantum.IQSharp.Jupyter;
///
- /// Tableau visualizer for jupiter.
+ /// Encodes the Tableau in HTML so it can be rendered by jupiter.
///
public class TableauToHtmlEncoder : IResultEncoder
{
private readonly IConfigurationSource configurationSource;
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Settings to be used.
public TableauToHtmlEncoder(IConfigurationSource configurationSource)
{
this.configurationSource = configurationSource;
}
+ ///
+ /// Gets the mimetype used for rendering that its html.
+ ///
public string MimeType => MimeTypes.Html;
+ ///
+ /// Returns the StabilizerTableau into the text as encoded data.
+ ///
+ /// Should be the StabilizerTableau.
+ /// Text encoded table.
public EncodedData? Encode(object displayable)
{
if (displayable is StabilizerTableau tableau)
diff --git a/src/jupyter/TableauToTextEncoder.cs b/src/jupyter/TableauToTextEncoder.cs
index 1510787..762cf1c 100644
--- a/src/jupyter/TableauToTextEncoder.cs
+++ b/src/jupyter/TableauToTextEncoder.cs
@@ -1,6 +1,5 @@
//
-// Copyright (c) Sarah Kaiser. All rights reserved.
-// Licensed under the MIT License.
+// Copyright (c) Sarah Kaiser. Licensed under the MIT License.
//
// Adapted from State display encoders in the IQSharp project here:
// https://github.com/microsoft/iqsharp/blob/master/src/Jupyter/Visualization/StateDisplayEncoders.cs
@@ -12,10 +11,21 @@ namespace QSharpCommunity.Simulators.Chp
using Microsoft.Jupyter.Core;
using Microsoft.Quantum.IQSharp.Jupyter;
+ ///
+ /// Encodes the Tableau in text so it can be rendered by jupiter.
+ ///
public class TableauToTextEncoder : IResultEncoder
{
+ ///
+ /// Gets the mimetype used for rendering that its text.
+ ///
public string MimeType => MimeTypes.PlainText;
+ ///
+ /// Returns the StabilizerTableau into the text as encoded data.
+ ///
+ /// Should be the StabilizerTableau.
+ /// Text encoded table.
public EncodedData? Encode(object displayable)
{
if (displayable is StabilizerTableau tableau)
diff --git a/src/stylecop.json b/src/stylecop.json
index 2a3a4bd..81e1abb 100644
--- a/src/stylecop.json
+++ b/src/stylecop.json
@@ -9,7 +9,7 @@
"settings": {
"documentationRules": {
"companyName": "https://qsharp.community/",
- "copyrightText": "Copyright (c) Sarah Kaiser. All rights reserved."
+ "copyrightText": "Copyright (c) Sarah Kaiser. Licensed under the MIT License."
}
}
}