-
Notifications
You must be signed in to change notification settings - Fork 0
[BUGFIX] Stabilize the default test suite and bugfixes #46
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aecebab
Add utils for tests setup (pytest)
PeterCalifano dfe2f84
Cleanup old tests
PeterCalifano 19955be
Improve markers and gates for exec
PeterCalifano c6d2135
Add misc tests for utils and tcp api (legacy)
PeterCalifano fb81cd3
Minor bugfix and tests
PeterCalifano 5a5ccac
Add pytest marker
PeterCalifano b307d84
Add demo of optuna with mlflow logging
PeterCalifano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Shared pytest support package for local tests.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,50 +1,64 @@ | ||
| import numpy as np | ||
| from __future__ import annotations | ||
|
|
||
| # Custom imports | ||
| from pyTorchAutoForge.api.tcp import DataProcessor, pytcp_server, pytcp_requestHandler, ProcessingMode | ||
| import threading | ||
|
|
||
| # MAIN SCRIPT | ||
| def main(): | ||
| print('\n\n----------------------------------- RUNNING: test_start_server.py -----------------------------------\n') | ||
|
|
||
| # %% TCP SERVER INITIALIZATION | ||
| HOST1, PORT1 = "127.0.0.1", 50000 # Define host and port for the first server | ||
| HOST2, PORT2 = "127.0.0.1", 50001 # Define host and port for the second server | ||
|
|
||
| def dummy_function(inputData): | ||
| return inputData | ||
|
|
||
| # Define DataProcessor object for RequestHandler | ||
| dataProcessorObj = DataProcessor(dummy_function, np.float32, 1024, | ||
| ENDIANNESS='little', DYNAMIC_BUFFER_MODE=True, | ||
| PRE_PROCESSING_MODE=ProcessingMode.TENSOR) | ||
|
|
||
| dataProcessorObj_multi = DataProcessor(dummy_function, np.float32, 1024, | ||
| ENDIANNESS='little', DYNAMIC_BUFFER_MODE=True, | ||
| PRE_PROCESSING_MODE=ProcessingMode.MULTI_TENSOR) | ||
|
|
||
| def start_server(host, port, dataProcessorObj): | ||
| with pytcp_server((host, port), pytcp_requestHandler, dataProcessorObj, bindAndActivate=True) as server: | ||
| try: | ||
| print(f'\nServer initialized correctly on {host}:{port}. Set in "serve_forever" mode.') | ||
| server.serve_forever() | ||
| except KeyboardInterrupt: | ||
| print(f"\nServer on {host}:{port} is gracefully shutting down =D.") | ||
| server.shutdown() | ||
| server.server_close() | ||
|
|
||
| # Start two servers on separate threads | ||
| thread1 = threading.Thread(target=start_server, args=( HOST1, PORT1, dataProcessorObj) ) | ||
| thread2 = threading.Thread(target=start_server, args=( HOST2, PORT2, dataProcessorObj_multi) ) | ||
|
|
||
| thread1.start() | ||
| thread2.start() | ||
|
|
||
| # Wait for the threads to finish processing | ||
| thread1.join() | ||
| thread2.join() | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| import numpy as np | ||
|
|
||
| from pyTorchAutoForge.api.tcp import ( | ||
| DataProcessor, | ||
| ProcessingMode, | ||
| pytcp_requestHandler, | ||
| pytcp_server, | ||
| ) | ||
|
|
||
|
|
||
| def _Identity(input_data_: np.ndarray) -> np.ndarray: | ||
| return input_data_ | ||
|
|
||
|
|
||
| def test_data_processor_tensor_roundtrip() -> None: | ||
| processor_ = DataProcessor( | ||
| _Identity, | ||
| np.float32, | ||
| 1024, | ||
| ENDIANNESS="little", | ||
| DYNAMIC_BUFFER_MODE=True, | ||
| PRE_PROCESSING_MODE=ProcessingMode.TENSOR, | ||
| ) | ||
| input_array_ = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32) | ||
|
|
||
| output_buffer_ = processor_.process( | ||
| processor_.TensorToBytesBuffer(input_array_)) | ||
| output_array_, output_shape_ = processor_.BytesBufferToTensor(output_buffer_[ | ||
| 4:]) | ||
|
|
||
| assert output_shape_ == input_array_.shape | ||
| assert np.array_equal(output_array_, input_array_) | ||
|
|
||
|
|
||
| def test_tcp_server_starts_and_shuts_down_without_hanging() -> None: | ||
| processor_ = DataProcessor( | ||
| _Identity, | ||
| np.float32, | ||
| 1024, | ||
| ENDIANNESS="little", | ||
| DYNAMIC_BUFFER_MODE=True, | ||
| PRE_PROCESSING_MODE=ProcessingMode.TENSOR, | ||
| ) | ||
|
|
||
| with pytcp_server( | ||
| ("127.0.0.1", 0), | ||
| pytcp_requestHandler, | ||
| processor_, | ||
| bindAndActivate=True, | ||
| ) as server_: | ||
| thread_ = threading.Thread(target=server_.serve_forever, daemon=True) | ||
| thread_.start() | ||
|
|
||
| assert server_.server_address[0] == "127.0.0.1" | ||
| assert server_.server_address[1] > 0 | ||
|
|
||
| server_.shutdown() | ||
| thread_.join(timeout=2.0) | ||
|
|
||
| assert not thread_.is_alive() |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.