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
12 changes: 6 additions & 6 deletions src/Simulation/Common/SimulatorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public virtual I Get<I, T>() where T : AbstractCallable, I

public virtual void Init(AbstractCallable op)
{
op.Init();
op.__Init__();
}

public override AbstractCallable CreateInstance(Type t)
Expand Down Expand Up @@ -395,7 +395,7 @@ public Message(SimulatorBase m) : base(m)
sim = m;
}

public override Func<String, QVoid> Body => (msg) =>
public override Func<String, QVoid> __Body__ => (msg) =>
{
sim.OnLog?.Invoke(msg);
return QVoid.Instance;
Expand All @@ -414,7 +414,7 @@ public GetQubitsAvailableToUse(SimulatorBase m) : base(m)
sim = m;
}

public override Func<QVoid, long> Body => (arg) => sim.QubitManager.GetFreeQubitsCount();
public override Func<QVoid, long> __Body__ => (arg) => sim.QubitManager.GetFreeQubitsCount();
}

/// <summary>
Expand All @@ -429,7 +429,7 @@ public GetQubitsAvailableToBorrow(SimulatorBase m) : base(m)
sim = m;
}

public override Func<QVoid, long> Body => (arg) => sim.QubitManager.GetParentQubitsAvailableToBorrowCount() +
public override Func<QVoid, long> __Body__ => (arg) => sim.QubitManager.GetParentQubitsAvailableToBorrowCount() +
sim.QubitManager.GetFreeQubitsCount();
}

Expand All @@ -446,7 +446,7 @@ public DrawRandomInt(SimulatorBase m) : base(m)
sim = m;
}

public override Func<(long, long), long> Body => arg =>
public override Func<(long, long), long> __Body__ => arg =>
{
var (min, max) = arg;
if (max <= min)
Expand All @@ -470,7 +470,7 @@ public DrawRandomDouble(SimulatorBase m) : base(m)
sim = m;
}

