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: 7 additions & 7 deletions src/Simulation/Core/Operations/Operation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial interface ICallable<in I, out O> : ICallable
{
O Apply(I args);

ICallable<P,O> Partial<P>(Func<P, I> mapper);
ICallable<P, O> Partial<P>(Func<P, I> mapper);
}

/// <summary>
Expand All @@ -34,7 +34,7 @@ public interface IOperationWrapper
/// </summary>
/// <typeparam name="I">Type of input parameters.</typeparam>
/// <typeparam name="O">Type of return values.</typeparam>
[DebuggerTypeProxy(typeof(Operation<,>.DebuggerProxy))]
[DebuggerTypeProxy(typeof(Operation<,>.DebuggerProxy))]
public abstract class Operation<I, O> : AbstractCallable, ICallable<I, O>
{
private Lazy<AdjointedOperation<I, O>> _adjoint;
Expand All @@ -56,7 +56,7 @@ public Operation(IOperationFactory m) : base(m)


public virtual IApplyData __dataIn(I data) => new QTuple<I>(data);

public virtual IApplyData __dataOut(O data) => new QTuple<O>(data);

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
Expand All @@ -83,7 +83,7 @@ public Operation(IOperationFactory m) : base(m)
{
Label = ((ICallable)this).Name,
FormattedNonQubitArgs = args.GetNonQubitArgumentsAsString() ?? "",
Targets = args.GetQubits() ?? new List<Qubit>(),
Targets = args.GetQubits()?.Distinct() ?? new List<Qubit>(),
};

public O Apply(I a)
Expand All @@ -95,7 +95,7 @@ public O Apply(I a)
this.Factory?.StartOperation(this, __dataIn(a));
__result__ = this.Body(a);
}
catch( Exception e)
catch (Exception e)
{
this.Factory?.Fail(System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(e));
throw;
Expand All @@ -105,7 +105,7 @@ public O Apply(I a)
this.Factory?.EndOperation(this, __dataOut(__result__));
}

return __result__;
return __result__;
}

public T Partial<T>(object partialInfo)
Expand Down Expand Up @@ -212,7 +212,7 @@ internal class DebuggerProxy
{
private Operation<I, O> op;

public DebuggerProxy(Operation<I,O> op)
public DebuggerProxy(Operation<I, O> op)
{
this.op = op;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits {
HOp(q);
}
}

operation TwoQubitOp (q1 : Qubit, q2 : Qubit) : Unit {
// ...
}

}
25 changes: 25 additions & 0 deletions src/Simulation/Simulators.Tests/RuntimeMetadataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,10 @@ public void MResetZ()

Assert.Equal(op.GetRuntimeMetadata(args), expected);
}
}

public class CustomCircuitTests
{
[Fact]
public void EmptyOperation()
{
Expand Down Expand Up @@ -475,6 +478,28 @@ public void NestedOperation()

Assert.Equal(op.GetRuntimeMetadata(args), expected);
}

[Fact]
public void DuplicateQubitArgs()
{
var q = new FreeQubit(0);
var op = new QuantumSimulator().Get<Circuits.TwoQubitOp>();
var args = op.__dataIn((q, q));
var expected = new RuntimeMetadata()
{
Label = "TwoQubitOp",
FormattedNonQubitArgs = "",
IsAdjoint = false,
IsControlled = false,
IsMeasurement = false,
IsComposite = false,
Children = null,
Controls = new List<Qubit>() { },
Targets = new List<Qubit>() { q },
};

Assert.Equal(op.GetRuntimeMetadata(args), expected);
}
}

public class UDTTests
Expand Down