Skip to content

Commit 7de5a50

Browse files
Upgrade to v2.0.0
2 parents 1921703 + ac9d675 commit 7de5a50

File tree

113 files changed

+821
-26528
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+821
-26528
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# 2.0.0 (2025 - 05 - 13)
2+
3+
### Features
4+
5+
* **Use tno.quantum.optimization.qubo:** Allow easier usage of different qubo solvers.
6+
7+
8+
### BREAKING CHANGES
9+
10+
* **PortfolioOptimizer input:** Input PortFolioOptimizer now takes a solver instead of a sampler.deserialization.
11+
12+
13+
# 1.0.0 (2024 - 05 - 01)
14+
15+
* **Initial release**: Initial release of PortfolioOptimization.

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ contact:
1818
repository-code: https://github.com/TNO-Quantum/problems.portfolio_optimization
1919
repository-artifact: https://pypi.org/project/tno.quantum.problems.portfolio_optimization
2020
title: TNO Quantum - Problems - Portfolio Optimization
21-
version: v1.0.0
21+
version: v2.0.0
2222
date-released: 2024-05-01

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2024 The Netherlands Organisation for Applied Scientific Research (TNO)
189+
Copyright 2025 The Netherlands Organisation for Applied Scientific Research (TNO)
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 7 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The following objectives can be considered
1515

1616
Additionally, we allow for a capital growth factor and arbitrary emission reduction constraints to be considered.
1717

18-
The `Pareto front`, the set of solutions where one objective can't be improved without worsening the other objective,
18+
The Pareto front, the set of solutions where one objective can't be improved without worsening the other objective,
1919
can be computed for the objectives return on capital and diversification.
2020

2121
The codebase is based on the following paper:
@@ -25,11 +25,10 @@ The codebase is based on the following paper:
2525
**Funding:** This research was funded by Rabobank and Stichting TKI High Tech Systems
2626
and Materials, under a program by Brightland's Techruption.
2727

28-
*Limitations in (end-)use: the content of this software package may solely be used for applications that comply with international export control laws.*
2928

3029
## Documentation
3130

