Improving agent performance in fluid environments by perceptual pretraining
Jin Zhang Jianyang Xue Bochao Cao


AIP/123-QED




 cbc@fudan.edu.cn
 
Department of Aeronautics and Astronautics, Fudan University, Shanghai 200433, China

§ ABSTRACT 
In this paper, we construct a pretraining framework for fluid environment perception, which includes an information compression model and the corresponding pretraining method. We test this framework in a two-cylinder problem through numerical simulation. The results show that after unsupervised pretraining with this framework, the intelligent agent can acquire key features of surrounding fluid environment, thereby adapting more quickly and effectively to subsequent multi-scenario tasks. In our research, these tasks include perceiving the position of the upstream obstacle and actively avoiding shedding vortices in the flow field to achieve drag reduction. Better performance of the pretrained agent is discussed in the sensitivity analysis.


Improving agent performance in fluid environments by perceptual pretraining
    Jin Zhang, Jianyang Xue, Bochao Cao^*
    September 9, 2024
===========================================================================





§ INTRODUCTION

In water environments, aquatic animals or underwater robots can be regarded as embodied intelligent agents who collect information (pressure, temperature, vision, etc.) from their surrounding water environments using their sensory organs or electronic sensors. And these time-series information would then be processed by these underwater agents and help them make flow field perception or fulfill underwater missions, such as cruising, obstacle avoidance, and so on.

Embodied intelligent agents acquire knowledge through interactions with their environment, often with limited information, and apply this knowledge across various tasks <cit.>. Reinforcement learning (RL) has emerged as a promising technique for training embodied agents in complex fluid environments<cit.>. In the framework of RL, agents update their decision-making strategies through trials and errors, and finally maximize their cumulative rewards. There have been many successful cases of training embodied agents using RL algorithms. For example, RL has been adopted for training gliders to improve gliding performance in complex convection environments <cit.>, for active flow control to reduce drag <cit.>, and for studying the behavior of both individual fish-like swimmers and fish schooling from a biomimetic perspective <cit.>. Research works by Paris et al. <cit.> and <cit.> indicate the existence of optimal sensor placement for specific scenarios. Placing sensors in highly sensitive regions enables effective flow control even with a limited number of detection points. Wang et al. <cit.> propose that integrating temporal data into agent state variable can significantly enhance performance of the agent. These findings reveal potential advantages of flow control strategies using deep reinforcement learning techniques.

However, most of previous studies focus on training agents to perform well in isolated tasks within fixed scenarios. Given the inherent complexity and nonlinearity of fluid dynamics, training agents to generalize their abilities across different fluid environment remains extremely challenging which demands innovative approaches in both RL frameworks and training methodologies.

Extraction of meaningful representations from collected data might be crucial before training agents to fulfill multiple tasks. Some recent research works have indicated that unsupervised pretraining allows agents to develop a deep understanding of complex patterns and relationships within the data, enhancing their ability to generalize from one task to another. This procedure has been validated in various areas, including large language models <cit.>, computer vision <cit.> and reinforcement learning in video game environments <cit.>. In the area of fluid dynamics, information compression method has also been introduced in several research works. For instance, Fukami et al. <cit.> and Murata et al. <cit.> use nonlinear encoders to compress spatial features of flow fields into low-dimensional manifolds. Racca et al. <cit.> compress flow field data from both temporal and spatial dimensions using nonlinear encoders and successfully predict the development of unsteady turbulent flows by compressed low-dimensional information. 

In this study, we build a spatiotemporal compression model to transform perceptual information collected from a fluid environment into actionable knowledge. We start with unsupervised pretraining which enables the agent to learn environmental information without data labeling. Subsequently, using pretraining knowledge, we test the ability of the agent in different tasks, including obstacle position prediction and drag reduction reinforcement learning. The results illustrate that perceptual compression significantly enhances agent performance across different tasks. Our approach provides a new way of training general-purpose agents capable of various tasks in complex fluid environments.








§ METHODOLOGY



 §.§ Numerical Method

