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

Add sympy Serialization #850

Merged
merged 53 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
6d9a5de
Added methods to serialize and deserialize quantum data types.
Epsilon1024 Feb 14, 2024
216b130
Add serialization and deserialization methods for all data types. Write
Epsilon1024 Feb 17, 2024
b85f55c
Merge branch 'main' of https://github.com/quantumlib/Qualtran
Epsilon1024 Feb 17, 2024
fdf1554
Update qualtran/protos/data_types.proto
Epsilon1024 Feb 20, 2024
a3e931d
Update Proto:wq
Epsilon1024 Feb 20, 2024
4acf350
Merge branch 'main' of https://github.com/quantumlib/Qualtran
Epsilon1024 Feb 20, 2024
acd5dc2
Merge branch 'quantumlib:main' into main
Epsilon1024 Feb 20, 2024
7abd5ac
Resolved merge conflict
Epsilon1024 Feb 20, 2024
d183bc8
Fixed error formatting
Epsilon1024 Feb 20, 2024
c8cf49a
Remove bitsize from QBit
Epsilon1024 Feb 20, 2024
aa75cd5
Fixed formatting
Epsilon1024 Feb 21, 2024
f1d36ca
Remove uncessesary files
Epsilon1024 Feb 21, 2024
ecca62a
Fix data type in formatted string in error message
Epsilon1024 Feb 21, 2024
c99e000
Update qualtran/serialization/data_types_test.py
tanujkhattar Feb 21, 2024
f701f55
Merge branch 'quantumlib:main' into main
Epsilon1024 Feb 22, 2024
75e3d6f
Merge branch 'quantumlib:main' into main
Epsilon1024 Mar 6, 2024
847459b
Merge branch 'quantumlib:main' into main
Epsilon1024 Mar 16, 2024
c72368d
Merge branch 'main' of https://github.com/quantumlib/Qualtran
Epsilon1024 Mar 16, 2024
7d8cf0d
Merge branch 'main' of https://github.com/quantumlib/Qualtran
Epsilon1024 Mar 21, 2024
b53db71
Added Sympy serialization.
Epsilon1024 Apr 1, 2024
831195c
Clean up workspace
Epsilon1024 Apr 2, 2024
3f02b95
Merge branch 'main' of https://github.com/quantumlib/Qualtran into sympy
Epsilon1024 Apr 2, 2024
9d0441c
Merge branch 'quantumlib:main' into main
Epsilon1024 Apr 2, 2024
0a816a1
Merge branch 'main' of https://github.com/Epsilon1024/Qualtran
Epsilon1024 Apr 2, 2024
8c8d82f
Remote large tests from get_bloq_examples()
Epsilon1024 Apr 2, 2024
ffba712
Remove qpe_hubbard_model tests
Epsilon1024 Apr 2, 2024
97fcd13
Remove qpe_hubbard tests
Epsilon1024 Apr 2, 2024
16d988b
Cleanup branch
Epsilon1024 Apr 2, 2024
391191e
Only remove the serialization tests from the large bloq.s
Epsilon1024 Apr 3, 2024
3979300
Merge branch 'main' into sympy
Epsilon1024 Apr 3, 2024
32f8495
Address issues with failing sympy tests.
Epsilon1024 Apr 4, 2024
fe55ec8
Fix formatting
Epsilon1024 Apr 4, 2024
8fac303
Merge branch 'main' into sympy
Epsilon1024 Apr 4, 2024
25530b9
Fix formatting
Epsilon1024 Apr 4, 2024
7b95c0b
Delete Untitled.ipynb
Epsilon1024 Apr 4, 2024
8efb139
Cleanup after merging local branches.
Epsilon1024 Apr 4, 2024
c4b97eb
Merge branch 'sympy' of https://github.com/Epsilon1024/Qualtran into …
Epsilon1024 Apr 4, 2024
2ed6c07
Remove changes from PR#849
Epsilon1024 Apr 4, 2024
bbb2b10
Merge branch 'main' of https://github.com/quantumlib/Qualtran into sympy
Epsilon1024 Apr 11, 2024
780a7a5
Fixed assortment of bugs in fraction, and constant symbol serialization
Epsilon1024 Apr 12, 2024
87f8742
Scratch test
Epsilon1024 Apr 12, 2024
fbf36c4
Fixed bad reference to resolver dict by bloq module name.
Epsilon1024 Apr 15, 2024
74bd9e9
Minor refactoring
Epsilon1024 Apr 16, 2024
eb13fa8
Ran formatting tools
Epsilon1024 Apr 16, 2024
3468bc9
Merge branch 'main' of https://github.com/quantumlib/Qualtran into sympy
Epsilon1024 Apr 16, 2024
98784d1
Cleanup forgotten test code.
Epsilon1024 Apr 16, 2024
af1d32c
Add tests, fix naming conventions, and add proper return types.
Epsilon1024 Apr 16, 2024
deb3016
Update sympy_test.py
Epsilon1024 Apr 17, 2024
c426f30
Apply suggestions from code review
Epsilon1024 Apr 17, 2024
95ffb93
Fix sympy_test
Epsilon1024 Apr 17, 2024
cd5ca55
Merge branch 'main' into sympy
tanujkhattar Apr 17, 2024
ed40b30
Merge branch 'main' into sympy
tanujkhattar Apr 19, 2024
8524f33
Fix return type of sympy_expr_from_proto
tanujkhattar Apr 19, 2024
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
1 change: 1 addition & 0 deletions dev_tools/qualtran_dev_tools/bloq_report_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def get_bloq_report_card(
bexamples: Optional[Iterable[BloqExample]] = None,
package_prefix: str = 'qualtran.bloqs.',
) -> pd.DataFrame:

