Skip to content

Commit 89945e7

Browse files
nquetschlichCopilotpre-commit-ci[bot]burgholzer
authored
🎨 Improve RL Action Handling (#401)
<!--- This file has been generated from an external template. Please do not modify it directly. --> <!--- Changes should be contributed to https://github.com/munich-quantum-toolkit/templates. --> ## Description This PR introduces a class structure to the RL compilation actions and resolves #144. ## Checklist: <!--- This checklist serves as a reminder of a couple of things that ensure your pull request will be merged swiftly. --> - [x] The pull request only contains commits that are focused and relevant to this change. - [x] I have added appropriate tests that cover the new/changed functionality. - [x] I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals. - [x] The changes follow the project's style guidelines and introduce no new warnings. - [x] The changes are fully tested and pass the CI checks. - [x] I have reviewed my own code changes. --------- Signed-off-by: Nils Quetschlich <nils.quetschlich@tum.de> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Lukas Burgholzer <burgholzer@me.com>
1 parent 7eded67 commit 89945e7

10 files changed

Lines changed: 938 additions & 662 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ This project adheres to [Semantic Versioning], with the exception that minor rel
99

1010
## [Unreleased]
1111

12+
### Changed
13+
14+
- ✨ Improve RL action handling by using dataclasses ([#401]) ([**@nquetschlich**])
15+
1216
## [2.2.0] - 2025-02-02
1317

1418
_📚 Refer to the [GitHub Release Notes](https://github.com/munich-quantum-toolkit/predictor/releases) for previous changelogs._
@@ -22,6 +26,9 @@ _📚 Refer to the [GitHub Release Notes](https://github.com/munich-quantum-tool
2226

2327
<!-- Contributor -->
2428

29+
[**@burgholzer**]: https://github.com/burgholzer
30+
[**@nquetschlich**]: https://github.com/nquetschlich
31+
2532
<!-- General links -->
2633

2734
[Keep a Changelog]: https://keepachangelog.com/en/1.1.0/

docs/Usage.rst

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,10 @@ MQT Predictor Framework Setup
4343
To run ``qcompile``, the MQT Predictor framework must be set up. How this is properly done is described next.
4444

4545
First, the to-be-considered quantum devices must be included in the framework.
46-
Currently, all devices supported by `MQT Bench <https://github.com/cda-tum/mqt-bench>`_ are natively supported.
47-
In case another device shall be considered, it can be added by using a similar format as in MQT Bench but it is not
48-
necessary to add it in the repository since it can be directly added to the MQT Predictor framework as follows:
46+
All devices supported by `MQT Bench <https://github.com/cda-tum/mqt-bench>`_ are natively supported.
47+
Furthermore, a custom device can be added to the framework as long as it is provided as a Qiskit Target object.
4948

50-
- Modify in `mqt/predictor/rl/predictorenv.py <https://github.com/munich-quantum-toolkit/predictor/tree/main/src/mqt/predictor/rl/predictorenv.py>`_. the line where ``mqt.bench.devices.get_device_by_name`` is used.
51-
- Modify in `mqt/predictor/ml/predictor.py <https://github.com/munich-quantum-toolkit/predictor/tree/main/src/mqt/predictor/ml/predictor.py>`_. the lines where ``mqt.bench.devices.*`` are used.
52-
- Follow the same data format as defined in `mqt.bench.devices.device.py <https://github.com/cda-tum/mqt-bench/tree/main/src/mqt/bench/devices/device.py>`_
53-
54-
Second, for each supported device, a respective reinforcement learning model must be trained. This is done by running
49+
Second, for each device, a respective reinforcement learning model must be trained. This is done by running
5550
the following command based on the training data in the form of quantum circuits provided as qasm files in
5651
`mqt/predictor/rl/training_data/training_circuits <https://github.com/munich-quantum-toolkit/predictor/tree/main/src/mqt/predictor/rl/training_data/training_circuits>`_:
5752

@@ -72,6 +67,29 @@ the following command based on the training data in the form of quantum circuits
7267
This will train a reinforcement learning model for the ``ibm_falcon_27`` device with the expected fidelity as figure of merit.
7368
Additionally to the expected fidelity, also critical depth is provided as another figure of merit.
7469
Further figures of merit can be added in `mqt.predictor.reward.py <https://github.com/munich-quantum-toolkit/predictor/tree/main/src/mqt/predictor/reward.py>`_.
70+
Please note that there is a pre-configured set of available compilation passes that are supported.
71+
This is defined in `mqt.predictor.rl.actions <https://github.com/munich-quantum-toolkit/predictor/tree/main/src/mqt/predictor/rl/actions.py>`_ and can be easily extended.
72+
If another compilation pass from Qiskit, TKET, or BQSKit shall be added, this can be done using:
73+
74+
.. code-block:: python
75+
76+
from mqt.predictor.rl.actions import (
77+
CompilationOrigin,
78+
DeviceIndependentAction,
79+
PassType,
80+
register_action,
81+
)
82+
83+
my_custom_pass = ... # Define your custom pass here, e.g., a Qiskit pass
84+
action = DeviceIndependentAction(
85+
name="test_action",
86+
pass_type=PassType.OPT,
87+
transpile_pass=[my_custom_pass],
88+
origin=CompilationOrigin.QISKIT,
89+
)
90+
register_action(action)
91+
92+
For other sources, defining a new ``CompilationOrigin`` is necessary as well as providing parsing methods to and from Qiskit's QuantumCircuit, since this is used as our internal representation of quantum circuits.
7593

7694
Third, after the reinforcement learning models that are used for the respective compilations are trained, the
7795
supervised machine learning model to predict the device selection must be trained.

0 commit comments

Comments
 (0)