In this research, flow around two streamwisely aligned identical cylinders is simulated in OpenFOAM (http://www.openfoam.comwww.openfoam.com). The downstream cylinder acts as the perceptual intelligent agent in our study, while the upstream one serves as the obstacle which could oscillate in the vertical direction as shown in figure <ref>. The Reynolds number of the incoming flow is set as 100, and hence laminar algorithm is used in the simulation and current problem is solved by incompressible Navier-Stokes equations as shown below, 

    ∂ u_i/∂ x_i = 0




    ∂ u_i/∂ t + u_j ∂ u_i/∂ x_j = -1/ρ∂ p/∂ x_i + ν∂^2 u_i/∂ x_j ∂ x_j



where u_i denotes velocity component in the i-th direction, ρ is the fluid density, p is the pressure, and ν is the kinematic viscosity.

In the simulation, using overset mesh technique, the computational domain is partitioned into overlapping subdomains, each with its own grid. A background mesh spans the entire computational domain, while refined grids are used around the cylinders, as shown in figure <ref>. Computational information is exchanged between these grids through interpolation in overlapping regions. The illustration of computational domain is shown in figure <ref>. The background mesh size is 60D x 40D, where D is the cylinder diameter. The mesh around each cylinder is set in a circular region with diameter of 8D. The cylinders are placed along the centerline of the computational domain, with cylinder 1 located 20D from the inlet and cylinder 2 6D downstream of cylinder 1. Free-stream condition is given at the inlet of computational domain, while far-field condition is set at the other three boundaries, as shown in figure <ref>. A no-slip boundary condition is imposed on the cylinder surfaces. Moreover, since cylinder 2 is set as the perceptual agent in this study, its surface pressure is collected at each computational time step. Validation of current computational method is provided in APPENDIX <ref>.






















 §.§ Perceptual network

The perceptual network consists of a convolutional neural network encoder and a GRU network <cit.>. As shown in figure <ref>, firstly, instant pressure data p is compressed by convolutional neural network encoder, and instantaneous spatial feature z is extracted. The spatial feature is then further compressed in time dimension by a GRU network, yielding the dynamic feature h_t at time instant t. 

In this study, p is a 1×200 vector sampled at 10 Hz. The spatial encoder consists of five convolutional layers with kernel sizes of [10, 8, 7, 5, 3] and strides of [2, 2, 1, 1, 1], and ReLU is used as the activation function. Then GRU network compresses spatial feature time series with size of w×50 into a 1×64 dynamic feature vector h, where w is the length of perceptual time window. 

During pretraining, a network with two linear layers maps h_t to ẑ_t+1 and ẑ_t+2. The network is trained by maximizing the cosine similarity between z_t+1 and ẑ_t+1, and z_t+2 and ẑ_t+2, as defined below,


    ℒ = - 𝔼_t [ 𝐳_𝐭+1·ẑ_𝐭+1/‖𝐳_𝐭+1‖‖ẑ_𝐭+1‖ + 
        𝐳_𝐭+2·ẑ_𝐭+2/‖𝐳_𝐭+2‖‖ẑ_𝐭+2‖]

This process is similar to contrastive predictive coding <cit.>, which enables the agent to learn valuable knowledge by trying to forecast future information.


After pretraining, we anticipate the knowledge about surrounding fluid environment is well represented by the feature vector h which can then be used in other tasks. For example, we can simply connect a network with linear layers to this feature vector to make predictions of flow quantities. Or we can use this feature vector as a state variable of given reinforcement learning model to optimize the performance of an intelligent agent. 







 §.§ Reinforcement learning

A reinforcement learning problem is typically modeled as a Markov Decision Process (MDP). In an MDP, an agent interacts with an environment by taking actions and receiving feedback in the form of rewards. At each time step t, the agent selects an action a_t ∼π_x (a|s_t) from a policy π. This policy is parameterized by x. Given an initial state s_0 ∈ S, the agent takes an action and receives a reward r_t+1. The objective is to learn a policy that maximizes the expected cumulative reward 𝔼[∑_t=0^∞γ^t r_t|s_0,π_x], where γ∈ [0,1) is a discount factor that prioritizes earlier rewards over later ones.



In this study, we employ the Proximal Policy Optimization (PPO) algorithm, developed by Schulman et al. <cit.>. PPO is an episodic learning method, which means learning process is divided into episodes. Each episode consists of a fixed number (set as 10 in current work) of actions. A key feature of PPO is to use Generalized Advantage Estimation (GAE) to reduce variance in the advantage estimates, which stabilizes training process. Additionally, PPO employs a clipping strategy to constrain policy updates, which ensures that the new policy does not deviate excessively from the old one, and thus a balance between exploration and exploitation is maintained. The PPO algorithm uses two neural networks: a policy network which decides the next action, and a value network that estimates the expected cumulative reward. Both networks include perceptual layers to process input data, followed by a fully connected layer to generate action or estimated advantage. In the training process, the learning rates for the policy network and for the value network are set as 0.0001 and 0.001, respectively.






§ RESULTS AND DISCUSSION



 §.§ Pretraining

In the unsupervised pretraining process, the upstream obstacle cylinder oscillates randomly along the y-direction in the range of -1D to 1D for 5000 seconds, while surface pressure of the downstream agent cylinder is sampled with a frequency of 10Hz. During pretraining, the perception network extracts dynamic features from past pressure data and uses them to predict spatial features z for the next two time steps, as illustrated in figure <ref>. 















 §.§ Obstacle Perception


Obstacle perception is a common task that could be encountered by embodied agents navigating in fluid environments. Disturbances originating from upstream obstacles propagate downstream, which can be perceived by downstream agents and used to estimate obstacle positions. In the current study, we design a supervised learning task to investigate obstacle perception ability of a pretrained agent. In this supervised learning task, the downstream agent is trained to reconstruct the disturbance trajectory of the upstream cylinder using surface pressure information of the agent cylinder. We build a training set by annotating the positions of the upstream cylinder over the 5000-second pretraining data set. Considering the time-delay of disturbance propagation, we use a 10-second window of pressure information to estimate the position of the obstacle cylinder 10 seconds ago.

For comparison, we carry out the same training process on agents both with and without pretraining. The network structures for both agents are identical, but the weights of the non-pretrained agent are randomly initialized. The non-pretrained model serves as the baseline model. After the obstacle perception training, we evaluate performance of both agents on four different test data sets.  In test set 1, the obstacle cylinder oscillates in the same random manner as in the training set, but the data sets are different. Test set 2 features intermittent motion with a 5-second pause at the end of each oscillation. Test set 3 involves sinusoidal motion restricted at one side of the flow region. In test set 4, the upstream obstacle cylinder is kept still at the centerline of the flow field.

In the training process, the errors for both training and test sets are calculated at each training step. The test error is calculated as the average of all 4 tests. Loss curves for both agents (pretrained and baseline) are plotted in figure <ref>. Figure <ref> shows that both agents perform similarly on the training set, while their performance on the test set differs significantly. The pretrained model achieves a minimum test set error of 0.0432, while the minimum error for the baseline model is 0.0696, which is 70% higher. Comparisons between perceived and real trajectories of the obstacle cylinder are shown in figure <ref>. Both agents perform well on test set 1 (figure <ref>), since the obstacle cylinder oscillates in the same random manner in this test as it does in the training process. However, on test sets 2, 3, and 4 (figures <ref>, <ref>, and <ref>), the pretrained agent performs much better in perceiving the trajectory of obstacle cylinder. This demonstrates that the agent exhibits enhanced generalization capabilities in new scenarios after the pretraining process.






 §.§ Reinforcement Learning for drag reduction

In the reinforcement learning task, the upstream obstacle cylinder is kept still. A Kármán vortex street is generated from the cylinder surface and sheds downstream with a Strouhal number of St=fD/U=0.167.  
Meanwhile, the agent cylinder is allowed to move in the y-direction in the range of -1D to 1D, and it keeps optimizing its motion trajectory in the vortical wake flow to minimize the drag exerted on it.

In the RL training process, the agent identifies instant dynamic feature of pressure time series data over past 10-second window and takes it as its state. This window length ensures sufficient information included in the state variable. The agent's action variable has two components: the next position of the cylinder a_pos and the average velocity of the motion a_vel. We enforce the agent cylinder to cross the centerline of the flow field during each action. The reward function is defined as the negative value of the average drag induced by the current action. In this study, a_pos ranges from -1 to 1, and a_vel ranges from 0.2 to 0.4. In our setting, actions are sampled from a normal distribution, with the variance decreasing independently as the episodes progress.

Figure <ref> presents the learning curves of the pretrained and baseline agents. The solid lines represent the mean values of five repeated RL training processes, while the shaded areas correspond to one standard deviation. As shown in figure <ref>, initially the average drag coefficient of the agent cylinder with random motion is about 0.57. After 100 episodes of training, the pretrained agent significantly reduces its drag coefficient to a value below 0.37. In contrast, the baseline agent is trapped in the complexity of the problem and fails to find a motion pattern to reduce the drag acting on it.  

Performance evolution of pretrained agent can be better illustrated by flow field snapshots taken in the RL training process. Figure <ref> shows flow field snapshots captured at 4 continuous time instants in the early stage of RL training process on the pretrained agent. The time interval between snapshots is 2 seconds. As shown in figure <ref>, in the early stage of training, the agent cylinder oscillates aimlessly in y-direction and it keeps colliding with the shedding vortices from upstream. The breakdown of shedding vortices induces additional drag force on the agent cylinder. However, through tens of episodes of trial-and-error, the agent is able to adjust its action strategy using pretrained knowledge. As depicted in flow field snapshots obtained from the later stage of training process (figure <ref>), the agent cylinder chooses to move through the gaps between vortices to avoid direct collision with shedding vortices, which significantly reduces the drag force exerted on the cylinder.




 §.§ Sensitivity Analysis

Previous sections have shown that the agent with pretraining outperforms the baseline agent in both obstacle perception and reinforcement learning tasks. To further analyze this performance difference, we compute the sensitivity of the dynamic feature h_t with respect to each surface pressure input and plot the distribution of sensitivity values over the agent cylinder surface in figure <ref>. This sensitivity distribution reveals which areas of the surface pressure information on the agent cylinder the perception network focuses on. Before pretraining, with initially randomized parameters, the perception network's understanding of the surrounding fluid environment is chaotic and lacks a focused region (figure <ref>). After pretraining, the perception network adjusts its concentration to the upstream side of the cylinder which indicates this area is important in the pretraining task—the prediction of future spatial features of surface pressure distribution  (figure <ref>). 

In the following specific tasks, the agent further adjusts parameters of the perception network to fit objectives of the tasks. For example, in the obstacle perception task (figure <ref>, <ref>), sensitivity concentration region is shifted from the upstream side of the cylinder to both lateral sides where the shedding vortices might hit the cylinder. In contrast, sensitivity distribution of the baseline agent only focuses on one side of the cylinder, which might result in worse performance in the obstacle perception task. Furthermore, in the reinforcement learning task (figure <ref>, <ref>), the pretrained agent distributes its attention to upstream, downstream and lateral sides of the cylinder. In this complex task, the agent needs to perceive not only the incoming flow but also the pressure variance induced by the lateral motion of the cylinder. On the other hand, the baseline agent mainly focuses on the downstream and slightly on the lateral sides of the cylinder. A lack of information on lateral and upstream sides of the cylinder might lead to the failure of the baseline agent in this drag reduction task.

The sensitivity analysis above shows that the pretraining process enables the agent to adjust the parameters of the perception network to fit new task scenarios better and faster, thus outperforming the agent with a randomly initialized network.








§ CONCLUSION

We develop a perception network that can be used for information compression in fluid environments. The network consists of a convolutional neural network for spatial compression and a GRU network for temporal compression. We propose a pretraining process which is to predict spatial feature variables of next two time instants. 

We have tested the perception network and the pretraining process in a two-cylinder problem. The results show that the pretrained agent cylinder can better perceive the position of the upstream obstacle cylinder. Moreover, in the subsequent reinforcement learning task, the baseline agent fails to develop an effective strategy for drag reduction. On the other hand, through trials and errors, the pretrained agent successfully finds a motion strategy to avoid shedding vortices in the Kármán vortex street, which results in significant drag reduction. The sensitivity analysis indicates that this performance could be due to the better attention distribution of the pretrained agent. 

This study demonstrates that the pretraining process with the perception network in fluid environments can significantly improve the agent's performance in subsequent tasks, offering a promising pathway toward a robust and effective solution for real-world, complex, multi-scenario fluid problems.




§ DATA AVAILABILITY STATEMENT

The data that support the findings of this study are avail-able from the corresponding author upon reasonablerequest.



§ DISCLOSURE STATEMENT

The authors report there are no competing interests to declare.




§ VALIDATION OF THE FLUID SOLVER

In numerical simulation, time step is chosen so that the maximum Courant number during computation does not exceed 0.5. A mesh convergence test is carried out to confirm the mesh size. In mesh convergence test, flow field around two fixed cylinders is computed and both both coarse (67,352 elements) and fine grids (89,400 elements) are used. The time histories of drag and lift coefficients of the downstream agent cylinder are recorded and plotted in figure <ref>. The results demonstrate spatial convergence on the fine grid, which is used in subsequent simulations.

We validate the fluid solver by computing flow field around single cylinder. The computed average drag and maximum lift coefficients at Re=100 are compared with previous literature, as shown in Table <ref>. The comparison of variance of Strouhal number versus Reynolds number is shown in Table <ref>. 

To further validate the accuracy of the overset mesh technique in simulating flow around moving cylinder, additional simulations are performed on an in-line oscillating cylinder in uniform flow at a Reynolds number of 100. The cylinder oscillates parallel to the free stream at a frequency twice of the vortex shedding frequency for a fixed cylinder, with an oscillation amplitude of 0.14 times the cylinder diameter D. Table <ref> shows that the present results are consistent with those reported in the earlier literature.





