if bclasses is None:
bclasses = get_bloq_classes()
if bexamples is None:
Expand Down
1 change: 0 additions & 1 deletion qualtran/protos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

3 changes: 2 additions & 1 deletion qualtran/protos/bloq.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import "qualtran/protos/args.proto";
import "qualtran/protos/registers.proto";
import "qualtran/protos/data_types.proto";
import "qualtran/protos/ctrl_spec.proto";
import "qualtran/protos/sympy.proto";

package qualtran;

Expand All @@ -32,7 +33,7 @@ message BloqArg {
double float_val = 3;
string string_val = 4;
// Sympy expression generated using str(expr).
string sympy_expr = 5;
Term sympy_expr = 5;
// N-dimensional numpy array stored as bytes.
NDArray ndarray = 6;
// Integer reference of a subbloq. Assumes access to a BloqLibrary.
Expand Down
35 changes: 18 additions & 17 deletions qualtran/protos/bloq_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions qualtran/protos/bloq_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import qualtran.protos.args_pb2
import qualtran.protos.ctrl_spec_pb2
import qualtran.protos.data_types_pb2
import qualtran.protos.registers_pb2
import qualtran.protos.sympy_pb2
import sys

if sys.version_info >= (3, 8):
Expand Down Expand Up @@ -56,8 +57,9 @@ class BloqArg(google.protobuf.message.Message):
int_val: builtins.int
float_val: builtins.float
string_val: builtins.str
sympy_expr: builtins.str
"""Sympy expression generated using str(expr)."""
@property
def sympy_expr(self) -> qualtran.protos.sympy_pb2.Term:
"""Sympy expression generated using str(expr)."""
@property
def ndarray(self) -> qualtran.protos.args_pb2.NDArray:
"""N-dimensional numpy array stored as bytes."""
Expand Down Expand Up @@ -86,7 +88,7 @@ class BloqArg(google.protobuf.message.Message):
int_val: builtins.int = ...,
float_val: builtins.float = ...,
string_val: builtins.str = ...,
sympy_expr: builtins.str = ...,
sympy_expr: qualtran.protos.sympy_pb2.Term | None = ...,
ndarray: qualtran.protos.args_pb2.NDArray | None = ...,
subbloq: builtins.int = ...,
cirq_json_gzip: builtins.bytes = ...,
Expand Down
75 changes: 75 additions & 0 deletions qualtran/protos/sympy.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
Copyright 2023 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

syntax = "proto3";
package qualtran;

// A function sympy expression.
enum Function {
// Each Term has an associated function. A "NONE" function means that the term
// is made up of a single parameter and can not be decomposed further.
NONE = 0;
Epsilon1024 marked this conversation as resolved.
Show resolved Hide resolved
Add = 1;
Mul = 2;
Pow = 3;
Mod = 4;
Log = 5;
Floor = 6;
Ceiling = 7;
Max = 8;
Min = 9;
Sin = 10;
Cos = 11;
Tan = 12;
}

// Represents a constant, rational number.
message Rational {
Parameter numerator = 1;
Parameter denominator = 2;
}

enum ConstSymbol {
Pi = 0;
E = 1;
EulerGamma = 2;
Infinity = 3;
ImaginaryUnit = 4;
}

// A single parameter of a sympy expression.
message Parameter {
oneof parameter {
int32 const_int = 1;
string symbol = 2;
Rational const_rat = 3;
float const_float = 4;
ConstSymbol const_symbol = 5;

}
}

message Operand {
oneof operand {
Term term = 1;
Parameter parameter = 2;
}
}

message Term {
Function function = 1;
repeated Operand operands = 2;
}
36 changes: 36 additions & 0 deletions qualtran/protos/sympy_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading