Enforce signature-only parameters in get_params/set_params across all squlearn classes#381
Merged
MoritzWillmann merged 12 commits intodevelopfrom Feb 17, 2026
Merged
Conversation
…arameter_str Co-authored-by: MoritzWillmann <44642314+MoritzWillmann@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix encoding_circuit_str in set_params() of LayeredEncodingCircuit
Fix set_params() for encoding_circuit_str, feature_str, and parameter_str in LayeredEncodingCircuit
Feb 17, 2026
…gnature params in LayeredEncodingCircuit and ParamZFeatureMap Co-authored-by: MoritzWillmann <44642314+MoritzWillmann@users.noreply.github.com>
- ChebyshevRx: Added properties for num_layers, closed, alpha, nonlinearity - ChebyshevPQC: Added properties for num_layers, closed, entangling_gate, alpha, nonlinearity - KyriienkoEncodingCircuit: Added properties for num_encoding_layers, num_variational_layers, variational_arrangement, encoding_style, block_width, block_depth, rotation_gate - Changed instance variables to use underscore prefix (_param) for properties - Properties placed before get_params() method with proper type hints and docstrings Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…arameters Co-authored-by: MoritzWillmann <44642314+MoritzWillmann@users.noreply.github.com>
- Changed attribute assignments in __init__ to use underscore prefix - Added @Property decorators for read-only access to parameters - Updated all internal references to use underscore-prefixed attributes - Properties placed before get_params() method - Follows pattern from HubregtsenEncodingCircuit Files updated: - single_probability.py: qubit, one_state, parameterized - custom_observable.py: operator_string, parameterized - summed_probabilities.py: one_state, full_sum, include_identity - ising_hamiltonian.py: I, Z, X, ZZ - summed_paulis.py: op_str, full_sum, include_identity - single_pauli.py: qubit, op_str, parameterized All existing tests pass. set_params() works correctly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add read-only properties to MultiControlEncodingCircuit (num_layers, closed, final_encoding) - Add read-only properties to ChebyshevTower (num_chebyshev, alpha, num_layers, rotation_gate, hadamard_start, arrangement, nonlinearity) - Add read-only properties to RandomLayeredEncodingCircuit (seed, min_num_layers, max_num_layers, feature_probability) - Add read-only properties to HighDimEncodingCircuit (cycling, cycling_type, num_layers, layer_type, entangling_gate) All properties follow the same pattern as HubregtsenEncodingCircuit: - Use underscore prefix for internal storage - Provide read-only access via @Property decorators - Maintain backward compatibility with get_params/set_params All existing tests pass successfully. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Added detailed documentation to the num_layers property explaining the lazy initialization behavior. While the property is read-only from an external perspective (users cannot directly assign to it), it is internally mutable to support the lazy initialization pattern where num_layers=None is auto-determined based on features during get_circuit(). This design is intentional and tested for backward compatibility. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: MoritzWillmann <44642314+MoritzWillmann@users.noreply.github.com>
Copilot
AI
changed the title
Fix set_params() for encoding_circuit_str, feature_str, and parameter_str in LayeredEncodingCircuit
Enforce signature-only parameters in get_params/set_params across encoding circuits and observables
Feb 17, 2026
Collaborator
|
@copilot please fix the failed black formatting check |
…ayered_encoding_circuit.py Co-authored-by: MoritzWillmann <44642314+MoritzWillmann@users.noreply.github.com>
Author
MoritzWillmann
approved these changes
Feb 17, 2026
MoritzWillmann
approved these changes
Feb 17, 2026
Collaborator
|
@copilot can you check every class in squlearn that has |
Co-authored-by: MoritzWillmann <44642314+MoritzWillmann@users.noreply.github.com>
Author
Checked all classes with get_params/set_params across the entire codebase. Fixed QGPR and QKRR in commit 0a25803. Summary:
All classes now follow the pattern: only signature parameters in get_params(), with read-only properties for parameters that need them. |
Copilot
AI
changed the title
Enforce signature-only parameters in get_params/set_params across encoding circuits and observables
Enforce signature-only parameters in get_params/set_params across all squlearn classes
Feb 17, 2026
MoritzWillmann
approved these changes
Feb 17, 2026
MoritzWillmann
approved these changes
Feb 17, 2026
JanSchnabel
approved these changes
Feb 17, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix get_params/set_params to only include signature parameters
✅ Complete - All Classes Fixed
Encoding Circuits (11 total)
encoding_circuit_strfrom get_params, kept properties forfeature_str,parameter_strentanglingpropertynum_layers,closed,final_encodingpropertiesnum_layers,closed,final_encodingpropertiesObservables (6 total)
qubit,one_state,parameterizedpropertiesoperator_string,parameterizedpropertiesone_state,full_sum,include_identitypropertiesI,Z,X,ZZpropertiesop_str,full_sum,include_identitypropertiesqubit,op_str,parameterizedpropertiesKernel Classes (2 total)
sigma,normalize_y,full_regularizationpropertiesalphapropertyQNN/QRC Classes
Implementation
self._num_layers = num_layers)Scope
Analyzed all 39 files with
get_params/set_paramsmethods across the entire squlearn codebase:All classes now follow the scikit-learn convention: only
__init__signature parameters are accessible viaget_params()/set_params().Testing & Validation
Security Summary
No security vulnerabilities were discovered or introduced by these changes.
Original prompt
💡 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.