public override Func<(double, double), double> Body => arg =>
public override Func<(double, double), double> __Body__ => arg =>
{
var (min, max) = arg;
if (max <= min)
Expand Down
6 changes: 3 additions & 3 deletions src/Simulation/Core/AbstractCallable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public abstract class AbstractCallable : IApplyData

public AbstractCallable(IOperationFactory m)
{
this.Factory = m;
this.__Factory__ = m;
}

public IOperationFactory Factory { get; private set; }
public IOperationFactory __Factory__ { get; private set; }

/// <summary>
/// This method is called once, to let the Operation initialize and verify its dependencies.
/// </summary>
public abstract void Init();
public abstract void __Init__();

/// <summary>
/// Retrieves the runtime metadata of the Operation. If the Operation has no associated
Expand Down
8 changes: 4 additions & 4 deletions src/Simulation/Core/Functions/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public Function(IOperationFactory m) : base(m)
OperationFunctor ICallable.Variant => OperationFunctor.Body;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public abstract Func<I, O> Body { get; }
public abstract Func<I, O> __Body__ { get; }

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

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

public O Apply(I a)
{
var __result__ = this.Body(a);
var __result__ = this.__Body__(a);
return __result__;
}

Expand Down
10 changes: 5 additions & 5 deletions src/Simulation/Core/Functions/FunctionPartial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.Quantum.Simulation.Core
public class FunctionPartial<P, I, O> : Function<P, O>, ICallable<P, O>
{

public FunctionPartial(Function<I, O> op, Func<P, I> mapper) : base(op.Factory)
public FunctionPartial(Function<I, O> op, Func<P, I> mapper) : base(op.__Factory__)
{
Debug.Assert(op != null);
Debug.Assert(mapper != null);
Expand All @@ -23,7 +23,7 @@ public FunctionPartial(Function<I, O> op, Func<P, I> mapper) : base(op.Factory)
this.Mapper = mapper;
}

public FunctionPartial(Function<I, O> op, object partialTuple) : base(op.Factory)
public FunctionPartial(Function<I, O> op, object partialTuple) : base(op.__Factory__)
{
Debug.Assert(op != null);
Debug.Assert(partialTuple != null);
Expand All @@ -32,7 +32,7 @@ public FunctionPartial(Function<I, O> op, object partialTuple) : base(op.Factory
this.Mapper = PartialMapper.Create<P, I>(partialTuple);
}

public override void Init() { }
public override void __Init__() { }

public ICallable<I, O> BaseOp { get; }

Expand All @@ -43,7 +43,7 @@ public override void Init() { }

OperationFunctor ICallable.Variant => ((ICallable)this.BaseOp).Variant;

public override Func<P, O> Body => (a) =>
public override Func<P, O> __Body__ => (a) =>
{
var args = this.Mapper(a);
return this.BaseOp.Apply(args);
Expand Down Expand Up @@ -79,4 +79,4 @@ public DebuggerProxy(FunctionPartial<P, I, O> op) : base(op)
public ICallable<I, O> Base => _op.BaseOp;
}
}
}
}
2 changes: 1 addition & 1 deletion src/Simulation/Core/Generics/Adjoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface IAdjointable : ICallable
[DebuggerTypeProxy(typeof(GenericAdjoint.DebuggerProxy))]
public class GenericAdjoint : GenericCallable, IApplyData, IOperationWrapper
{
public GenericAdjoint(GenericCallable baseOp) : base(baseOp.Factory, null)
public GenericAdjoint(GenericCallable baseOp) : base(baseOp.__Factory__, null)
{
this.BaseOp = baseOp;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Simulation/Core/Generics/Controlled.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public partial interface IControllable : ICallable
[DebuggerTypeProxy(typeof(GenericControlled.DebuggerProxy))]
public class GenericControlled : GenericCallable, IApplyData, IOperationWrapper
{
public GenericControlled(GenericCallable baseOp) : base(baseOp.Factory, null)
public GenericControlled(GenericCallable baseOp) : base(baseOp.__Factory__, null)
{
this.BaseOp = baseOp;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Simulation/Core/Generics/GenericCallable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public GenericCallable(IOperationFactory m, Type baseOp) : base(m)
_controlled = new Lazy<GenericControlled>(() => new GenericControlled(this));
}

public override void Init() { }
public override void __Init__() { }

public Type OperationType { get; }

Expand Down Expand Up @@ -103,12 +103,12 @@ protected virtual ICallable CreateCallable(Type I, Type O)
op = FindClosedType(I, O);
}

var get = this.Factory.GetType()
var get = this.__Factory__.GetType()
.GetMethod("Get", new Type[0]);

var result = get
.MakeGenericMethod(typeof(ICallable), op)
.Invoke(this.Factory, new object[] { })
.Invoke(this.__Factory__, new object[] { })
as ICallable;

return result;
Expand Down Expand Up @@ -162,7 +162,7 @@ public virtual Type FindClosedType(Type I, Type O)

// Get the list of Parameters of the Invoke method of the Body of the operation:
var expectedParameters = this.OperationType
.GetProperty("Body").PropertyType
.GetProperty("__Body__").PropertyType
.GetMethod("Invoke").GetParameters();

// Tuple in...
Expand All @@ -171,7 +171,7 @@ public virtual Type FindClosedType(Type I, Type O)

// Tuple out...
var expectedReturn = this.OperationType
.GetProperty("Body").PropertyType
.GetProperty("__Body__").PropertyType
.GetMethod("Invoke").ReturnType;
Resolve(expectedReturn, O, typeArgs);

Expand Down
2 changes: 1 addition & 1 deletion src/Simulation/Core/Generics/GenericPartial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class GenericPartial : GenericCallable, IApplyData, IOperationWrapper
{
private Lazy<Qubit[]> __qubits = null;

public GenericPartial(GenericCallable baseOp, object partialValues) : base(baseOp.Factory, null)
public GenericPartial(GenericCallable baseOp, object partialValues) : base(baseOp.__Factory__, null)
{
Debug.Assert(baseOp != null, "Received a null base operation");
Debug.Assert(partialValues != null, "Received a null partial value");
Expand Down
16 changes: 8 additions & 8 deletions src/Simulation/Core/Operations/Adjoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Adjointable(IOperationFactory m) : base(m)
[DebuggerTypeProxy(typeof(AdjointedOperation<,>.DebuggerProxy))]
public class AdjointedOperation<I, O> : Unitary<I>, IApplyData, ICallable, IOperationWrapper
{
public AdjointedOperation(Operation<I, O> op) : base(op.Factory)
public AdjointedOperation(Operation<I, O> op) : base(op.__Factory__)
{
Debug.Assert(typeof(O) == typeof(QVoid));
Debug.Assert(op is Operation<I, QVoid>);
Expand All @@ -54,25 +54,25 @@ public AdjointedOperation(Operation<I, O> op) : base(op.Factory)
public Operation<I, QVoid> BaseOp { get; }
ICallable IOperationWrapper.BaseOperation => BaseOp;

public override void Init() { }
public override void __Init__() { }

string ICallable.Name => ((ICallable)this.BaseOp).Name;
string ICallable.FullName => ((ICallable)this.BaseOp).FullName;
OperationFunctor ICallable.Variant => ((ICallable)this.BaseOp).AdjointVariant();

public override Func<I, QVoid> Body => this.BaseOp.AdjointBody;
public override Func<I, QVoid> __Body__ => this.BaseOp.__AdjointBody__;

public override Func<I, QVoid> AdjointBody => this.BaseOp.Body;
public override Func<I, QVoid> __AdjointBody__ => this.BaseOp.__Body__;

public override Func<(IQArray<Qubit>, I), QVoid> ControlledBody => this.BaseOp.ControlledAdjointBody;
public override Func<(IQArray<Qubit>, I), QVoid> __ControlledBody__ => this.BaseOp.__ControlledAdjointBody__;

public override Func<(IQArray<Qubit>, I), QVoid> ControlledAdjointBody => this.BaseOp.ControlledBody;
public override Func<(IQArray<Qubit>, I), QVoid> __ControlledAdjointBody__ => this.BaseOp.__ControlledBody__;

IEnumerable<Qubit> IApplyData.Qubits => ((IApplyData)this.BaseOp).Qubits;

public override IApplyData __dataIn(I data) => this.BaseOp.__dataIn(data);
public override IApplyData __DataIn__(I data) => this.BaseOp.__DataIn__(data);

public override IApplyData __dataOut(QVoid data) => data;
public override IApplyData __DataOut__(QVoid data) => data;

/// <inheritdoc/>
public override RuntimeMetadata? GetRuntimeMetadata(IApplyData args)
Expand Down
22 changes: 11 additions & 11 deletions src/Simulation/Core/Operations/Controlled.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public In((IQArray<Qubit>, IApplyData) data)
IEnumerable<Qubit> IApplyData.Qubits => Qubit.Concat(Ctrls, BaseData?.Qubits);
}

public ControlledOperation(Operation<I, O> op) : base(op.Factory)
public ControlledOperation(Operation<I, O> op) : base(op.__Factory__)
{
Debug.Assert(typeof(O) == typeof(QVoid));
Debug.Assert(op is Operation<I, QVoid>);
Expand All @@ -71,47 +71,47 @@ public ControlledOperation(Operation<I, O> op) : base(op.Factory)
public Operation<I, QVoid> BaseOp { get; }
ICallable IOperationWrapper.BaseOperation => BaseOp;

public override void Init() { }
public override void __Init__() { }

string ICallable.Name => ((ICallable)this.BaseOp).Name;
string ICallable.FullName => ((ICallable)this.BaseOp).FullName;
OperationFunctor ICallable.Variant => ((ICallable)this.BaseOp).ControlledVariant();

public override Func<(IQArray<Qubit>, I), QVoid> Body => this.BaseOp.ControlledBody;
public override Func<(IQArray<Qubit>, I), QVoid> __Body__ => this.BaseOp.__ControlledBody__;

public override Func<(IQArray<Qubit>, I), QVoid> AdjointBody => this.BaseOp.ControlledAdjointBody;
public override Func<(IQArray<Qubit>, I), QVoid> __AdjointBody__ => this.BaseOp.__ControlledAdjointBody__;

public override Func<(IQArray<Qubit>, (IQArray<Qubit>, I)), QVoid> ControlledBody
public override Func<(IQArray<Qubit>, (IQArray<Qubit>, I)), QVoid> __ControlledBody__
{
get
{
return (__in) =>
{
var (ctrl1, (ctrl2, args)) = __in;
var ctrls = QArray<Qubit>.Add(ctrl1, ctrl2);
return this.BaseOp.ControlledBody.Invoke((ctrls, args));
return this.BaseOp.__ControlledBody__.Invoke((ctrls, args));
};
}
}

public override Func<(IQArray<Qubit>, (IQArray<Qubit>, I)), QVoid> ControlledAdjointBody
public override Func<(IQArray<Qubit>, (IQArray<Qubit>, I)), QVoid> __ControlledAdjointBody__
{
get
{
return (__in) =>
{
var (ctrl1, (ctrl2, args)) = __in;
var ctrls = QArray<Qubit>.Add(ctrl1, ctrl2);
return this.BaseOp.ControlledAdjointBody.Invoke((ctrls, args));
return this.BaseOp.__ControlledAdjointBody__.Invoke((ctrls, args));
};
}
}

IEnumerable<Qubit> IApplyData.Qubits => ((IApplyData)this.BaseOp).Qubits;

public override IApplyData __dataIn((IQArray<Qubit>, I) data) => new In((data.Item1, this.BaseOp.__dataIn(data.Item2)));
public override IApplyData __DataIn__((IQArray<Qubit>, I) data) => new In((data.Item1, this.BaseOp.__DataIn__(data.Item2)));

public override IApplyData __dataOut(QVoid data) => data;
public override IApplyData __DataOut__(QVoid data) => data;

/// <inheritdoc/>
public override RuntimeMetadata? GetRuntimeMetadata(IApplyData args)
Expand All @@ -121,7 +121,7 @@ public override void Init() { }
if (args.Value is ValueTuple<IQArray<Qubit>, I> ctrlArgs)
{
var (controls, baseArgs) = ctrlArgs;
var baseMetadata = this.BaseOp.GetRuntimeMetadata(this.BaseOp.__dataIn(baseArgs));
var baseMetadata = this.BaseOp.GetRuntimeMetadata(this.BaseOp.__DataIn__(baseArgs));
if (baseMetadata == null) return null;
baseMetadata.IsControlled = true;
baseMetadata.Controls = controls.Concat(baseMetadata.Controls);
Expand Down
20 changes: 10 additions & 10 deletions src/Simulation/Core/Operations/Operation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ public Operation(IOperationFactory m) : base(m)
OperationFunctor ICallable.Variant => OperationFunctor.Body;


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

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

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public abstract Func<I, O> Body { get; }
public abstract Func<I, O> __Body__ { get; }

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public virtual Func<I, QVoid> AdjointBody => throw new NotImplementedException();
public virtual Func<I, QVoid> __AdjointBody__ => throw new NotImplementedException();

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public virtual Func<(IQArray<Qubit>, I), QVoid> ControlledBody => throw new NotImplementedException();
public virtual Func<(IQArray<Qubit>, I), QVoid> __ControlledBody__ => throw new NotImplementedException();

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public virtual Func<(IQArray<Qubit>, I), QVoid> ControlledAdjointBody => throw new NotImplementedException();
public virtual Func<(IQArray<Qubit>, I), QVoid> __ControlledAdjointBody__ => throw new NotImplementedException();

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public AdjointedOperation<I, O> Adjoint => _adjoint.Value;
Expand All @@ -92,17 +92,17 @@ public O Apply(I a)

try
{
this.Factory?.StartOperation(this, __dataIn(a));
__result__ = this.Body(a);
this.__Factory__?.StartOperation(this, __DataIn__(a));
__result__ = this.__Body__(a);
}
catch (Exception e)
{
this.Factory?.Fail(System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(e));
this.__Factory__?.Fail(System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(e));
throw;
}
finally
{
this.Factory?.EndOperation(this, __dataOut(__result__));
this.__Factory__?.EndOperation(this, __DataOut__(__result__));
}

return __result__;
Expand Down
Loading