Consolidate NKT SuperK services into single unified base class architecture#384
Consolidate NKT SuperK services into single unified base class architecture#384
Conversation
|
@ivalaginja 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs. I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review. |
|
@copilot here are some instructions to write this pull request:
|
|
@copilot the documentation needs to be updated too. Inside of |
Thanks for the clarification! I've moved the base class to the correct location in The changes made:
This follows the repository's architectural pattern where base services are kept in the dedicated |
Documentation has been consolidated into a single |
|
@copilot the finaium and evo services also have a simulated services each, located in |
The simulated services have been successfully refactored to inherit from a common base class. Changes made:
Benefits:
All simulation services now follow the same inheritance pattern as their hardware counterparts while preserving device-specific behavior. Commit: b2d78ca |
|
@copilot the base class for the hardware services, |
Successfully consolidated the hardware and simulation base classes into a single unified Key changes:
All services work correctly with minimal import changes only. Commit: 4bbccd0 |
|
We don't do simulation checks with if statements in service classes, but this PR is good enough for me to take over and fix that. Only glanced over it for now, so if anyone seems something that's blatantly wrong, do let me know. |
|
@ehpor would you mind giving me some feedback on this? Sorry for the convoluted ways at times, I was testing what I could reasonably do with Copilot. Untested on hardware and sim, but it contains quite some changes overall so I wanted your input early. Especially on having both hw and sim functionality in the general base class for the NKT SuperK, and then still bifurcating between hw and sim services when it comes down to the concrete EVO and FIANIUM services. |
ivalaginja
left a comment
There was a problem hiding this comment.
Some comments to myself about the new test file
| self.mock_service = Mock() | ||
| self.mock_service.config = { | ||
| 'port': 'COM1', | ||
| 'emission': 1, |
There was a problem hiding this comment.
Would this work for the Fianium that uses 0 and 3?
| from catkit2.services.nkt_superk_evo_sim.nkt_superk_evo_sim import NktSuperkEvoSim | ||
|
|
||
| # Test EVO-specific methods for both hardware and simulation | ||
| evo_methods = ['update_evo_status', 'set_power_setpoint', 'set_current_setpoint'] |
There was a problem hiding this comment.
I moved set_power_setpoint to the intermediate Evo class, should this be moved in the test too?
| from catkit2.services.nkt_superk_fianium_sim.nkt_superk_fianium_sim import NktSuperkFianiumSim | ||
|
|
||
| # Test FIANIUM-specific methods for both hardware and simulation | ||
| fianium_methods = ['set_power_setpoint', 'set_pulse_picker_ratio', 'monitor_pulse_picker_ratio'] |
There was a problem hiding this comment.
Idem for the set_power_setpoint in the Fianium.
|
@ivalaginja I'll take a look after tomorrow. |
Co-authored-by: ivalaginja <29508965+ivalaginja@users.noreply.github.com>
Co-authored-by: ivalaginja <29508965+ivalaginja@users.noreply.github.com>
Co-authored-by: ivalaginja <29508965+ivalaginja@users.noreply.github.com>
…lass - Created NktSuperkSimBase abstract base class in catkit2/base_services/ - Contains all shared simulation functionality (VARIA controls, thread management, data streams) - Provides abstract methods for device-specific implementations - Refactored NktSuperkEvoSim to inherit from base class (81 lines removed) - Refactored NktSuperkFianiumSim to inherit from base class (81 lines removed) - Added comprehensive unit tests for simulation base class - Eliminates 162 lines of duplicated code between simulation services - Maintains all original functionality and interfaces Co-authored-by: ivalaginja <29508965+ivalaginja@users.noreply.github.com>
Co-authored-by: ivalaginja <29508965+ivalaginja@users.noreply.github.com>
6625f03 to
c3affd6
Compare
|
@ehpor any thoughts? |
PR Description
catkit2/base_services/nkt_superk.pyfor all NKT SuperK services, no matter concrete model, or hw/sim. This base class has a boolean that differentiates between hw/sim since some functionality is shared between the Evo and Fianium.catkit2/base_services/nkt_superk_evo.pyandcatkit2/base_services/nkt_superk_fianium.pyAI description
Warning
The below PR description was AI-generated and does not capture all the work in this PR correctly after user-committed work.
This PR consolidates the duplicated code across NKT SuperK services by creating a single unified base class that handles both hardware and simulation services.
Problem
The NKT SuperK services had significant code duplication across multiple base classes:
Previous Architecture:
NktSuperkBase- Hardware services base class (253 lines)NktSuperkSimBase- Simulation services base class (169 lines)This resulted in maintenance overhead where common bugs needed fixing in multiple places and inconsistent patterns between hardware and simulation services.
Solution
Unified Base Class Architecture:
Created a single
NktSuperkbase class incatkit2/base_services/nkt_superk.pythat:'sim'in service name)Service Refactoring Results:
NktSuperkEvo: Minimal changes (import update only)NktSuperkFianium: Minimal changes (import update only)NktSuperkEvoSim: Minimal changes (import update only)NktSuperkFianiumSim: Minimal changes (import update only)Code Consolidation Results:
Key Benefits
The unified architecture maintains the clean separation between hardware-specific operations (register communication) and simulation operations (testbed interaction) while sharing all common service lifecycle, data stream management, and threading patterns.
Fixes #378.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.