Skip to content
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

Ast2ast refactoring #65

Merged
merged 3 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/source/example_big_circuit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -35,14 +35,14 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"QCircuit<test>(21984 gates, 1044 qubits)\n"
"QCircuit<test>(21831 gates, 1036 qubits)\n"
]
}
],
Expand Down
10 changes: 5 additions & 5 deletions docs/source/example_bqm_polynomial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -39,7 +39,7 @@
" (_ret.5, x.5)]"
]
},
"execution_count": 1,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -50,15 +50,15 @@
"\n",
"@qlassf\n",
"def poly(x: Qfixed[3, 3], y: Qfixed[3, 3]) -> Qfixed[3, 3]:\n",
" return x * 3 - y * 2 + 1\n",
" return x * 3 - y * 2 + 1.0\n",
"\n",
"\n",
"poly.expressions"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand All @@ -77,7 +77,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down
41 changes: 15 additions & 26 deletions docs/source/example_bqm_tsp.ipynb

Large diffs are not rendered by default.

23 changes: 7 additions & 16 deletions docs/source/example_simon.ipynb

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions qlasskit/ast2ast/ast2ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from .astrewriter import ASTRewriter
from .constantfolder import ConstantFolder
from .replacemultitargetassign import ReplaceMultiTargetAssign
from .replacetypeann import ReplaceTypeAnn


class IndexReplacer(NodeTransformer):
Expand All @@ -35,11 +37,15 @@ def ast2ast(a_tree):
if sys.version_info < (3, 9):
a_tree = IndexReplacer().visit(a_tree)

# Matrix translator

# Fold constants
a_tree = ConstantFolder().visit(a_tree)

# Replace Type Annotations
a_tree = ReplaceTypeAnn().visit(a_tree)

# Replace multi-target assign
a_tree = ReplaceMultiTargetAssign().visit(a_tree)

# Rewrite the ast
a_tree = ASTRewriter().visit(a_tree)

Expand Down
Loading
Loading