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
2 changes: 1 addition & 1 deletion src/Simulation/Core/IOperationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IOperationFactory
/// <summary>
/// Returns an instance of the requested operation.
/// </summary>
I Get<I>(Type t);
I Get<I>(Type T);

/// <summary>
/// Returns an instance of the requested operation.
Expand Down
2 changes: 0 additions & 2 deletions src/Simulation/Native/src/simulator/capi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ extern "C"
MICROSOFT_QUANTUM_DECL void destroy(_In_ unsigned sid); // NOLINT
MICROSOFT_QUANTUM_DECL void seed(_In_ unsigned sid, _In_ unsigned s); // NOLINT
MICROSOFT_QUANTUM_DECL void Dump(_In_ unsigned sid, _In_ bool (*callback)(size_t, double, double));

// TODO(rokuzmin): What does it return?
MICROSOFT_QUANTUM_DECL bool DumpQubits(
_In_ unsigned sid,
_In_ unsigned n,
Expand Down
1 change: 0 additions & 1 deletion src/Simulation/Native/src/simulator/simulatorinterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ class SimulatorInterface
{
assert(false);
}
// TODO(rokuzmin): What does it return?
virtual bool dumpQubits(std::vector<logical_qubit_id> const& qs, bool (*callback)(size_t, double, double))
{
assert(false);
Expand Down
39 changes: 29 additions & 10 deletions src/Simulation/Simulators/QuantumSimulator/Dump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,48 @@ protected virtual QVoid Dump<T>(T target, IQArray<Qubit>? qubits = null)
{
var filename = (target is QVoid) ? "" : target.ToString();

// If no file provided, output to the console;
QVoid process(Action<string> channel)
{
var ids = qubits?.Select(q => (uint)q.Id).ToArray() ?? QubitIds;

var dumper = new SimpleDumper(this, channel);
channel($"# wave function for qubits with ids (least to most significant): {string.Join(";", ids)}");

if (!dumper.Dump(qubits))
{
channel("## Qubits were entangled with an external qubit. Cannot dump corresponding wave function. ##");
}

return QVoid.Instance;
}

var logMessage = this.Get<ICallable<string, QVoid>, Microsoft.Quantum.Intrinsic.Message>();

// If no file provided, use `Message` to generate the message into the console;
if (string.IsNullOrWhiteSpace(filename))
{
new DisplayableStateDumper(this).Dump(qubits);
var op = this.Get<ICallable<string, QVoid>, Microsoft.Quantum.Intrinsic.Message>();
return process((msg) => op.Apply(msg));
}
else
{
try
{
using var file = new StreamWriter(filename);
new DisplayableStateDumper(this, file.WriteLine).Dump(qubits);
using (var file = new StreamWriter(filename))
{
return process(file.WriteLine);
}
}
catch (Exception e)
{
var logMessage = this.Get<ICallable<string, QVoid>, Microsoft.Quantum.Intrinsic.Message>();
logMessage.Apply($"[warning] Unable to write state to '{filename}' ({e.Message})");
return QVoid.Instance;
}
}
return QVoid.Instance;
}

public class QsimDumpMachine<T> : Quantum.Diagnostics.DumpMachine<T> // Is inherited (and replaced at runtime)
{ // by (iqsharp's) JupyterDumpMachine<T>.
public class QsimDumpMachine<T> : Quantum.Diagnostics.DumpMachine<T>
{
private QuantumSimulator Simulator { get; }

public QsimDumpMachine(QuantumSimulator m) : base(m)
Expand All @@ -61,8 +80,8 @@ public QsimDumpMachine(QuantumSimulator m) : base(m)
};
}

public class QSimDumpRegister<T> : Quantum.Diagnostics.DumpRegister<T> // Is inherited (and replaced at runtime)
{ // by (iqsharp's) JupyterDumpRegister<T>.
public class QSimDumpRegister<T> : Quantum.Diagnostics.DumpRegister<T>
{
private QuantumSimulator Simulator { get; }

public QSimDumpRegister(QuantumSimulator m) : base(m)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public partial class QuantumSimulator
[DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Dump")]
private static extern void sim_Dump(uint id, DumpCallback callback);

// TODO(rokuzmin): What does it return?
[DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "DumpQubits")]
private static extern bool sim_DumpQubits(uint id, uint cout, uint[] ids, DumpCallback callback);

Expand Down
4 changes: 2 additions & 2 deletions src/Simulation/Simulators/QuantumSimulator/SimulatorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public SimulatorBase(IQubitManager? qubitManager = null, int? seed = null)
}
}

public I Get<I>(Type t)
public I Get<I>(Type T)
{
return (I)this.GetInstance(t);
return (I)this.GetInstance(T);
}

/// <summary>
Expand Down
Loading