public void PartialUDT() { var target = new FreeQubit(0); var op = new QrackSimulator().Get <ICallable <(String, (Qubit, Double)), Circuits.FooUDT> >(typeof(Circuits.FooUDT)) .Partial <double>((double d) => (("bar", (target, d)))); var args = new QTuple <double>(2.1); var expected = new RuntimeMetadata() { Label = "FooUDT", FormattedNonQubitArgs = "(\"bar\", (" + 2.1 + "))", IsAdjoint = false, IsControlled = false, IsMeasurement = false, IsComposite = false, Children = null, Controls = new List <Qubit>() { }, Targets = new List <Qubit>() { }, }; Assert.Equal(op.GetRuntimeMetadata(args), expected); }
private float IndexTable(GameState state, Position?move) { var tuple = new QTuple(state, move); if (!QTable.ContainsKey(tuple)) { QTable.Add(tuple, 0); } return(QTable[tuple]); }
public override bool CanConvert(Type typeToConvert) { if (!typeToConvert.IsGenericType) { return(false); } if (typeToConvert.GetGenericTypeDefinition() != typeof(Dictionary <,>)) { return(false); } QTuple test = new QTuple(new GameState(), null); return(typeToConvert.GetGenericArguments()[0].Equals(test.GetType())); }
public void QubitTypes() { var q = new FreeQubit(0); Assert.Null(q.GetNonQubitArgumentsAsString()); var qs = new QArray <Qubit>(new[] { new FreeQubit(0) }); Assert.Null(qs.GetNonQubitArgumentsAsString()); qs = new QArray <Qubit>(new[] { new FreeQubit(0), new FreeQubit(1) }); Assert.Null(qs.GetNonQubitArgumentsAsString()); var qtuple = new QTuple <Qubit>(q); Assert.Null(qtuple.GetNonQubitArgumentsAsString()); }
public void SarsaUpdate(GameState state, Position?action, GameState?statePrime, Position?actionPrime) { IndexTable(state, action); var tuple = new QTuple(state, action); if (statePrime != null) { IndexTable((GameState)statePrime, actionPrime); var tuplePrime = new QTuple((GameState)statePrime, actionPrime); float value = QTable[tuple] + StepSize * (StateReward(state) - Discount * QTable[tuplePrime] - QTable[tuple]); QTable[tuple] = value; } else { QTable[tuple] = StateReward(state); } }
private static string TupleToJson(QTuple tuple) { return(tuple.Item1.ToString() + "|" + tuple.Item2.ToString()); }