本文整理汇总了Python中LinearAlgebra.orthonormal_tangent_basis方法的典型用法代码示例。如果您正苦于以下问题:Python LinearAlgebra.orthonormal_tangent_basis方法的具体用法?Python LinearAlgebra.orthonormal_tangent_basis怎么用?Python LinearAlgebra.orthonormal_tangent_basis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinearAlgebra
的用法示例。
在下文中一共展示了LinearAlgebra.orthonormal_tangent_basis方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_client
# 需要导入模块: import LinearAlgebra [as 别名]
# 或者: from LinearAlgebra import orthonormal_tangent_basis [as 别名]
def start_client(self):
"""Start the instance of SimulationClient and begin computing local geodesics.
"""
# Define a flag to indicate if contact with the SimulationServer instance is possible.
connection_made = False
# Create a response to send to the SimulationServer indicating that this is the first time this SimulationClient
# has attempted to get a task.
client_response = {'status_code': comm_code('CLIENT_FIRST_CONTACT'),
'client_name': self.ID}
# Attempt to connect to the SimulationServer instance.
try:
# Create a Client object that communicates with the listener on CURVE_ADDRESS using password AUTHKEY.
server = Client(self.CURVE_ADDRESS, authkey=self.AUTHKEY)
# When a connection is made send the client message.
server.send(client_response)
# The client assumes the server will respond with a message, either a local geodesic to compute or a message
# asking the client to try again after DELAY seconds.
server_response = server.recv()
# Interpret the servers response by first extracting the status_code variable from the response.
server_response_code = server_response['status_code']
# Close the connection to the server at this point to allow other clients to communicate with the
# SimulationServer.
server.close()
# Store in the connection_made flag that it was possible to create a connection.
connection_made = True
# If it isn't possible to connect to the server than a socket.error exception is raised.
except socket.error:
# Write an error to the log for this client indicating that the connection couldn't be made.
logging.warning('Failed to Make Connection to SimulationServer. Shutting down client.')
# Send a signal to the running instances of SimulationPotential that the SimulationClient would have used
# indicating that they should also shutdown.
shutdown_metric(self.METRIC_SERVERS, self.AUTHKEY)
# This is the main loop of the SimulationClient - the program stops running when it is no longer possible to
# communicate with the SimulationServer. This is decided by the connection_made flag.
while connection_made:
# At this point in the code a new server_response should have been received. How the SimulationClient reacts
# depends on the communication code received.
# If the server has indicated it is giving the SimulationClient a new geodesic to compute then...
if server_response_code == comm_code('SERVER_GIVES_NEW_TASK'):
# Compute the rescaled tangent direction of the curve as store as a NumPy array.
tangent_direction = (1 / float(self.CONFIGURATION['local_number_of_nodes'] + 1)) * \
np.subtract(server_response['right_end_point'], server_response['left_end_point'], dtype='float64')
# Compute the local geodesic using the BFGS method and store the NumPy array in result
result = \
find_geodesic_midpoint(server_response['left_end_point'],
server_response['right_end_point'],
self.CONFIGURATION['local_number_of_nodes'],
la.orthonormal_tangent_basis(tangent_direction,
self.CONFIGURATION['dimension']),
tangent_direction, self.CONFIGURATION['codimension'],
self.METRIC_SERVERS,
self.MASS_MATRIX,
self.AUTHKEY)
# If the function find_geodesic_midpoint returned a None object then it couldn't contact it's
# SimulationPotential instances and should be restarted.
if result is None:
# Tell the user via the log that the SimulationPotential instances couldn't be contacted.
logging.warning('Failed to Make Connection to SimulationPotential. Shutting down client.')
# Exit the main loop of the SimulationClient.
break
# If there is a midpoint then construct a client response to tell the server which node has which new
# position.
client_response = {'status_code': comm_code('CLIENT_HAS_MIDPOINT_DATA'),
'node_number': server_response['node_number'],
'new_node_position': result,
'client_name': self.ID
}
# Otherwise if the server has asked the SimulationClient to try again later...
elif server_response_code == comm_code('SERVER_REQUEST_CALLBACK'):
# Make the SimulationClient wait for DELAY seconds
time.sleep(self.DELAY)
# Create a response to tell the SimulationServer that the SimulationClient would like a new job.
client_response = {'status_code': comm_code('CLIENT_HAS_NO_TASK'), 'client_name': self.ID}
# Attempt to connect to the SimulationServer instance.
try:
# Create a Client object that communicates with the listener on CURVE_ADDRESS using password AUTHKEY.
server = Client(self.CURVE_ADDRESS, authkey=self.AUTHKEY)
#.........这里部分代码省略.........