Skip to content

Remove need for num_features before fitting - #301

Merged
MoritzWillmann merged 152 commits into
sQUlearn:developfrom
DennisKleinhans:remove_num_features
Aug 20, 2025
Merged

Remove need for num_features before fitting #301
MoritzWillmann merged 152 commits into
sQUlearn:developfrom
DennisKleinhans:remove_num_features

Conversation

@DennisKleinhans

@DennisKleinhans DennisKleinhans commented Oct 25, 2024

Copy link
Copy Markdown
Collaborator

Changes Made

1. Delayed Initialization of High-Level Methods

  • The num_features parameter is no longer required during the instantiation of high-level methods.
  • If num_features is not provided, the complete initialization of the high-level method is postponed until the fit method is called, allowing the actual number of features to be known.
  • If num_features is provided during instantiation, the high-level method will be fully initialized immediately.

2. New num_encoding_slots Property for EncodingCircuit

  • A new property called num_encoding_slots has been introduced for each EncodingCircuit, which calculates the number of encoding slots individually.
  • In the get_circuit method, there is now a check to ensure that the number of provided features matches the number of available encoding slots.
  • If there are not enough encoding slots for all features, an EncodingSlotsMismatchError is raised.

closes #266, #292

Dennis Kleinhans added 29 commits August 14, 2024 16:55
…d quantum kernel and the Support Vector HLM's
- Extract initialization logic for the FidelityKernel and ProjectedQuantumKernel into a new method "initialize_kernel", which is called within the fit methods of the high-level classes.
- Separate the initialization logic for QSVR and QSVC into their own "initialize_kernel" methods, which also invoke the underlying "initialize_kernel" methods of the Fidelity or Projected Kernel.
make sure the kernel is fully initialised in the evaluate method before evaluating it. This is necessary to deal with kernel cloning in some cases.
Comment thread src/squlearn/encoding_circuit/encoding_circuit_base.py Outdated
Comment thread docs/user_guide/encoding_circuits.rst
Comment thread examples/encoding_circuits/pruning_example.ipynb
Comment thread examples/integration/mlflow.ipynb
Comment thread examples/qnn/classification_example.ipynb
Comment thread src/squlearn/kernel/qgpc.py Outdated
Comment thread src/squlearn/kernel/qsvr.py Outdated
Comment thread tests/kernel/ml/test_qkrr.py Outdated
Comment thread tests/kernel/ml/test_qkrr.py Outdated
Comment thread tests/util/execution/test_automatic_backend_selection.py

@MoritzWillmann MoritzWillmann left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now, LGTM

@MoritzWillmann
MoritzWillmann merged commit 1b0adcd into sQUlearn:develop Aug 20, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle feature encoding when #features != n*encoding slots Remove need for num_features before fitting

3 participants