32-
Documentation of the `tno.quantum.problems.portfolio_optimization` package can be found [here](https://tno-quantum.github.io/problems.portfolio_optimization/).
31+
Documentation of the `tno.quantum.problems.portfolio_optimization` package can be found [here](https://tno-quantum.github.io/documentation/).
3332

3433
## Install
3534

@@ -39,97 +38,12 @@ Easily install the `tno.quantum.problems.portfolio_optimization` package using p
3938
$ python -m pip install tno.quantum.problems.portfolio_optimization
4039
```
4140

42-
If you wish to use D-Wave quantum hardware:
43-
```console
44-
$ python -m pip install 'tno.quantum.problems.portfolio_optimization[quantum]'
45-
```
46-
4741
If you wish to run the tests you can use:
4842
```console
49-
$ python -m pip install 'tno.quantum.problems.portfolio_optimization[tests]'
43+
$ python -m pip install tno.quantum.problems.portfolio_optimization[tests]
5044
```
5145

52-
## Usage
53-
54-
<details>
55-
<summary>Solve portfolio optimization problem.</summary>
56-
57-
Here's an example of how the `PortfolioOptimizer` class can be used to define an portfolio optimization problem,
58-
and subsequently, how the Pareto front can be computed using the simulated annealing sampler from D-Wave.
59-
60-
```python
61-
import numpy as np
62-
from dwave.samplers import SimulatedAnnealingSampler
63-
64-
from tno.quantum.problems.portfolio_optimization import PortfolioOptimizer
65-
66-
# Choose sampler for solving qubo
67-
sampler = SimulatedAnnealingSampler()
68-
sampler_kwargs = {"num_reads": 20, "num_sweeps": 200}
69-
70-
# Set up penalty coefficients for the constraints
71-
lambdas1 = np.logspace(-16, 1, 25, endpoint=False, base=10.0)
72-
lambdas2 = np.logspace(-16, 1, 25, endpoint=False, base=10.0)
73-
lambdas3 = np.array([1])
74-
75-
# Create portfolio optimization problem
76-
portfolio_optimizer = PortfolioOptimizer("benchmark_dataset")
77-
portfolio_optimizer.add_minimize_hhi(weights=lambdas1)
78-
portfolio_optimizer.add_maximize_roc(formulation=1, weights_roc=lambdas2)
79-
portfolio_optimizer.add_emission_constraint(
80-
weights=lambdas3,
81-
emission_now="emis_intens_now",
82-
emission_future="emis_intens_future",
83-
name="emission"
84-
)
85-
86-
# Solve the portfolio optimization problem
87-
results = portfolio_optimizer.run(sampler, sampler_kwargs)
88-
```
89-
</details>
90-
91-
<details>
92-
<summary>Visualize results.</summary>
93-
94-
The results can be inspected in more detail by looking at the Pandas results DataFrame
95-
`results.results_df`.
96-
97-
Alternatively, the results can be plotted in a `(Diversification, ROC)`-graph. The
98-
following example first slices the results in data points that do and do not satisfy the
99-
constraints using the method `slice_results`.
100-
101-
Note that:
102-
103-
- Individual data points can subsequently be plotted using the `plot_points` function.
104-
- The Pareto front can be plotted using the `plot_front` function.
105-
106-
```python
107-
import matplotlib.pyplot as plt
108-
109-
from tno.quantum.problems.portfolio_optimization import plot_front, plot_points
110-
111-
(x1, y1), (x2, y2) = results.slice_results()
112-
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(12, 5))
113-
114-
# Plot data points
115-
plot_points(x2, y2, color="orange", label="QUBO constraint not met", ax=ax1)
116-
plot_points(x1, y1, color="green", label="QUBO constraint met", ax=ax1)
117-
ax1.set_title("Points")
118-
119-
# Plot Pareto front
120-
plot_front(x2, y2, color="orange", label="QUBO constraint not met", ax=ax2)
121-
plot_front(x1, y1, color="green", label="QUBO constraint met", ax=ax2)
122-
ax2.set_title("Pareto Front")
123-
fig.tight_layout()
124-
plt.show()
125-
```
126-
127-
</details>
128-
129-
![(Diversification, ROC)-Graph](./images_for_docs/example.png)
130-
131-
132-
More elaborate examples can be found in our [examples repository](https://github.com/TNO-Quantum/examples ).
46+
Usage examples can be found in the [documentation](https://tno-quantum.github.io/documentation/).
13347

13448
Data input
13549
----------
@@ -148,28 +62,9 @@ The data needs to contain at least the following columns:
14862

14963
If the input datafile contains all the correct information, but has different column
15064
names, it is possible to rename the columns without altering the input file.
151-
Details and examples can be found in the [documentation]((https://tno-quantum.github.io/problems.portfolio_optimization/)).
152-
153-
The data that was used for the publication can be found in the `tno/quantum/problems/portfolio_optimization/datasets/` folder.
154-
15565

156-
Using Quantum Annealing Solvers
157-
-------------------------------
66+
The data that was used for the publication can be found in the `src/tno/quantum/problems/portfolio_optimization/datasets/` folder.
15867

159-
By default, the portfolio optimization QUBO is solved using simulated annealing.
160-
Any D-Wave ``Sampler`` is however supported and can be provided to the `PortfolioOptimizer.run` method.
161-
162-
163-
Below is an example how to initialise a quantum annealing sampler that uses `100` micro seconds annealing time per sample.
164-
The example assumes a proper [configuration setup](https://docs.ocean.dwavesys.com/en/stable/overview/sapi.html) to the D-Wave's Solver API.
165-
166-
```python
167-
from dwave.system import DWaveSampler, LazyFixedEmbeddingComposite
168-
169-
# Define QPU D-Wave Sampler
170-
qpu = DWaveSampler()
171-
sampler = LazyFixedEmbeddingComposite(qpu)
172-
sampler_kwargs = {"annealing_time": 100}
173-
```
17468

175-
We refer to the [D-Wave Sampler documentation](https://docs.ocean.dwavesys.com/projects/system/en/stable/reference/samplers.html) for information on usage of different samplers and their sampler arguments.
69+
## (End)use limitations
70+
The content of this software may solely be used for applications that comply with international export control laws.

docs/.buildinfo

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/.doctrees/environment.pickle

-182 KB
Binary file not shown.

docs/.doctrees/index.doctree

-41.8 KB
Binary file not shown.
-374 KB
Binary file not shown.
-71.5 KB
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)