Skip to content

Commit

Permalink
Revert "bug fix: use string of cost function"
Browse files Browse the repository at this point in the history
This reverts commit f2061f8.
  • Loading branch information
wrightjandrew committed Mar 16, 2024
1 parent c15d6d4 commit bb121d2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 45 deletions.
51 changes: 8 additions & 43 deletions examples/dbi/dbi_scheduling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -43,24 +43,9 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"[Qibo 0.2.5|INFO|2024-03-12 17:24:06]: Using qibojit (numba) backend on /CPU:0\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Initial off diagonal norm 37.94733192202055\n"
]
}
],
"outputs": [],
"source": [
"# Hamiltonian\n",
"set_backend(\"qibojit\", \"numba\")\n",
Expand All @@ -86,7 +71,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -109,24 +94,9 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": null,
"metadata": {},
"outputs": [
{
"ename": "TypeError",
"evalue": "loss() got an unexpected keyword argument 'state'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[16], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[39m# grid_search\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m step_grid \u001b[39m=\u001b[39m dbi\u001b[39m.\u001b[39;49mchoose_step(scheduling\u001b[39m=\u001b[39;49mDoubleBracketScheduling\u001b[39m.\u001b[39;49mgrid_search)\n\u001b[0;32m 3\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39m'\u001b[39m\u001b[39mgrid_search step:\u001b[39m\u001b[39m'\u001b[39m, step_grid)\n\u001b[0;32m 4\u001b[0m \u001b[39m# hyperopt\u001b[39;00m\n",
"File \u001b[1;32mc:\\Users\\andre\\Documents\\GitHub\\qibo\\.conda\\lib\\site-packages\\qibo\\models\\dbi\\double_bracket.py:164\u001b[0m, in \u001b[0;36mDoubleBracketIteration.choose_step\u001b[1;34m(self, d, scheduling, **kwargs)\u001b[0m\n\u001b[0;32m 162\u001b[0m \u001b[39mif\u001b[39;00m scheduling \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m 163\u001b[0m scheduling \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mscheduling\n\u001b[1;32m--> 164\u001b[0m step \u001b[39m=\u001b[39m scheduling(\u001b[39mself\u001b[39m, d\u001b[39m=\u001b[39md, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n\u001b[0;32m 165\u001b[0m \u001b[39mif\u001b[39;00m (\n\u001b[0;32m 166\u001b[0m step \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m\n\u001b[0;32m 167\u001b[0m \u001b[39mand\u001b[39;00m scheduling \u001b[39m==\u001b[39m DoubleBracketScheduling\u001b[39m.\u001b[39mpolynomial_approximation\n\u001b[0;32m 168\u001b[0m ):\n\u001b[0;32m 169\u001b[0m kwargs[\u001b[39m\"\u001b[39m\u001b[39mn\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m kwargs\u001b[39m.\u001b[39mget(\u001b[39m\"\u001b[39m\u001b[39mn\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m3\u001b[39m)\n",
"File \u001b[1;32mc:\\Users\\andre\\Documents\\GitHub\\qibo\\.conda\\lib\\site-packages\\qibo\\models\\dbi\\utils_scheduling.py:47\u001b[0m, in \u001b[0;36mgrid_search_step\u001b[1;34m(dbi_object, step_min, step_max, num_evals, space, d, state)\u001b[0m\n\u001b[0;32m 44\u001b[0m \u001b[39mif\u001b[39;00m d \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m 45\u001b[0m d \u001b[39m=\u001b[39m dbi_object\u001b[39m.\u001b[39mdiagonal_h_matrix\n\u001b[1;32m---> 47\u001b[0m loss_list \u001b[39m=\u001b[39m [dbi_object\u001b[39m.\u001b[39mloss(step, d\u001b[39m=\u001b[39md, state\u001b[39m=\u001b[39mstate) \u001b[39mfor\u001b[39;00m step \u001b[39min\u001b[39;00m space]\n\u001b[0;32m 48\u001b[0m idx_max_loss \u001b[39m=\u001b[39m np\u001b[39m.\u001b[39margmin(loss_list)\n\u001b[0;32m 49\u001b[0m \u001b[39mreturn\u001b[39;00m space[idx_max_loss]\n",
"File \u001b[1;32mc:\\Users\\andre\\Documents\\GitHub\\qibo\\.conda\\lib\\site-packages\\qibo\\models\\dbi\\utils_scheduling.py:47\u001b[0m, in \u001b[0;36m<listcomp>\u001b[1;34m(.0)\u001b[0m\n\u001b[0;32m 44\u001b[0m \u001b[39mif\u001b[39;00m d \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m 45\u001b[0m d \u001b[39m=\u001b[39m dbi_object\u001b[39m.\u001b[39mdiagonal_h_matrix\n\u001b[1;32m---> 47\u001b[0m loss_list \u001b[39m=\u001b[39m [dbi_object\u001b[39m.\u001b[39;49mloss(step, d\u001b[39m=\u001b[39;49md, state\u001b[39m=\u001b[39;49mstate) \u001b[39mfor\u001b[39;00m step \u001b[39min\u001b[39;00m space]\n\u001b[0;32m 48\u001b[0m idx_max_loss \u001b[39m=\u001b[39m np\u001b[39m.\u001b[39margmin(loss_list)\n\u001b[0;32m 49\u001b[0m \u001b[39mreturn\u001b[39;00m space[idx_max_loss]\n",
"\u001b[1;31mTypeError\u001b[0m: loss() got an unexpected keyword argument 'state'"
]
}
],
"outputs": [],
"source": [
"# grid_search\n",
"step_grid = dbi.choose_step(scheduling=DoubleBracketScheduling.grid_search)\n",
Expand Down Expand Up @@ -447,7 +417,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "DBF_qibo",
"language": "python",
"name": "python3"
},
Expand All @@ -461,12 +431,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
},
"vscode": {
"interpreter": {
"hash": "48caf7dabad7b721a854729228548373f17e53f40870080394d552284aea7c35"
}
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
1 change: 0 additions & 1 deletion src/qibo/models/dbi/double_bracket.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def __init__(
self.mode = mode
self.scheduling = scheduling
self.cost = cost
self.cost_str = cost.name
self.state = state

def __call__(
Expand Down
2 changes: 1 addition & 1 deletion src/qibo/models/dbi/utils_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def polynomial_step(
backup_scheduling (`DoubleBracketScheduling`): the scheduling method to use in case no real positive roots are found.
"""
if cost is None:
cost = dbi_object.cost.name
cost = dbi_object.cost
if d is None:
d = dbi_object.diagonal_h_matrix

Expand Down

0 comments on commit bb121d2

Please sign in to comment.