-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Price Optimization Notebook #88
base: main
Are you sure you want to change the base?
Add Price Optimization Notebook #88
Conversation
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the reference to the blog post in the example notebook please.
examples/quantum_annealing/price_optimization/qubo_dynamic_pricing.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cell 26 takes a long time to run and submits a substantial amount of tasks against DWave. I recommend that you comment out as default similar to cell 9 here:https://github.com/aws/amazon-braket-examples/blob/main/examples/braket_features/Using_the_tensor_network_simulator_TN1.ipynb
import matplotlib.pyplot as plt We are already importing this, can we remove these imports from every cell again? |
Hi @FengShi0705, Thanks for submitting the notebook. I just have some questions/comments hoping you can address.
|
examples/quantum_annealing/price_optimization/qubo_dynamic_pricing.py
Outdated
Show resolved
Hide resolved
View / edit / reply to this conversation on ReviewNB licedric commented on 2021-12-04T01:00:36Z Optimization or optimisation? Settle on a spelling. I suggest "optimization" since that's what we use in our other notebooks.
"We showcase how to formulate this problem as a quadratic unconstrained binary optimization problem (QUBO) and use D-Wave Systems Inc. Advantage quantum annealer on Amazon Braket to find close-to-optimal solutions."
-> "We show how to formulate this problem as a quadratic unconstrained binary optimization problem (QUBO) and use the D-Wave Advantage quantum annealer on Amazon Braket to find close-to-optimal solutions." FengShi0705 commented on 2021-12-21T21:05:36Z Done |
View / edit / reply to this conversation on ReviewNB licedric commented on 2021-12-04T01:00:37Z "Table of content" -> "Table of contents" FengShi0705 commented on 2021-12-21T21:05:47Z Done |
View / edit / reply to this conversation on ReviewNB licedric commented on 2021-12-04T01:00:38Z Incomplete sentence FengShi0705 commented on 2021-12-21T21:06:12Z Done, complete it now |
View / edit / reply to this conversation on ReviewNB licedric commented on 2021-12-04T01:00:38Z Maximizing the revenue subject to what? What can we change? I suggest rewriting the problem as something like max_{p} R, R = sum d_t(p_t) p_t
so it's clear that we're optimizing with respect to p.
soly -> solely. Also add period at the end of the sentence. FengShi0705 commented on 2021-12-21T21:06:57Z Done |
View / edit / reply to this conversation on ReviewNB licedric commented on 2021-12-04T01:00:39Z "b is the constant" -> "b is a constant"
FengShi0705 commented on 2021-12-21T21:07:13Z Done |
View / edit / reply to this conversation on ReviewNB licedric commented on 2021-12-04T01:00:40Z Still too much output. Just show a subset. Ditto for the rest of the notebook FengShi0705 commented on 2021-12-21T21:07:38Z Done |
View / edit / reply to this conversation on ReviewNB licedric commented on 2021-12-04T01:00:40Z Line #4. price_levels=[5, 8, 10, 12, 13, 16, 19] # the option of price at each day Can you clarify this comment? Something like "possible prices for each day"
FengShi0705 commented on 2021-12-21T21:08:01Z Done |
View / edit / reply to this conversation on ReviewNB licedric commented on 2021-12-04T01:00:41Z Line #45. print("dataset x:") This is huge. Just print out a few entries of x and y. FengShi0705 commented on 2021-12-21T21:08:29Z yes, done, reduced the size of output printing |
View / edit / reply to this conversation on ReviewNB licedric commented on 2021-12-04T01:00:42Z "By using the created training dataset, we simply using sklearn to fit a linear demand model." -> "We use
"round the model coefficients to integer" -> "round the model coefficients to integers" But where does this rounding take place? FengShi0705 commented on 2021-12-21T21:10:30Z Done. Good point, the rounding is a legacy procedure for previous version. There is no need for rounding to take place, so the wording around "rounding" is now removed . |
View / edit / reply to this conversation on ReviewNB licedric commented on 2021-12-04T01:00:42Z "Where" -> "where"
FengShi0705 commented on 2021-12-21T21:10:44Z Done |
View / edit / reply to this conversation on ReviewNB licedric commented on 2021-12-04T01:00:43Z Maximize shouldn't be in math font.
"most recent n day's" -> "most recent n days'"
"random choose" -> "randomly choose" FengShi0705 commented on 2021-12-21T21:11:15Z Done |
View / edit / reply to this conversation on ReviewNB licedric commented on 2021-12-04T01:00:44Z Where do we assume that the price each day is only drawn from a set of fixed m options? This should be called out earlier explicitly. Also add a reference if this model is taken from the literature.
"the objective function which is the total revenue R in the next n days" -> "the objective function, i.e. the total revenue R, for the next n days"
"subject to" should not be in math font FengShi0705 commented on 2021-12-21T21:13:38Z Done.
Good point, A sentence is now added to explain the discrete price choices. |
View / edit / reply to this conversation on ReviewNB licedric commented on 2021-12-04T01:00:44Z Explain why you're using a 1d list to represent the 2d matrix x.
FengShi0705 commented on 2021-12-21T21:14:18Z Done.
Now added a comment in the code: |
View / edit / reply to this conversation on ReviewNB licedric commented on 2021-12-04T01:00:45Z "price to represent revenue" -> "the price to represent the revenue" FengShi0705 commented on 2021-12-21T21:15:04Z Done |
View / edit / reply to this conversation on ReviewNB licedric commented on 2021-12-04T01:00:46Z Line #10. def get_demands_rev(a,b,hist_p, p): What does this function do? Add it as a comment. FengShi0705 commented on 2021-12-21T21:15:49Z Done. comment added |
View / edit / reply to this conversation on ReviewNB licedric commented on 2021-12-04T01:00:46Z Line #16. d_i = get_demand( This code is not Pythonic. Try something like d = [get_demand(coeff=a, b=b, prices=all_p[i+1:i+1+t]) for i in range(t)] rev = np.dot(d, p) FengShi0705 commented on 2021-12-21T21:16:24Z Done as suggested |
View / edit / reply to this conversation on ReviewNB licedric commented on 2021-12-04T01:00:47Z The uncertainty of the predicted demand d_t can be represented by its estimated variance." Use comma at the end
"Where beta" -> "where beta" "regularized parameters" -> "regularization parameter" "esitmation" -> "estimation"
Where does the formula for the estimated variance come from? FengShi0705 commented on 2021-12-21T21:17:03Z Done. and a reference to the formula is added |
View / edit / reply to this conversation on ReviewNB licedric commented on 2021-12-04T01:00:48Z "As we mentioned above that price can only take one option per day, this means that one and only one of the binary variables in a day must be 1 and others must be 0."
-> "Since the price can only take one value per day, exactly one of the binary variables in a day must be 1, and the others must be 0."
"large enough coefficients" -> "large enough coefficient" FengShi0705 commented on 2021-12-21T21:17:33Z Done |
Done. Good point, the rounding is a legacy procedure for previous version. There is no need for rounding to take place, so the wording around "rounding" is now removed . View entire conversation on ReviewNB |
Done View entire conversation on ReviewNB |
1 similar comment
Done View entire conversation on ReviewNB |
Done.
Good point, A sentence is now added to explain the discrete price choices. View entire conversation on ReviewNB |
Done.
Now added comments in the code: View entire conversation on ReviewNB |
Done View entire conversation on ReviewNB |
Done. comment added View entire conversation on ReviewNB |
Done as suggested View entire conversation on ReviewNB |
Done. and a reference to the formula is added View entire conversation on ReviewNB |
Done View entire conversation on ReviewNB |
Perfect suggestion. Done View entire conversation on ReviewNB |
Done. reduced the printing size. The rows and columns are now explained in the text. View entire conversation on ReviewNB |
Done View entire conversation on ReviewNB |
2 similar comments
Done View entire conversation on ReviewNB |
Done View entire conversation on ReviewNB |
Really great point. We missed the covariance in this formula. Now we made following changes:
View entire conversation on ReviewNB |
Done, also added covariance calculation in this function now View entire conversation on ReviewNB |
Done. Added explanation sentence View entire conversation on ReviewNB |
Done View entire conversation on ReviewNB |
1 similar comment
Done View entire conversation on ReviewNB |
Done, added wikipedian link View entire conversation on ReviewNB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for taking the time to create this demo notebook for Braket! Fantastic description of the use case. I've added a number of edit requests below, mostly style things, and also some code updates now that we have the option to do default s3 buckets.
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clear the output of this cell, since it's not informative for a reader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that people can run this notebook in their local environment, let's add the ocean sdk and plugins to the pip install:
pip install sklearn dwave-ocean-sdk amazon-braket-ocean-plugin
"source": [ | ||
"# Using quantum annealing on Amazon Braket for price optimization\n", | ||
"\n", | ||
"Combinatorial Optimization is one of the most important fields in optimization. Practical applications can be found in virtually every industry. Prominent examples include supply chain optimization in transport and logistics, portfolio management in finance, and the optimization of clinical trials in healthcare, among many others. It is also one of the most active research topics in operation research and computer science. However, many practical combinatorial optimization problems are NP-hard and require massive computation costs to find solution of good quality. \n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few suggestions to make the start of the paragraph flow more smoothly, moving up a sentence from later in the paragraph:
"Combinatorial Optimization is an active topic of research at the forefront of computer science and operations research, with practical applications across virtually every industry."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an informational link for NP-hard in case a reader isn't familiar with the term. e.g. https://en.wikipedia.org/wiki/NP-hardness
"execution_count": 8, | ||
"id": "a668a23a", | ||
"metadata": {}, | ||
"outputs": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The format of this all_p
output isn't very informative to the reader. Recommend changing the display format to eliminate the Binary
and Num
prefixes and separating out p_data
and p
into separate cells, describing what the expressions mean.
{ | ||
"data": { | ||
"text/plain": [ | ||
"'(((Binary(X_048)*Num(19.000000)+Binary(X_047)*Num(16.000000)+Binary(X_046)*Num(13.000000)+Binary(X...m(12.000000)+Binary(X_009)*Num(10.000000)+Binary(X_007)*Num(5.000000)+Binary(X_008)*Num(8.000000)))'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, this display format is hard on the eyes. Same suggestion as above.
{ | ||
"data": { | ||
"text/plain": [ | ||
"'((((Binary(X_048)*Num(19.000000)+Binary(X_047)*Num(16.000000)+Binary(X_046)*Num(13.000000)+Binary(...X_001)*Num(8.000000))*Num(-0.000535)+Num(0.016381))+Num(1.000000))*Num(100.000000))*Num(-1.000000))'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Display format.
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May want to say here that this cell takes a few minutes to run.
] | ||
} | ||
], | ||
"source": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whitespace seems to have gotten messed up somehow. Please paste in this, which should work instantly with the standard Command/CTRL -> / for commenting/uncommenting multi lines.
# beta_options=[1e2,1e3,1e4,1e5,1e6,1e7,1e8,1e9]
# results = {beta_option:[] for beta_option in beta_options}
# beta_samples = beta_options*6
# for beta_i in beta_samples:
# max_revenue, prediction_variance, energy, opt_demand, opt_prices, rev_std = optimize(
# a = a,
# b = b,
# data_x = data_x,
# selected_hist_prices = p_data,
# price_levels = price_levels,
# Lp = Lp,
# Ld = Ld,
# sigma = sigma ,
# beta=beta_i,
# vol_bound=None,
# )
# print('---')
# print(f"beta_sample:{beta_i}")
# print(f"max_revenue:{max_revenue}")
# print(f"prediction_variance:{prediction_variance}")
# print(f"energy:{energy}")
# print(f"opt_demand:{opt_demand}")
# print(f"opt_prices:{opt_prices}")
# print(f"rev_std: {rev_std}")
# print(f"penalty_term: {max_revenue-beta_i*prediction_variance+energy}")
# results[beta_i].append([energy, max_revenue, prediction_variance, rev_std])
:return: variance | ||
""" | ||
n_samples, t = data_x.shape | ||
ones = np.ones((n_samples, 1), dtype=np.float) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to builtin float
:return: variance | ||
""" | ||
n_samples, t = data_x.shape | ||
ones = np.ones((n_samples, 1), dtype=np.float) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to built-in float
" :return: variance\n", | ||
" \"\"\"\n", | ||
" n_samples, t = data_x.shape\n", | ||
" ones = np.ones((n_samples, 1), dtype=np.float)\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to built-in float
Description of changes:
Adding price optimization notebook.
We prepare to publish an AWS blog post where we used Amazon Braket quantum annealer to solve a price optimization problem. We are adding this notebook to complement the blog post as an asset.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.