Commit 485f88d6 authored by Mikko Lainio's avatar Mikko Lainio 🇺🇦
Browse files

Updated with noise parameter

parent ea743dbd
......@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Numerics;
using UnityEngine;
using Python.Runtime;
using UnityEngine.Serialization;
using Vector3 = UnityEngine.Vector3;
public class QuantumDemoManager : MonoBehaviour
......@@ -23,13 +24,15 @@ public class QuantumDemoManager : MonoBehaviour
}
}
private HangerController m_left;
private HangerController m_right;
private HangerController m_mid;
private WellController m_left;
private WellController m_right;
private WellController m_mid;
private StirapEnv m_env;
public float UpdateFrequency;
[Tooltip("Steps per second")]
[SerializeField] private float m_updateFrequency = 60;
public float UpdateIntervalSeconds => 1f / m_updateFrequency;
[SerializeField] private TMPro.TextMeshProUGUI m_timeStepText;
[SerializeField] private TMPro.TextMeshProUGUI m_scoreText;
[SerializeField] private TMPro.TextMeshProUGUI m_growthText;
......@@ -44,6 +47,7 @@ public class QuantumDemoManager : MonoBehaviour
[SerializeField] private LineRenderer m_plotRenderer;
[SerializeField] private PlotAccuracy m_plotAccuracy = PlotAccuracy.Max;
[SerializeField] private VisualizeMode m_plotVisualizeMode;
[SerializeField] private float m_noise = 0f;
public enum VisualizeMode
{
......@@ -148,7 +152,7 @@ public class QuantumDemoManager : MonoBehaviour
// To be safe, add a using (Py.Gil()) block every time you interact with any python wrapper class like StirapEnv
using (Python.Runtime.Py.GIL())
{
m_env = new StirapEnv(TimeSteps+1);
m_env = m_noise > 0 ? new StirapEnv(TimeSteps+1, m_noise) : new StirapEnv(TimeSteps+1);
}
}
......@@ -168,7 +172,10 @@ public class QuantumDemoManager : MonoBehaviour
do
{
time = Time.time;
yield return new WaitForSeconds(UpdateFrequency);
if (UpdateIntervalSeconds > 0)
yield return new WaitForSeconds(UpdateIntervalSeconds);
else
yield return null;
delta = Time.time - time;
if (m_timeStepText != null)
......@@ -226,7 +233,7 @@ public class QuantumDemoManager : MonoBehaviour
return result.Done;
}
private void UpdateWell(HangerController t, float value, RingBuffer growthMeasure)
private void UpdateWell(WellController t, float value, RingBuffer growthMeasure)
{
Vector3 p = t.transform.position;
float last = p.y;
......@@ -299,15 +306,15 @@ public class QuantumDemoManager : MonoBehaviour
}
public static void RegisterController(HangerController ctrl, HangerController.CubePosition cPosition)
public static void RegisterController(WellController ctrl, WellController.CubePosition cPosition)
{
switch (cPosition)
{
case HangerController.CubePosition.Left: Instance.m_left = ctrl;
case WellController.CubePosition.Left: Instance.m_left = ctrl;
break;
case HangerController.CubePosition.Right: Instance.m_right = ctrl;
case WellController.CubePosition.Right: Instance.m_right = ctrl;
break;
case HangerController.CubePosition.Mid: Instance.m_mid = ctrl;
case WellController.CubePosition.Mid: Instance.m_mid = ctrl;
break;
}
}
......
......@@ -4,7 +4,7 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
public class HangerController : MonoBehaviour
public class WellController : MonoBehaviour
{
public enum CubePosition
{
......
......@@ -60,6 +60,17 @@ public class StirapEnv
{
m_stirap = PythonManager.Instance.StirapEnv.StirapEnv(false, new PyInt(timeSteps));
}
/// <summary>
/// Constructor with noise parameter
/// </summary>
/// <param name="timeSteps"></param>
/// <param name="noise">max randomness for the function</param>
public StirapEnv(int timeSteps, float noise)
{
m_stirap = PythonManager.Instance.StirapEnv.StirapEnv(false, new PyInt(timeSteps), new PyFloat(noise));
}
/// <summary>
/// Run a single simulation step. movements for the left and right wells between -1 and 1
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment