Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feedback-guided scheduling algorithms #791

Merged
merged 29 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c7dd158
Add feedback strategy. (#715)
aoli-al Apr 8, 2024
c6f74dc
Improving the code with some cleanup. (#719)
ankushdesai Apr 15, 2024
3f4781a
PR cleanup (#723)
aoli-al Apr 25, 2024
9241ed4
Merge Recent Bug Fixes (#778)
ankushdesai Oct 1, 2024
9446874
Fix feedback strategy and remove experiment features.
aoli-al Oct 3, 2024
5c98bc9
Merge branch 'master' into experimental/feedback-strategy
aoli-al Oct 3, 2024
9d91a54
Removing Pattern (#786)
ChristineZh0u Oct 8, 2024
5f65c5c
Remove conflict analysis
Oct 8, 2024
6537ce6
Merge pull request #787 from p-org/experimental/feedback_cleanup
ChristineZh0u Oct 8, 2024
ccaa276
Removing compiler changes (#789)
ChristineZh0u Oct 9, 2024
61fa8d3
Cleanup.
aoli-al Oct 10, 2024
548f0f6
Revert changes to Event.
aoli-al Oct 10, 2024
e2dc756
Merge branch 'master' into experimental/feedback
ankushdesai Oct 10, 2024
52dc10a
Revert changes.
aoli-al Oct 11, 2024
cfdc88e
Merge branch 'master' into experimental/feedback
aoli-al Oct 11, 2024
8510ec4
Fix merge conflicts.
aoli-al Oct 11, 2024
6262502
Remove temp file.
aoli-al Oct 11, 2024
c183bcb
Merge branch 'master' into experimental/feedback
ChristineZh0u Oct 11, 2024
907dcd1
Rename LastSentReceiver to MessageReceiver
aoli-al Oct 12, 2024
0a371a8
Merge branch 'master' into experimental/feedback
ankushdesai Oct 14, 2024
6a4110c
Merge branch 'master' into experimental/feedback
ankushdesai Oct 17, 2024
8153cd6
Simplify scheduler implementation.
aoli-al Oct 17, 2024
d8331b8
Revert changes in QLearning strategy.
aoli-al Oct 17, 2024
b4837da
Refactor.
aoli-al Oct 17, 2024
6bd65eb
Merge branch 'master' into experimental/feedback
ankushdesai Oct 17, 2024
2eda040
Added VectorTime and BehavioralObserver class for feedback strategy (…
ChristineZh0u Oct 18, 2024
5e306b4
Revert changes in PCTStrategy.
aoli-al Oct 18, 2024
91cd717
Revert changes in Probabilistic folder.
aoli-al Oct 18, 2024
3ee77e3
revert change.
aoli-al Oct 18, 2024
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: 2 additions & 0 deletions Src/PChecker/CheckerCore/Coverage/CoverageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public CoverageInfo()
Machines = new HashSet<string>();
MachinesToStates = new Dictionary<string, HashSet<string>>();
RegisteredEvents = new Dictionary<string, HashSet<string>>();
EventInfo = new EventCoverage();
CoverageGraph = new Graph();
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions Src/PChecker/CheckerCore/Random/IRandomValueGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;

namespace PChecker.Random
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Threading.Tasks;
using PChecker.Coverage;
using PChecker.Exceptions;
using PChecker.Feedback;
using PChecker.Random;
using PChecker.Runtime.Events;
using PChecker.Runtime.Logging;
Expand Down Expand Up @@ -150,7 +151,6 @@ private static ControlledRuntime CreateWithConfiguration(CheckerConfiguration ch
/// </summary>
public JsonWriter JsonLogger => LogWriter.JsonLogger;


/// <summary>
/// Returns the current hashed state of the monitors.
/// </summary>
Expand Down Expand Up @@ -618,6 +618,8 @@ private EnqueueStatus EnqueueEvent(StateMachineId targetId, Event e, StateMachin
"Cannot send event '{0}' to state machine id '{1}' that is not bound to an state machine instance.",
e.GetType().FullName, targetId.Value);

Scheduler.ScheduledOperation.LastSentReceiver = targetId.ToString();
ankushdesai marked this conversation as resolved.
Show resolved Hide resolved
aoli-al marked this conversation as resolved.
Show resolved Hide resolved

Scheduler.ScheduleNextEnabledOperation(AsyncOperationType.Send);
ResetProgramCounter(sender);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ internal abstract class AsyncOperation : IAsyncOperation
/// True if the next awaiter is controlled, else false.
/// </summary>
internal bool IsAwaiterControlled;

/// <summary>
/// The receiver if the operation is Send.
/// </summary>
ankushdesai marked this conversation as resolved.
Show resolved Hide resolved
public string LastSentReceiver = "";

/// <summary>
/// Initializes a new instance of the <see cref="AsyncOperation"/> class.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
using System;
using System.Collections.Generic;
using System.Linq;
using PChecker.Runtime.Events;
using PChecker.Runtime.Logging;
using PChecker.Runtime.StateMachines;

namespace PChecker.Feedback;

internal class TimelineObserver: IControlledRuntimeLog
{

private HashSet<(string, string, string)> _timelines = new();
private Dictionary<string, HashSet<string>> _allEvents = new();
private Dictionary<string, List<string>> _orderedEvents = new();
private IControlledRuntimeLog _controlledRuntimeLogImplementation;

public static readonly List<(int, int)> Coefficients = new();
public static int NumOfCoefficients = 50;

static TimelineObserver()
{
// Fix seed to generate same random numbers across runs.
var rand = new System.Random(0);

for (int i = 0; i < NumOfCoefficients; i++)
{
Coefficients.Add((rand.Next(), rand.Next()));
}
}

public int GetTimelineHash()
{
return GetAbstractTimeline().GetHashCode();
}

public string GetAbstractTimeline()
{
var tls = _timelines.Select(it => $"<{it.Item1}, {it.Item2}, {it.Item3}>").ToList();
tls.Sort();
return string.Join(";", tls);
}

public string GetTimeline()
{
return string.Join(";", _orderedEvents.Select(it =>
{
var events = string.Join(",", it.Value);
return $"{it.Key}: {events}";
}));
}

public List<int> GetTimelineMinhash()
{
List<int> minHash = new();
var timelineHash = _timelines.Select(it => it.GetHashCode());
foreach (var (a, b) in Coefficients)
{
int minValue = Int32.MaxValue;
foreach (var value in timelineHash)
{
int hash = a * value + b;
minValue = Math.Min(minValue, hash);
}
minHash.Add(minValue);
}
return minHash;
}

public void OnCreateStateMachine(StateMachineId id, string creatorName, string creatorType)
{
}

public void OnExecuteAction(StateMachineId id, string handlingStateName, string currentStateName, string actionName)
{
}

public void OnSendEvent(StateMachineId targetStateMachineId, string senderName, string senderType, string senderStateName,
Event e, bool isTargetHalted)
{
}

public void OnRaiseEvent(StateMachineId id, string stateName, Event e)
{
}

public void OnEnqueueEvent(StateMachineId id, Event e)
{
}

public void OnDequeueEvent(StateMachineId id, string stateName, Event e)
{
string actor = id.Type;

_allEvents.TryAdd(actor, new());
_orderedEvents.TryAdd(actor, new());

string name = e.GetType().Name;
foreach (var ev in _allEvents[actor])
{
_timelines.Add((actor, ev, name));
}
_allEvents[actor].Add(name);
_orderedEvents[actor].Add(name);
}

public void OnReceiveEvent(StateMachineId id, string stateName, Event e, bool wasBlocked)
{
}

public void OnWaitEvent(StateMachineId id, string stateName, Type eventType)
{
}

public void OnWaitEvent(StateMachineId id, string stateName, params Type[] eventTypes)
{
}

public void OnStateTransition(StateMachineId id, string stateName, bool isEntry)
{
}

public void OnGotoState(StateMachineId id, string currentStateName, string newStateName)
{
}

public void OnDefaultEventHandler(StateMachineId id, string stateName)
{
}

public void OnHalt(StateMachineId id, int inboxSize)
{
}

public void OnHandleRaisedEvent(StateMachineId id, string stateName, Event e)
{
}

public void OnPopStateUnhandledEvent(StateMachineId id, string stateName, Event e)
{
}

public void OnExceptionThrown(StateMachineId id, string stateName, string actionName, Exception ex)
{
}

public void OnExceptionHandled(StateMachineId id, string stateName, string actionName, Exception ex)
{
}

public void OnCreateMonitor(string monitorType)
{
}

public void OnMonitorExecuteAction(string monitorType, string stateName, string actionName)
{
}

public void OnMonitorProcessEvent(string monitorType, string stateName, string senderName, string senderType,
string senderStateName, Event e)
{
}

public void OnMonitorRaiseEvent(string monitorType, string stateName, Event e)
{
}

public void OnMonitorStateTransition(string monitorType, string stateName, bool isEntry, bool? isInHotState)
{
}

public void OnMonitorError(string monitorType, string stateName, bool? isInHotState)
{
}

public void OnRandom(object result, string callerName, string callerType)
{
}

public void OnAssertionFailure(string error)
{
}

public void OnStrategyDescription(string strategyName, string description)
{
}

public void OnCompleted()
{
}
}
Loading
Loading