From 6d9a5dea5ac42dad3df87ff8dfda160198a16c7e Mon Sep 17 00:00:00 2001 From: Arren Bustamante Date: Wed, 14 Feb 2024 01:49:40 +0000 Subject: [PATCH 01/34] Added methods to serialize and deserialize quantum data types. --- qualtran/protos/data_types.proto | 62 ++++ qualtran/protos/data_types_pb2.py | 422 +++++++++++++++++++++++++++ qualtran/serialization/data_types.py | 61 ++++ 3 files changed, 545 insertions(+) create mode 100644 qualtran/protos/data_types.proto create mode 100644 qualtran/protos/data_types_pb2.py create mode 100644 qualtran/serialization/data_types.py diff --git a/qualtran/protos/data_types.proto b/qualtran/protos/data_types.proto new file mode 100644 index 000000000..27196c0c5 --- /dev/null +++ b/qualtran/protos/data_types.proto @@ -0,0 +1,62 @@ +/* + 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; + +message QDType { + oneof bitsize { + int64 bitsize_int = 1; + string bitsize_expr = 2; + } + oneof data_type { + QBit qbit = 3; + QAny qany = 4; + QInt qint = 5; + QOnesComp q_ones_comp = 6; + QUInt quint = 7; + BoundedQUInt bounded_q_int = 8; + QFixedPoint q_fxp = 9; + } +} + +message QBit { +} + +message QAny { +} + +message QInt { +} + +message QOnesComp { +} +message QUInt { +} + +message BoundedQUInt { + + int64 iteration_length = 1; +} + +message QFixedPoint { + int64 num_frac = 1; + bool signed = 2; +} + + + diff --git a/qualtran/protos/data_types_pb2.py b/qualtran/protos/data_types_pb2.py new file mode 100644 index 000000000..4502ccbc0 --- /dev/null +++ b/qualtran/protos/data_types_pb2.py @@ -0,0 +1,422 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: data_types.proto +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='data_types.proto', + package='qualtran', + syntax='proto3', + serialized_options=None, + create_key=_descriptor._internal_create_key, + serialized_pb=b'\n\x10\x64\x61ta_types.proto\x12\x08qualtran\"\xd6\x02\n\x06QDType\x12\x15\n\x0b\x62itsize_int\x18\x01 \x01(\x03H\x00\x12\x16\n\x0c\x62itsize_expr\x18\x02 \x01(\tH\x00\x12\x1e\n\x04qbit\x18\x03 \x01(\x0b\x32\x0e.qualtran.QBitH\x01\x12\x1e\n\x04qany\x18\x04 \x01(\x0b\x32\x0e.qualtran.QAnyH\x01\x12\x1e\n\x04qint\x18\x05 \x01(\x0b\x32\x0e.qualtran.QIntH\x01\x12*\n\x0bq_ones_comp\x18\x06 \x01(\x0b\x32\x13.qualtran.QOnesCompH\x01\x12 \n\x05quint\x18\x07 \x01(\x0b\x32\x0f.qualtran.QUIntH\x01\x12/\n\rbounded_q_int\x18\x08 \x01(\x0b\x32\x16.qualtran.BoundedQUIntH\x01\x12&\n\x05q_fxp\x18\t \x01(\x0b\x32\x15.qualtran.QFixedPointH\x01\x42\t\n\x07\x62itsizeB\x0b\n\tdata_type\"\x06\n\x04QBit\"\x06\n\x04QAny\"\x06\n\x04QInt\"\x0b\n\tQOnesComp\"\x07\n\x05QUInt\"(\n\x0c\x42oundedQUInt\x12\x18\n\x10iteration_length\x18\x01 \x01(\x03\"/\n\x0bQFixedPoint\x12\x10\n\x08num_frac\x18\x01 \x01(\x03\x12\x0e\n\x06signed\x18\x02 \x01(\x08\x62\x06proto3' +) + + + + +_QDTYPE = _descriptor.Descriptor( + name='QDType', + full_name='qualtran.QDType', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='bitsize_int', full_name='qualtran.QDType.bitsize_int', index=0, + number=1, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='bitsize_expr', full_name='qualtran.QDType.bitsize_expr', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='qbit', full_name='qualtran.QDType.qbit', index=2, + number=3, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='qany', full_name='qualtran.QDType.qany', index=3, + number=4, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='qint', full_name='qualtran.QDType.qint', index=4, + number=5, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='q_ones_comp', full_name='qualtran.QDType.q_ones_comp', index=5, + number=6, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='quint', full_name='qualtran.QDType.quint', index=6, + number=7, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='bounded_q_int', full_name='qualtran.QDType.bounded_q_int', index=7, + number=8, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='q_fxp', full_name='qualtran.QDType.q_fxp', index=8, + number=9, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + _descriptor.OneofDescriptor( + name='bitsize', full_name='qualtran.QDType.bitsize', + index=0, containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[]), + _descriptor.OneofDescriptor( + name='data_type', full_name='qualtran.QDType.data_type', + index=1, containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[]), + ], + serialized_start=31, + serialized_end=373, +) + + +_QBIT = _descriptor.Descriptor( + name='QBit', + full_name='qualtran.QBit', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=375, + serialized_end=381, +) + + +_QANY = _descriptor.Descriptor( + name='QAny', + full_name='qualtran.QAny', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=383, + serialized_end=389, +) + + +_QINT = _descriptor.Descriptor( + name='QInt', + full_name='qualtran.QInt', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=391, + serialized_end=397, +) + + +_QONESCOMP = _descriptor.Descriptor( + name='QOnesComp', + full_name='qualtran.QOnesComp', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=399, + serialized_end=410, +) + + +_QUINT = _descriptor.Descriptor( + name='QUInt', + full_name='qualtran.QUInt', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=412, + serialized_end=419, +) + + +_BOUNDEDQUINT = _descriptor.Descriptor( + name='BoundedQUInt', + full_name='qualtran.BoundedQUInt', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='iteration_length', full_name='qualtran.BoundedQUInt.iteration_length', index=0, + number=1, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=421, + serialized_end=461, +) + + +_QFIXEDPOINT = _descriptor.Descriptor( + name='QFixedPoint', + full_name='qualtran.QFixedPoint', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='num_frac', full_name='qualtran.QFixedPoint.num_frac', index=0, + number=1, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='signed', full_name='qualtran.QFixedPoint.signed', index=1, + number=2, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=463, + serialized_end=510, +) + +_QDTYPE.fields_by_name['qbit'].message_type = _QBIT +_QDTYPE.fields_by_name['qany'].message_type = _QANY +_QDTYPE.fields_by_name['qint'].message_type = _QINT +_QDTYPE.fields_by_name['q_ones_comp'].message_type = _QONESCOMP +_QDTYPE.fields_by_name['quint'].message_type = _QUINT +_QDTYPE.fields_by_name['bounded_q_int'].message_type = _BOUNDEDQUINT +_QDTYPE.fields_by_name['q_fxp'].message_type = _QFIXEDPOINT +_QDTYPE.oneofs_by_name['bitsize'].fields.append( + _QDTYPE.fields_by_name['bitsize_int']) +_QDTYPE.fields_by_name['bitsize_int'].containing_oneof = _QDTYPE.oneofs_by_name['bitsize'] +_QDTYPE.oneofs_by_name['bitsize'].fields.append( + _QDTYPE.fields_by_name['bitsize_expr']) +_QDTYPE.fields_by_name['bitsize_expr'].containing_oneof = _QDTYPE.oneofs_by_name['bitsize'] +_QDTYPE.oneofs_by_name['data_type'].fields.append( + _QDTYPE.fields_by_name['qbit']) +_QDTYPE.fields_by_name['qbit'].containing_oneof = _QDTYPE.oneofs_by_name['data_type'] +_QDTYPE.oneofs_by_name['data_type'].fields.append( + _QDTYPE.fields_by_name['qany']) +_QDTYPE.fields_by_name['qany'].containing_oneof = _QDTYPE.oneofs_by_name['data_type'] +_QDTYPE.oneofs_by_name['data_type'].fields.append( + _QDTYPE.fields_by_name['qint']) +_QDTYPE.fields_by_name['qint'].containing_oneof = _QDTYPE.oneofs_by_name['data_type'] +_QDTYPE.oneofs_by_name['data_type'].fields.append( + _QDTYPE.fields_by_name['q_ones_comp']) +_QDTYPE.fields_by_name['q_ones_comp'].containing_oneof = _QDTYPE.oneofs_by_name['data_type'] +_QDTYPE.oneofs_by_name['data_type'].fields.append( + _QDTYPE.fields_by_name['quint']) +_QDTYPE.fields_by_name['quint'].containing_oneof = _QDTYPE.oneofs_by_name['data_type'] +_QDTYPE.oneofs_by_name['data_type'].fields.append( + _QDTYPE.fields_by_name['bounded_q_int']) +_QDTYPE.fields_by_name['bounded_q_int'].containing_oneof = _QDTYPE.oneofs_by_name['data_type'] +_QDTYPE.oneofs_by_name['data_type'].fields.append( + _QDTYPE.fields_by_name['q_fxp']) +_QDTYPE.fields_by_name['q_fxp'].containing_oneof = _QDTYPE.oneofs_by_name['data_type'] +DESCRIPTOR.message_types_by_name['QDType'] = _QDTYPE +DESCRIPTOR.message_types_by_name['QBit'] = _QBIT +DESCRIPTOR.message_types_by_name['QAny'] = _QANY +DESCRIPTOR.message_types_by_name['QInt'] = _QINT +DESCRIPTOR.message_types_by_name['QOnesComp'] = _QONESCOMP +DESCRIPTOR.message_types_by_name['QUInt'] = _QUINT +DESCRIPTOR.message_types_by_name['BoundedQUInt'] = _BOUNDEDQUINT +DESCRIPTOR.message_types_by_name['QFixedPoint'] = _QFIXEDPOINT +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +QDType = _reflection.GeneratedProtocolMessageType('QDType', (_message.Message,), { + 'DESCRIPTOR' : _QDTYPE, + '__module__' : 'data_types_pb2' + # @@protoc_insertion_point(class_scope:qualtran.QDType) + }) +_sym_db.RegisterMessage(QDType) + +QBit = _reflection.GeneratedProtocolMessageType('QBit', (_message.Message,), { + 'DESCRIPTOR' : _QBIT, + '__module__' : 'data_types_pb2' + # @@protoc_insertion_point(class_scope:qualtran.QBit) + }) +_sym_db.RegisterMessage(QBit) + +QAny = _reflection.GeneratedProtocolMessageType('QAny', (_message.Message,), { + 'DESCRIPTOR' : _QANY, + '__module__' : 'data_types_pb2' + # @@protoc_insertion_point(class_scope:qualtran.QAny) + }) +_sym_db.RegisterMessage(QAny) + +QInt = _reflection.GeneratedProtocolMessageType('QInt', (_message.Message,), { + 'DESCRIPTOR' : _QINT, + '__module__' : 'data_types_pb2' + # @@protoc_insertion_point(class_scope:qualtran.QInt) + }) +_sym_db.RegisterMessage(QInt) + +QOnesComp = _reflection.GeneratedProtocolMessageType('QOnesComp', (_message.Message,), { + 'DESCRIPTOR' : _QONESCOMP, + '__module__' : 'data_types_pb2' + # @@protoc_insertion_point(class_scope:qualtran.QOnesComp) + }) +_sym_db.RegisterMessage(QOnesComp) + +QUInt = _reflection.GeneratedProtocolMessageType('QUInt', (_message.Message,), { + 'DESCRIPTOR' : _QUINT, + '__module__' : 'data_types_pb2' + # @@protoc_insertion_point(class_scope:qualtran.QUInt) + }) +_sym_db.RegisterMessage(QUInt) + +BoundedQUInt = _reflection.GeneratedProtocolMessageType('BoundedQUInt', (_message.Message,), { + 'DESCRIPTOR' : _BOUNDEDQUINT, + '__module__' : 'data_types_pb2' + # @@protoc_insertion_point(class_scope:qualtran.BoundedQUInt) + }) +_sym_db.RegisterMessage(BoundedQUInt) + +QFixedPoint = _reflection.GeneratedProtocolMessageType('QFixedPoint', (_message.Message,), { + 'DESCRIPTOR' : _QFIXEDPOINT, + '__module__' : 'data_types_pb2' + # @@protoc_insertion_point(class_scope:qualtran.QFixedPoint) + }) +_sym_db.RegisterMessage(QFixedPoint) + + +# @@protoc_insertion_point(module_scope) diff --git a/qualtran/serialization/data_types.py b/qualtran/serialization/data_types.py new file mode 100644 index 000000000..df5a860a4 --- /dev/null +++ b/qualtran/serialization/data_types.py @@ -0,0 +1,61 @@ +import dataclasses +import inspect +import sympy + +from typing import Any, Callable, Dict, List, Optional, Union +import attrs + +from qualtran import QDType, QBit, QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt, QFxp +from qualtran.protos import data_types_pb2 + +def data_type_to_proto(data: QDType) -> data_types_pb2.QDType: + + if isinstance(data.bitsize, int): + dtype = data_types_pb2.QDType(bitsize_int=data.bitsize) + elif isinstance(data.bitsize, sympy.Expr): + dtype = data_types_pb2.QDType(bitsize_expr=str(data.bitsize)) + else: + raise TypeError("Bitsize must either be an integer or a sympy expression") + + if isinstance(data, QBit): + dtype.qbit.SetInParent() + elif isinstance(data, QAny): + dtype.qany.SetInParent() + elif isinstance(data, QInt): + dtype.qint.SetInParent() + elif isinstance(data, QIntOnesComp): + dtype.q_ones_comp.SetInParent() + elif isinstance(data, QUInt): + dtype.quint.SetInParent() + elif isinstance(data, BoundedQUInt): + dtype.bounded_q_int.SetInParent() + dtype.bounded_q_int.iteration_length = data.iteration_length + elif isinstance(data, QFxp): + dtype.q_fxp.SetInParent() + dtype.num_frac = data.num_frac + dtype.signed = data.signed + else: + raise TypeError("data must be of one of the following subtypes: QBit, QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt, QFixedPoint") + return dtype + +def data_type_from_proto(data: data_types_pb2.QDType): + if isinstance(data.qbit, data_types_pb2.QBit): + return QBit() + elif isinstance(data.qany, data_types_pb2.QAny): + return QAny(data.bitsize_int) + elif isinstance(data.qint, data_types_pb2.QInt): + return QInt(data.bitsize_int) + elif isinstance(data.q_ones_comp, data_types_pb2.QIntOnesComp): + return QIntOnesComp(data.bitsize_int) + elif isinstance(data.quint, data_types_pb2.QUInt): + return QUInt(data.bitsize_int) + elif isinstance(data.bounded_q_int, data_types_pb2.BoundedQInt): + return BoundedQUInt(data.bitsize_int, data.bounded_q_int.iteration_length) + elif isinstance(data.q_fxp, data_types_pb2.QFixedPoint): + return QFxp(data.bitsize_int, data.signed) +a_qbit = BoundedQUInt(8, 2) + +serialized_qbit = data_type_to_proto(a_qbit) +original_qbit = data_type_from_proto(serialized_qbit) + + From 216b13097e666df65e0728247f7b9d10b7dcc7ab Mon Sep 17 00:00:00 2001 From: Arren Bustamante Date: Sat, 17 Feb 2024 00:30:51 +0000 Subject: [PATCH 02/34] Add serialization and deserialization methods for all data types. Write unit tests to ensure round trip of each datatype using both numeric and sympy inputs. --- qualtran/serialization/data_types.py | 119 +++++++++++++--------- qualtran/serialization/data_types_test.py | 64 ++++++++++++ 2 files changed, 135 insertions(+), 48 deletions(-) create mode 100644 qualtran/serialization/data_types_test.py diff --git a/qualtran/serialization/data_types.py b/qualtran/serialization/data_types.py index df5a860a4..a1b4420e6 100644 --- a/qualtran/serialization/data_types.py +++ b/qualtran/serialization/data_types.py @@ -1,61 +1,84 @@ -import dataclasses -import inspect -import sympy - -from typing import Any, Callable, Dict, List, Optional, Union -import attrs +# 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. +from typing import Union from qualtran import QDType, QBit, QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt, QFxp from qualtran.protos import data_types_pb2 +from qualtran.serialization.args import int_or_sympy_from_proto,int_or_sympy_to_proto -def data_type_to_proto(data: QDType) -> data_types_pb2.QDType: - - if isinstance(data.bitsize, int): - dtype = data_types_pb2.QDType(bitsize_int=data.bitsize) - elif isinstance(data.bitsize, sympy.Expr): - dtype = data_types_pb2.QDType(bitsize_expr=str(data.bitsize)) - else: - raise TypeError("Bitsize must either be an integer or a sympy expression") - + +SerializedDataTypes = Union[data_types_pb2.QBit, data_types_pb2.QAny, + data_types_pb2.QInt, data_types_pb2.QIntOnesComp, + data_types_pb2.QUInt, data_types_pb2.BoundedQUInt, + data_types_pb2.QFxp] + +def data_type_to_proto(data: QDType) -> SerializedDataTypes: if isinstance(data, QBit): - dtype.qbit.SetInParent() - elif isinstance(data, QAny): - dtype.qany.SetInParent() + return data_types_pb2.QBit() + + bitsize = int_or_sympy_to_proto(data.bitsize) + if isinstance(data, QAny): + return data_types_pb2.QAny(bitsize=bitsize) elif isinstance(data, QInt): - dtype.qint.SetInParent() + return data_types_pb2.QInt(bitsize=bitsize) elif isinstance(data, QIntOnesComp): - dtype.q_ones_comp.SetInParent() + return data_types_pb2.QIntOnesComp(bitsize=bitsize) elif isinstance(data, QUInt): - dtype.quint.SetInParent() + return data_types_pb2.QUInt(bitsize=bitsize) elif isinstance(data, BoundedQUInt): - dtype.bounded_q_int.SetInParent() - dtype.bounded_q_int.iteration_length = data.iteration_length + iteration_length = int_or_sympy_to_proto(data.iteration_length) + return data_types_pb2.BoundedQUInt(bitsize=bitsize, + iteration_length=iteration_length) elif isinstance(data, QFxp): - dtype.q_fxp.SetInParent() - dtype.num_frac = data.num_frac - dtype.signed = data.signed + num_frac = int_or_sympy_to_proto(data.num_frac) + return data_types_pb2.QFxp(bitsize=bitsize, + num_frac=num_frac, + signed=data.signed) else: - raise TypeError("data must be of one of the following subtypes: QBit, QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt, QFixedPoint") - return dtype + raise TypeError("Data must be of one of the following subtypes: " \ + "QBit, QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt,"\ + " QFixedPoint") -def data_type_from_proto(data: data_types_pb2.QDType): - if isinstance(data.qbit, data_types_pb2.QBit): +def data_type_from_proto(serialized): + if isinstance(serialized, data_types_pb2.QBit): return QBit() - elif isinstance(data.qany, data_types_pb2.QAny): - return QAny(data.bitsize_int) - elif isinstance(data.qint, data_types_pb2.QInt): - return QInt(data.bitsize_int) - elif isinstance(data.q_ones_comp, data_types_pb2.QIntOnesComp): - return QIntOnesComp(data.bitsize_int) - elif isinstance(data.quint, data_types_pb2.QUInt): - return QUInt(data.bitsize_int) - elif isinstance(data.bounded_q_int, data_types_pb2.BoundedQInt): - return BoundedQUInt(data.bitsize_int, data.bounded_q_int.iteration_length) - elif isinstance(data.q_fxp, data_types_pb2.QFixedPoint): - return QFxp(data.bitsize_int, data.signed) -a_qbit = BoundedQUInt(8, 2) - -serialized_qbit = data_type_to_proto(a_qbit) -original_qbit = data_type_from_proto(serialized_qbit) - - + + bitsize = int_or_sympy_from_proto(serialized.bitsize) + if isinstance(serialized, data_types_pb2.QAny): + return QAny(bitsize=bitsize) + elif isinstance(serialized, data_types_pb2.QInt): + return QInt(bitsize=bitsize) + elif isinstance(serialized, data_types_pb2.QIntOnesComp): + return QIntOnesComp(bitsize=bitsize) + elif isinstance(serialized, data_types_pb2.QUInt): + return QUInt(bitsize=bitsize) + elif isinstance(serialized, data_types_pb2.QIntOnesComp): + return QIntOnesComp(bitsize=bitsize) + elif isinstance(serialized, data_types_pb2.QUInt): + return QUInt(bitsize=bitsize) + elif isinstance(serialized, data_types_pb2.BoundedQUInt): + iteration_length = int_or_sympy_from_proto(serialized.iteration_length) + return BoundedQUInt(bitsize=bitsize, + iteration_length=iteration_length) + elif isinstance(serialized, data_types_pb2.QFxp): + num_frac = int_or_sympy_from_proto(serialized.num_frac) + return QFxp(bitsize=bitsize, num_frac=num_frac, + signed=serialized.signed) + else: + raise TypeError("Data type {} is not recognized."\ + " It must be of one of the following subtypes: QBit, "\ + "QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt, "\ + "QFixedPoint".format(str(type(serialized)))) + + \ No newline at end of file diff --git a/qualtran/serialization/data_types_test.py b/qualtran/serialization/data_types_test.py new file mode 100644 index 000000000..f58cc0569 --- /dev/null +++ b/qualtran/serialization/data_types_test.py @@ -0,0 +1,64 @@ +# 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. + +from qualtran.serialization.data_types import data_type_from_proto, data_type_to_proto +import pytest + +import sympy + +from typing import Union + +from qualtran import QDType, QBit, QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt, QFxp + +def round_trip(data: QDType): + serialized_qbit = data_type_to_proto(data) + original_qbit = data_type_from_proto(serialized_qbit) + + assert data.num_qubits == original_qbit.num_qubits + if isinstance(serialized_qbit, BoundedQUInt): + assert data.iteration_length == original_qbit.iteration_length + elif isinstance(serialized_qbit, QFxp): + assert data.num_frac == original_qbit.num_frac + assert data.signed == original_qbit.signed + +def test_qbit(): + round_trip(QBit()) + +@pytest.mark.parametrize("num_qbits", + [10, 1000, sympy.Symbol("a") * sympy.Symbol("b")]) +def test_qint_succeeds(num_qbits: Union[int, sympy.Expr]): + round_trip(QInt(num_qbits)) + +@pytest.mark.parametrize("num_qbits", + [10, 1000, sympy.Symbol("a") * sympy.Symbol("b")]) +def test_basic_data_types(num_qbits:int): + round_trip(QAny(num_qbits)) + round_trip(QIntOnesComp(num_qbits)) + round_trip(QUInt(num_qbits)) + +@pytest.mark.parametrize("num_qbits, iteration_length",[ + (10, 1), (5, 10), (1000, 1000), + (sympy.Symbol("a") * sympy.Symbol("b"), 10), + (sympy.Symbol("a"), sympy.Symbol("b")) + ]) +def test_bounded_q_u_int(num_qbits: int, iteration_length): + round_trip(BoundedQUInt(num_qbits, iteration_length)) + +@pytest.mark.parametrize("num_qbits, num_frac, signed", [ + (10, 5, True), (10, 5, False), (5,5,False), + (sympy.Symbol("a"), sympy.Symbol("a"), False) + ]) +def test_qfxp(num_qbits:int, num_frac:int, signed:bool): + round_trip(QFxp(num_qbits, num_frac, signed)) + From fdf15541efa5c11373d6f9120c37940953709c09 Mon Sep 17 00:00:00 2001 From: Epsilon1024 <50683403+Epsilon1024@users.noreply.github.com> Date: Tue, 20 Feb 2024 12:01:29 -0800 Subject: [PATCH 03/34] Update qualtran/protos/data_types.proto Co-authored-by: Tanuj Khattar --- qualtran/protos/data_types.proto | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/qualtran/protos/data_types.proto b/qualtran/protos/data_types.proto index 27196c0c5..1d5565419 100644 --- a/qualtran/protos/data_types.proto +++ b/qualtran/protos/data_types.proto @@ -1,18 +1,16 @@ -/* - 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. -*/ +# 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"; From a3e931d9af1699dea848cdcf1c824536b029d15d Mon Sep 17 00:00:00 2001 From: Arren Bustamante Date: Tue, 20 Feb 2024 20:31:31 +0000 Subject: [PATCH 04/34] Update Proto:wq --- qualtran/protos/annotations_pb2.py | 2 +- qualtran/protos/args_pb2.py | 2 +- qualtran/protos/bloq_pb2.py | 6 +- qualtran/protos/data_types.proto | 41 +- qualtran/protos/data_types_pb2.py | 439 ++-------------------- qualtran/protos/data_types_pb2.pyi | 175 +++++++++ qualtran/protos/registers_pb2.py | 2 +- qualtran/serialization/data_types_test.py | 5 +- 8 files changed, 224 insertions(+), 448 deletions(-) create mode 100644 qualtran/protos/data_types_pb2.pyi diff --git a/qualtran/protos/annotations_pb2.py b/qualtran/protos/annotations_pb2.py index 77e511577..9b9ac0949 100644 --- a/qualtran/protos/annotations_pb2.py +++ b/qualtran/protos/annotations_pb2.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: qualtran/protos/annotations.proto +# Protobuf Python Version: 4.25.0 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -19,7 +20,6 @@ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'qualtran.protos.annotations_pb2', _globals) if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None _globals['_TCOMPLEXITY']._serialized_start=47 _globals['_TCOMPLEXITY']._serialized_end=108 diff --git a/qualtran/protos/args_pb2.py b/qualtran/protos/args_pb2.py index 78c782e25..29c33f6af 100644 --- a/qualtran/protos/args_pb2.py +++ b/qualtran/protos/args_pb2.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: qualtran/protos/args.proto +# Protobuf Python Version: 4.25.0 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -19,7 +20,6 @@ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'qualtran.protos.args_pb2', _globals) if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None _globals['_INTORSYMPY']._serialized_start=40 _globals['_INTORSYMPY']._serialized_end=100 diff --git a/qualtran/protos/bloq_pb2.py b/qualtran/protos/bloq_pb2.py index d01e6a3dc..5c555a5ae 100644 --- a/qualtran/protos/bloq_pb2.py +++ b/qualtran/protos/bloq_pb2.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: qualtran/protos/bloq.proto +# Protobuf Python Version: 4.25.0 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -22,10 +23,9 @@ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'qualtran.protos.bloq_pb2', _globals) if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None - _BLOQLIBRARY_BLOQWITHDECOMPOSITION_BLOQCOUNTSENTRY._options = None - _BLOQLIBRARY_BLOQWITHDECOMPOSITION_BLOQCOUNTSENTRY._serialized_options = b'8\001' + _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION_BLOQCOUNTSENTRY']._options = None + _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION_BLOQCOUNTSENTRY']._serialized_options = b'8\001' _globals['_BLOQLIBRARY']._serialized_start=137 _globals['_BLOQLIBRARY']._serialized_end=497 _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION']._serialized_start=227 diff --git a/qualtran/protos/data_types.proto b/qualtran/protos/data_types.proto index 27196c0c5..338669403 100644 --- a/qualtran/protos/data_types.proto +++ b/qualtran/protos/data_types.proto @@ -13,50 +13,37 @@ See the License for the specific language governing permissions and limitations under the License. */ - syntax = "proto3"; - package qualtran; - -message QDType { - oneof bitsize { - int64 bitsize_int = 1; - string bitsize_expr = 2; - } - oneof data_type { - QBit qbit = 3; - QAny qany = 4; - QInt qint = 5; - QOnesComp q_ones_comp = 6; - QUInt quint = 7; - BoundedQUInt bounded_q_int = 8; - QFixedPoint q_fxp = 9; - } -} +import "qualtran/protos/args.proto"; message QBit { + optional int64 bitsize = 1; } message QAny { + optional IntOrSympy bitsize = 1; } message QInt { + optional IntOrSympy bitsize = 1; } -message QOnesComp { +message QIntOnesComp { + optional IntOrSympy bitsize = 1; } + message QUInt { + optional IntOrSympy bitsize = 1; } message BoundedQUInt { - - int64 iteration_length = 1; + optional IntOrSympy bitsize = 1; + optional IntOrSympy iteration_length = 2; } -message QFixedPoint { - int64 num_frac = 1; - bool signed = 2; +message QFxp { + optional IntOrSympy bitsize = 1; + optional IntOrSympy num_frac = 2; + optional bool signed = 3; } - - - diff --git a/qualtran/protos/data_types_pb2.py b/qualtran/protos/data_types_pb2.py index 4502ccbc0..589c0e3a9 100644 --- a/qualtran/protos/data_types_pb2.py +++ b/qualtran/protos/data_types_pb2.py @@ -1,422 +1,39 @@ # -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! -# source: data_types.proto +# source: qualtran/protos/data_types.proto +# Protobuf Python Version: 4.25.0 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection +from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() - - -DESCRIPTOR = _descriptor.FileDescriptor( - name='data_types.proto', - package='qualtran', - syntax='proto3', - serialized_options=None, - create_key=_descriptor._internal_create_key, - serialized_pb=b'\n\x10\x64\x61ta_types.proto\x12\x08qualtran\"\xd6\x02\n\x06QDType\x12\x15\n\x0b\x62itsize_int\x18\x01 \x01(\x03H\x00\x12\x16\n\x0c\x62itsize_expr\x18\x02 \x01(\tH\x00\x12\x1e\n\x04qbit\x18\x03 \x01(\x0b\x32\x0e.qualtran.QBitH\x01\x12\x1e\n\x04qany\x18\x04 \x01(\x0b\x32\x0e.qualtran.QAnyH\x01\x12\x1e\n\x04qint\x18\x05 \x01(\x0b\x32\x0e.qualtran.QIntH\x01\x12*\n\x0bq_ones_comp\x18\x06 \x01(\x0b\x32\x13.qualtran.QOnesCompH\x01\x12 \n\x05quint\x18\x07 \x01(\x0b\x32\x0f.qualtran.QUIntH\x01\x12/\n\rbounded_q_int\x18\x08 \x01(\x0b\x32\x16.qualtran.BoundedQUIntH\x01\x12&\n\x05q_fxp\x18\t \x01(\x0b\x32\x15.qualtran.QFixedPointH\x01\x42\t\n\x07\x62itsizeB\x0b\n\tdata_type\"\x06\n\x04QBit\"\x06\n\x04QAny\"\x06\n\x04QInt\"\x0b\n\tQOnesComp\"\x07\n\x05QUInt\"(\n\x0c\x42oundedQUInt\x12\x18\n\x10iteration_length\x18\x01 \x01(\x03\"/\n\x0bQFixedPoint\x12\x10\n\x08num_frac\x18\x01 \x01(\x03\x12\x0e\n\x06signed\x18\x02 \x01(\x08\x62\x06proto3' -) - - - - -_QDTYPE = _descriptor.Descriptor( - name='QDType', - full_name='qualtran.QDType', - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name='bitsize_int', full_name='qualtran.QDType.bitsize_int', index=0, - number=1, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), - _descriptor.FieldDescriptor( - name='bitsize_expr', full_name='qualtran.QDType.bitsize_expr', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=b"".decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), - _descriptor.FieldDescriptor( - name='qbit', full_name='qualtran.QDType.qbit', index=2, - number=3, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), - _descriptor.FieldDescriptor( - name='qany', full_name='qualtran.QDType.qany', index=3, - number=4, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), - _descriptor.FieldDescriptor( - name='qint', full_name='qualtran.QDType.qint', index=4, - number=5, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), - _descriptor.FieldDescriptor( - name='q_ones_comp', full_name='qualtran.QDType.q_ones_comp', index=5, - number=6, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), - _descriptor.FieldDescriptor( - name='quint', full_name='qualtran.QDType.quint', index=6, - number=7, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), - _descriptor.FieldDescriptor( - name='bounded_q_int', full_name='qualtran.QDType.bounded_q_int', index=7, - number=8, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), - _descriptor.FieldDescriptor( - name='q_fxp', full_name='qualtran.QDType.q_fxp', index=8, - number=9, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - _descriptor.OneofDescriptor( - name='bitsize', full_name='qualtran.QDType.bitsize', - index=0, containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[]), - _descriptor.OneofDescriptor( - name='data_type', full_name='qualtran.QDType.data_type', - index=1, containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[]), - ], - serialized_start=31, - serialized_end=373, -) - - -_QBIT = _descriptor.Descriptor( - name='QBit', - full_name='qualtran.QBit', - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=375, - serialized_end=381, -) - - -_QANY = _descriptor.Descriptor( - name='QAny', - full_name='qualtran.QAny', - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=383, - serialized_end=389, -) - - -_QINT = _descriptor.Descriptor( - name='QInt', - full_name='qualtran.QInt', - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=391, - serialized_end=397, -) - - -_QONESCOMP = _descriptor.Descriptor( - name='QOnesComp', - full_name='qualtran.QOnesComp', - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=399, - serialized_end=410, -) - - -_QUINT = _descriptor.Descriptor( - name='QUInt', - full_name='qualtran.QUInt', - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=412, - serialized_end=419, -) - - -_BOUNDEDQUINT = _descriptor.Descriptor( - name='BoundedQUInt', - full_name='qualtran.BoundedQUInt', - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name='iteration_length', full_name='qualtran.BoundedQUInt.iteration_length', index=0, - number=1, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=421, - serialized_end=461, -) - - -_QFIXEDPOINT = _descriptor.Descriptor( - name='QFixedPoint', - full_name='qualtran.QFixedPoint', - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name='num_frac', full_name='qualtran.QFixedPoint.num_frac', index=0, - number=1, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), - _descriptor.FieldDescriptor( - name='signed', full_name='qualtran.QFixedPoint.signed', index=1, - number=2, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=463, - serialized_end=510, -) - -_QDTYPE.fields_by_name['qbit'].message_type = _QBIT -_QDTYPE.fields_by_name['qany'].message_type = _QANY -_QDTYPE.fields_by_name['qint'].message_type = _QINT -_QDTYPE.fields_by_name['q_ones_comp'].message_type = _QONESCOMP -_QDTYPE.fields_by_name['quint'].message_type = _QUINT -_QDTYPE.fields_by_name['bounded_q_int'].message_type = _BOUNDEDQUINT -_QDTYPE.fields_by_name['q_fxp'].message_type = _QFIXEDPOINT -_QDTYPE.oneofs_by_name['bitsize'].fields.append( - _QDTYPE.fields_by_name['bitsize_int']) -_QDTYPE.fields_by_name['bitsize_int'].containing_oneof = _QDTYPE.oneofs_by_name['bitsize'] -_QDTYPE.oneofs_by_name['bitsize'].fields.append( - _QDTYPE.fields_by_name['bitsize_expr']) -_QDTYPE.fields_by_name['bitsize_expr'].containing_oneof = _QDTYPE.oneofs_by_name['bitsize'] -_QDTYPE.oneofs_by_name['data_type'].fields.append( - _QDTYPE.fields_by_name['qbit']) -_QDTYPE.fields_by_name['qbit'].containing_oneof = _QDTYPE.oneofs_by_name['data_type'] -_QDTYPE.oneofs_by_name['data_type'].fields.append( - _QDTYPE.fields_by_name['qany']) -_QDTYPE.fields_by_name['qany'].containing_oneof = _QDTYPE.oneofs_by_name['data_type'] -_QDTYPE.oneofs_by_name['data_type'].fields.append( - _QDTYPE.fields_by_name['qint']) -_QDTYPE.fields_by_name['qint'].containing_oneof = _QDTYPE.oneofs_by_name['data_type'] -_QDTYPE.oneofs_by_name['data_type'].fields.append( - _QDTYPE.fields_by_name['q_ones_comp']) -_QDTYPE.fields_by_name['q_ones_comp'].containing_oneof = _QDTYPE.oneofs_by_name['data_type'] -_QDTYPE.oneofs_by_name['data_type'].fields.append( - _QDTYPE.fields_by_name['quint']) -_QDTYPE.fields_by_name['quint'].containing_oneof = _QDTYPE.oneofs_by_name['data_type'] -_QDTYPE.oneofs_by_name['data_type'].fields.append( - _QDTYPE.fields_by_name['bounded_q_int']) -_QDTYPE.fields_by_name['bounded_q_int'].containing_oneof = _QDTYPE.oneofs_by_name['data_type'] -_QDTYPE.oneofs_by_name['data_type'].fields.append( - _QDTYPE.fields_by_name['q_fxp']) -_QDTYPE.fields_by_name['q_fxp'].containing_oneof = _QDTYPE.oneofs_by_name['data_type'] -DESCRIPTOR.message_types_by_name['QDType'] = _QDTYPE -DESCRIPTOR.message_types_by_name['QBit'] = _QBIT -DESCRIPTOR.message_types_by_name['QAny'] = _QANY -DESCRIPTOR.message_types_by_name['QInt'] = _QINT -DESCRIPTOR.message_types_by_name['QOnesComp'] = _QONESCOMP -DESCRIPTOR.message_types_by_name['QUInt'] = _QUINT -DESCRIPTOR.message_types_by_name['BoundedQUInt'] = _BOUNDEDQUINT -DESCRIPTOR.message_types_by_name['QFixedPoint'] = _QFIXEDPOINT -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - -QDType = _reflection.GeneratedProtocolMessageType('QDType', (_message.Message,), { - 'DESCRIPTOR' : _QDTYPE, - '__module__' : 'data_types_pb2' - # @@protoc_insertion_point(class_scope:qualtran.QDType) - }) -_sym_db.RegisterMessage(QDType) - -QBit = _reflection.GeneratedProtocolMessageType('QBit', (_message.Message,), { - 'DESCRIPTOR' : _QBIT, - '__module__' : 'data_types_pb2' - # @@protoc_insertion_point(class_scope:qualtran.QBit) - }) -_sym_db.RegisterMessage(QBit) - -QAny = _reflection.GeneratedProtocolMessageType('QAny', (_message.Message,), { - 'DESCRIPTOR' : _QANY, - '__module__' : 'data_types_pb2' - # @@protoc_insertion_point(class_scope:qualtran.QAny) - }) -_sym_db.RegisterMessage(QAny) - -QInt = _reflection.GeneratedProtocolMessageType('QInt', (_message.Message,), { - 'DESCRIPTOR' : _QINT, - '__module__' : 'data_types_pb2' - # @@protoc_insertion_point(class_scope:qualtran.QInt) - }) -_sym_db.RegisterMessage(QInt) - -QOnesComp = _reflection.GeneratedProtocolMessageType('QOnesComp', (_message.Message,), { - 'DESCRIPTOR' : _QONESCOMP, - '__module__' : 'data_types_pb2' - # @@protoc_insertion_point(class_scope:qualtran.QOnesComp) - }) -_sym_db.RegisterMessage(QOnesComp) - -QUInt = _reflection.GeneratedProtocolMessageType('QUInt', (_message.Message,), { - 'DESCRIPTOR' : _QUINT, - '__module__' : 'data_types_pb2' - # @@protoc_insertion_point(class_scope:qualtran.QUInt) - }) -_sym_db.RegisterMessage(QUInt) - -BoundedQUInt = _reflection.GeneratedProtocolMessageType('BoundedQUInt', (_message.Message,), { - 'DESCRIPTOR' : _BOUNDEDQUINT, - '__module__' : 'data_types_pb2' - # @@protoc_insertion_point(class_scope:qualtran.BoundedQUInt) - }) -_sym_db.RegisterMessage(BoundedQUInt) - -QFixedPoint = _reflection.GeneratedProtocolMessageType('QFixedPoint', (_message.Message,), { - 'DESCRIPTOR' : _QFIXEDPOINT, - '__module__' : 'data_types_pb2' - # @@protoc_insertion_point(class_scope:qualtran.QFixedPoint) - }) -_sym_db.RegisterMessage(QFixedPoint) - - +from qualtran.protos import args_pb2 as qualtran_dot_protos_dot_args__pb2 + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n qualtran/protos/data_types.proto\x12\x08qualtran\x1a\x1aqualtran/protos/args.proto\"(\n\x04QBit\x12\x14\n\x07\x62itsize\x18\x01 \x01(\x03H\x00\x88\x01\x01\x42\n\n\x08_bitsize\">\n\x04QAny\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x42\n\n\x08_bitsize\">\n\x04QInt\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x42\n\n\x08_bitsize\"F\n\x0cQIntOnesComp\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x42\n\n\x08_bitsize\"?\n\x05QUInt\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x42\n\n\x08_bitsize\"\x90\x01\n\x0c\x42oundedQUInt\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x12\x33\n\x10iteration_length\x18\x02 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x01\x88\x01\x01\x42\n\n\x08_bitsizeB\x13\n\x11_iteration_length\"\x98\x01\n\x04QFxp\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x12+\n\x08num_frac\x18\x02 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x01\x88\x01\x01\x12\x13\n\x06signed\x18\x03 \x01(\x08H\x02\x88\x01\x01\x42\n\n\x08_bitsizeB\x0b\n\t_num_fracB\t\n\x07_signedb\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'qualtran.protos.data_types_pb2', _globals) +if _descriptor._USE_C_DESCRIPTORS == False: + DESCRIPTOR._options = None + _globals['_QBIT']._serialized_start=74 + _globals['_QBIT']._serialized_end=114 + _globals['_QANY']._serialized_start=116 + _globals['_QANY']._serialized_end=178 + _globals['_QINT']._serialized_start=180 + _globals['_QINT']._serialized_end=242 + _globals['_QINTONESCOMP']._serialized_start=244 + _globals['_QINTONESCOMP']._serialized_end=314 + _globals['_QUINT']._serialized_start=316 + _globals['_QUINT']._serialized_end=379 + _globals['_BOUNDEDQUINT']._serialized_start=382 + _globals['_BOUNDEDQUINT']._serialized_end=526 + _globals['_QFXP']._serialized_start=529 + _globals['_QFXP']._serialized_end=681 # @@protoc_insertion_point(module_scope) diff --git a/qualtran/protos/data_types_pb2.pyi b/qualtran/protos/data_types_pb2.pyi new file mode 100644 index 000000000..256b89302 --- /dev/null +++ b/qualtran/protos/data_types_pb2.pyi @@ -0,0 +1,175 @@ +""" +@generated by mypy-protobuf. Do not edit manually! +isort:skip_file + +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. +""" +import builtins +import google.protobuf.descriptor +import google.protobuf.message +import qualtran.protos.args_pb2 +import sys +import typing + +if sys.version_info >= (3, 8): + import typing as typing_extensions +else: + import typing_extensions + +DESCRIPTOR: google.protobuf.descriptor.FileDescriptor + +@typing_extensions.final +class QBit(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + BITSIZE_FIELD_NUMBER: builtins.int + bitsize: builtins.int + def __init__( + self, + *, + bitsize: builtins.int | None = ..., + ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["_bitsize", b"_bitsize", "bitsize", b"bitsize"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["_bitsize", b"_bitsize", "bitsize", b"bitsize"]) -> None: ... + def WhichOneof(self, oneof_group: typing_extensions.Literal["_bitsize", b"_bitsize"]) -> typing_extensions.Literal["bitsize"] | None: ... + +global___QBit = QBit + +@typing_extensions.final +class QAny(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + BITSIZE_FIELD_NUMBER: builtins.int + @property + def bitsize(self) -> qualtran.protos.args_pb2.IntOrSympy: ... + def __init__( + self, + *, + bitsize: qualtran.protos.args_pb2.IntOrSympy | None = ..., + ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["_bitsize", b"_bitsize", "bitsize", b"bitsize"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["_bitsize", b"_bitsize", "bitsize", b"bitsize"]) -> None: ... + def WhichOneof(self, oneof_group: typing_extensions.Literal["_bitsize", b"_bitsize"]) -> typing_extensions.Literal["bitsize"] | None: ... + +global___QAny = QAny + +@typing_extensions.final +class QInt(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + BITSIZE_FIELD_NUMBER: builtins.int + @property + def bitsize(self) -> qualtran.protos.args_pb2.IntOrSympy: ... + def __init__( + self, + *, + bitsize: qualtran.protos.args_pb2.IntOrSympy | None = ..., + ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["_bitsize", b"_bitsize", "bitsize", b"bitsize"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["_bitsize", b"_bitsize", "bitsize", b"bitsize"]) -> None: ... + def WhichOneof(self, oneof_group: typing_extensions.Literal["_bitsize", b"_bitsize"]) -> typing_extensions.Literal["bitsize"] | None: ... + +global___QInt = QInt + +@typing_extensions.final +class QIntOnesComp(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + BITSIZE_FIELD_NUMBER: builtins.int + @property + def bitsize(self) -> qualtran.protos.args_pb2.IntOrSympy: ... + def __init__( + self, + *, + bitsize: qualtran.protos.args_pb2.IntOrSympy | None = ..., + ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["_bitsize", b"_bitsize", "bitsize", b"bitsize"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["_bitsize", b"_bitsize", "bitsize", b"bitsize"]) -> None: ... + def WhichOneof(self, oneof_group: typing_extensions.Literal["_bitsize", b"_bitsize"]) -> typing_extensions.Literal["bitsize"] | None: ... + +global___QIntOnesComp = QIntOnesComp + +@typing_extensions.final +class QUInt(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + BITSIZE_FIELD_NUMBER: builtins.int + @property + def bitsize(self) -> qualtran.protos.args_pb2.IntOrSympy: ... + def __init__( + self, + *, + bitsize: qualtran.protos.args_pb2.IntOrSympy | None = ..., + ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["_bitsize", b"_bitsize", "bitsize", b"bitsize"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["_bitsize", b"_bitsize", "bitsize", b"bitsize"]) -> None: ... + def WhichOneof(self, oneof_group: typing_extensions.Literal["_bitsize", b"_bitsize"]) -> typing_extensions.Literal["bitsize"] | None: ... + +global___QUInt = QUInt + +@typing_extensions.final +class BoundedQUInt(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + BITSIZE_FIELD_NUMBER: builtins.int + ITERATION_LENGTH_FIELD_NUMBER: builtins.int + @property + def bitsize(self) -> qualtran.protos.args_pb2.IntOrSympy: ... + @property + def iteration_length(self) -> qualtran.protos.args_pb2.IntOrSympy: ... + def __init__( + self, + *, + bitsize: qualtran.protos.args_pb2.IntOrSympy | None = ..., + iteration_length: qualtran.protos.args_pb2.IntOrSympy | None = ..., + ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["_bitsize", b"_bitsize", "_iteration_length", b"_iteration_length", "bitsize", b"bitsize", "iteration_length", b"iteration_length"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["_bitsize", b"_bitsize", "_iteration_length", b"_iteration_length", "bitsize", b"bitsize", "iteration_length", b"iteration_length"]) -> None: ... + @typing.overload + def WhichOneof(self, oneof_group: typing_extensions.Literal["_bitsize", b"_bitsize"]) -> typing_extensions.Literal["bitsize"] | None: ... + @typing.overload + def WhichOneof(self, oneof_group: typing_extensions.Literal["_iteration_length", b"_iteration_length"]) -> typing_extensions.Literal["iteration_length"] | None: ... + +global___BoundedQUInt = BoundedQUInt + +@typing_extensions.final +class QFxp(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + BITSIZE_FIELD_NUMBER: builtins.int + NUM_FRAC_FIELD_NUMBER: builtins.int + SIGNED_FIELD_NUMBER: builtins.int + @property + def bitsize(self) -> qualtran.protos.args_pb2.IntOrSympy: ... + @property + def num_frac(self) -> qualtran.protos.args_pb2.IntOrSympy: ... + signed: builtins.bool + def __init__( + self, + *, + bitsize: qualtran.protos.args_pb2.IntOrSympy | None = ..., + num_frac: qualtran.protos.args_pb2.IntOrSympy | None = ..., + signed: builtins.bool | None = ..., + ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["_bitsize", b"_bitsize", "_num_frac", b"_num_frac", "_signed", b"_signed", "bitsize", b"bitsize", "num_frac", b"num_frac", "signed", b"signed"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["_bitsize", b"_bitsize", "_num_frac", b"_num_frac", "_signed", b"_signed", "bitsize", b"bitsize", "num_frac", b"num_frac", "signed", b"signed"]) -> None: ... + @typing.overload + def WhichOneof(self, oneof_group: typing_extensions.Literal["_bitsize", b"_bitsize"]) -> typing_extensions.Literal["bitsize"] | None: ... + @typing.overload + def WhichOneof(self, oneof_group: typing_extensions.Literal["_num_frac", b"_num_frac"]) -> typing_extensions.Literal["num_frac"] | None: ... + @typing.overload + def WhichOneof(self, oneof_group: typing_extensions.Literal["_signed", b"_signed"]) -> typing_extensions.Literal["signed"] | None: ... + +global___QFxp = QFxp diff --git a/qualtran/protos/registers_pb2.py b/qualtran/protos/registers_pb2.py index 62ba124ac..44b7b4220 100644 --- a/qualtran/protos/registers_pb2.py +++ b/qualtran/protos/registers_pb2.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: qualtran/protos/registers.proto +# Protobuf Python Version: 4.25.0 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -20,7 +21,6 @@ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'qualtran.protos.registers_pb2', _globals) if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None _globals['_REGISTER']._serialized_start=74 _globals['_REGISTER']._serialized_end=265 diff --git a/qualtran/serialization/data_types_test.py b/qualtran/serialization/data_types_test.py index f58cc0569..dcb05fb61 100644 --- a/qualtran/serialization/data_types_test.py +++ b/qualtran/serialization/data_types_test.py @@ -12,13 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from qualtran.serialization.data_types import data_type_from_proto, data_type_to_proto import pytest - import sympy - from typing import Union - +from qualtran.serialization.data_types import data_type_from_proto, data_type_to_proto from qualtran import QDType, QBit, QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt, QFxp def round_trip(data: QDType): From d183bc8dc71c5c283a3ffb648eee55410323e30b Mon Sep 17 00:00:00 2001 From: Arren Bustamante Date: Tue, 20 Feb 2024 23:08:51 +0000 Subject: [PATCH 05/34] Fixed error formatting --- qualtran/serialization/data_types.py | 14 +++++++------- qualtran/serialization/data_types_test.py | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/qualtran/serialization/data_types.py b/qualtran/serialization/data_types.py index a1b4420e6..a9a0efc9d 100644 --- a/qualtran/serialization/data_types.py +++ b/qualtran/serialization/data_types.py @@ -46,11 +46,12 @@ def data_type_to_proto(data: QDType) -> SerializedDataTypes: num_frac=num_frac, signed=data.signed) else: - raise TypeError("Data must be of one of the following subtypes: " \ - "QBit, QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt,"\ - " QFixedPoint") + raise TypeError(f"Data type {type(serialized)} is not recognized."\ + " It must be of one of the following subtypes: QBit, "\ + "QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt, "\ + "QFixedPoint") -def data_type_from_proto(serialized): +def data_type_from_proto(serialized: SerializedDataTypes) -> QDType: if isinstance(serialized, data_types_pb2.QBit): return QBit() @@ -76,9 +77,8 @@ def data_type_from_proto(serialized): return QFxp(bitsize=bitsize, num_frac=num_frac, signed=serialized.signed) else: - raise TypeError("Data type {} is not recognized."\ + raise TypeError(f"Data type {type(serialized)} is not recognized."\ " It must be of one of the following subtypes: QBit, "\ "QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt, "\ - "QFixedPoint".format(str(type(serialized)))) - + "QFixedPoint") \ No newline at end of file diff --git a/qualtran/serialization/data_types_test.py b/qualtran/serialization/data_types_test.py index dcb05fb61..e9481730d 100644 --- a/qualtran/serialization/data_types_test.py +++ b/qualtran/serialization/data_types_test.py @@ -25,7 +25,7 @@ def round_trip(data: QDType): assert data.num_qubits == original_qbit.num_qubits if isinstance(serialized_qbit, BoundedQUInt): assert data.iteration_length == original_qbit.iteration_length - elif isinstance(serialized_qbit, QFxp): + if isinstance(serialized_qbit, QFxp): assert data.num_frac == original_qbit.num_frac assert data.signed == original_qbit.signed @@ -49,7 +49,7 @@ def test_basic_data_types(num_qbits:int): (sympy.Symbol("a") * sympy.Symbol("b"), 10), (sympy.Symbol("a"), sympy.Symbol("b")) ]) -def test_bounded_q_u_int(num_qbits: int, iteration_length): +def test_bounded_quint(num_qbits: int, iteration_length): round_trip(BoundedQUInt(num_qbits, iteration_length)) @pytest.mark.parametrize("num_qbits, num_frac, signed", [ From c8cf49ae3b6259ea718164f60024a93da2240935 Mon Sep 17 00:00:00 2001 From: Arren Bustamante Date: Tue, 20 Feb 2024 23:23:39 +0000 Subject: [PATCH 06/34] Remove bitsize from QBit --- qualtran/protos/data_types.proto | 1 - 1 file changed, 1 deletion(-) diff --git a/qualtran/protos/data_types.proto b/qualtran/protos/data_types.proto index c4f2c7aad..7f35a7562 100644 --- a/qualtran/protos/data_types.proto +++ b/qualtran/protos/data_types.proto @@ -17,7 +17,6 @@ package qualtran; import "qualtran/protos/args.proto"; message QBit { - optional int64 bitsize = 1; } message QAny { From aa75cd5c3cde50d64b0c7ef4c8e632ff91c0366b Mon Sep 17 00:00:00 2001 From: Arren Bustamante Date: Wed, 21 Feb 2024 00:21:53 +0000 Subject: [PATCH 07/34] Fixed formatting --- Untitled.ipynb | 48 ++ mod_exp_bloq.json | 76 ++++ mod_exp_cbloq.json | 511 ++++++++++++++++++++++ musical_score_example.json | 263 +++++++++++ qualtran/serialization/data_types.py | 56 +-- qualtran/serialization/data_types_test.py | 54 ++- 6 files changed, 958 insertions(+), 50 deletions(-) create mode 100644 Untitled.ipynb create mode 100644 mod_exp_bloq.json create mode 100644 mod_exp_cbloq.json create mode 100644 musical_score_example.json diff --git a/Untitled.ipynb b/Untitled.ipynb new file mode 100644 index 000000000..0f13bb35b --- /dev/null +++ b/Untitled.ipynb @@ -0,0 +1,48 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "5e9df935", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Register(name='control', bitsize=1, shape=(), side=)" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from qualtran import Register\n", + "\n", + "Register('control', bitsize=1)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/mod_exp_bloq.json b/mod_exp_bloq.json new file mode 100644 index 000000000..e9cc5871b --- /dev/null +++ b/mod_exp_bloq.json @@ -0,0 +1,76 @@ +{ + "max_x": 1, + "max_y": 1, + "soqs": [ + { + "symb_cls": "Text", + "symb_attributes": { + "text": "exponent" + }, + "y": 0, + "seq_x": -1, + "topo_gen": 0, + "ident": "dang,exponent,l,()" + }, + { + "symb_cls": "TextBox", + "symb_attributes": { + "text": "exponent" + }, + "y": 0, + "seq_x": 0, + "topo_gen": 1, + "ident": "0,exponent,Side.THRU,()" + }, + { + "symb_cls": "LarrowTextBox", + "symb_attributes": { + "text": "x" + }, + "y": 1, + "seq_x": 0, + "topo_gen": 1, + "ident": "0,x,Side.RIGHT,()" + }, + { + "symb_cls": "Text", + "symb_attributes": { + "text": "exponent" + }, + "y": 0, + "seq_x": 1, + "topo_gen": 2, + "ident": "dang,exponent,r,()" + }, + { + "symb_cls": "Text", + "symb_attributes": { + "text": "x" + }, + "y": 1, + "seq_x": 1, + "topo_gen": 2, + "ident": "dang,x,r,()" + } + ], + "hlines": [ + { + "y": 0, + "seq_x_start": -1, + "seq_x_end": 1 + }, + { + "y": 1, + "seq_x_start": 0, + "seq_x_end": 1 + } + ], + "vlines": [ + { + "x": 0, + "top_y": 1, + "bottom_y": 0, + "label": "3^e % 15" + } + ] +} \ No newline at end of file diff --git a/mod_exp_cbloq.json b/mod_exp_cbloq.json new file mode 100644 index 000000000..83a76c940 --- /dev/null +++ b/mod_exp_cbloq.json @@ -0,0 +1,511 @@ +{ + "max_x": 11, + "max_y": 9, + "soqs": [ + { + "symb_cls": "Text", + "symb_attributes": { + "text": "exponent" + }, + "y": 0, + "seq_x": -1, + "topo_gen": 0, + "ident": "dang,exponent,l,()" + }, + { + "symb_cls": "LarrowTextBox", + "symb_attributes": { + "text": "1" + }, + "y": 1, + "seq_x": 0, + "topo_gen": 0, + "ident": "0,val,Side.RIGHT,()" + }, + { + "symb_cls": "RarrowTextBox", + "symb_attributes": { + "text": " " + }, + "y": 0, + "seq_x": 1, + "topo_gen": 1, + "ident": "1,reg,Side.LEFT,()" + }, + { + "symb_cls": "LarrowTextBox", + "symb_attributes": { + "text": "[7]" + }, + "y": 9, + "seq_x": 1, + "topo_gen": 1, + "ident": "1,reg,Side.RIGHT,(7,)" + }, + { + "symb_cls": "LarrowTextBox", + "symb_attributes": { + "text": "[6]" + }, + "y": 8, + "seq_x": 1, + "topo_gen": 1, + "ident": "1,reg,Side.RIGHT,(6,)" + }, + { + "symb_cls": "LarrowTextBox", + "symb_attributes": { + "text": "[5]" + }, + "y": 7, + "seq_x": 1, + "topo_gen": 1, + "ident": "1,reg,Side.RIGHT,(5,)" + }, + { + "symb_cls": "LarrowTextBox", + "symb_attributes": { + "text": "[4]" + }, + "y": 6, + "seq_x": 1, + "topo_gen": 1, + "ident": "1,reg,Side.RIGHT,(4,)" + }, + { + "symb_cls": "LarrowTextBox", + "symb_attributes": { + "text": "[3]" + }, + "y": 5, + "seq_x": 1, + "topo_gen": 1, + "ident": "1,reg,Side.RIGHT,(3,)" + }, + { + "symb_cls": "LarrowTextBox", + "symb_attributes": { + "text": "[2]" + }, + "y": 4, + "seq_x": 1, + "topo_gen": 1, + "ident": "1,reg,Side.RIGHT,(2,)" + }, + { + "symb_cls": "LarrowTextBox", + "symb_attributes": { + "text": "[1]" + }, + "y": 3, + "seq_x": 1, + "topo_gen": 1, + "ident": "1,reg,Side.RIGHT,(1,)" + }, + { + "symb_cls": "LarrowTextBox", + "symb_attributes": { + "text": "[0]" + }, + "y": 2, + "seq_x": 1, + "topo_gen": 1, + "ident": "1,reg,Side.RIGHT,(0,)" + }, + { + "symb_cls": "Circle", + "symb_attributes": { + "filled": true + }, + "y": 9, + "seq_x": 2, + "topo_gen": 2, + "ident": "2,ctrl,Side.THRU,()" + }, + { + "symb_cls": "TextBox", + "symb_attributes": { + "text": "*=3" + }, + "y": 1, + "seq_x": 2, + "topo_gen": 2, + "ident": "2,x,Side.THRU,()" + }, + { + "symb_cls": "Circle", + "symb_attributes": { + "filled": true + }, + "y": 8, + "seq_x": 3, + "topo_gen": 3, + "ident": "3,ctrl,Side.THRU,()" + }, + { + "symb_cls": "TextBox", + "symb_attributes": { + "text": "*=9" + }, + "y": 1, + "seq_x": 3, + "topo_gen": 3, + "ident": "3,x,Side.THRU,()" + }, + { + "symb_cls": "Circle", + "symb_attributes": { + "filled": true + }, + "y": 7, + "seq_x": 4, + "topo_gen": 4, + "ident": "4,ctrl,Side.THRU,()" + }, + { + "symb_cls": "TextBox", + "symb_attributes": { + "text": "*=6" + }, + "y": 1, + "seq_x": 4, + "topo_gen": 4, + "ident": "4,x,Side.THRU,()" + }, + { + "symb_cls": "Circle", + "symb_attributes": { + "filled": true + }, + "y": 6, + "seq_x": 5, + "topo_gen": 5, + "ident": "5,ctrl,Side.THRU,()" + }, + { + "symb_cls": "TextBox", + "symb_attributes": { + "text": "*=6" + }, + "y": 1, + "seq_x": 5, + "topo_gen": 5, + "ident": "5,x,Side.THRU,()" + }, + { + "symb_cls": "Circle", + "symb_attributes": { + "filled": true + }, + "y": 5, + "seq_x": 6, + "topo_gen": 6, + "ident": "6,ctrl,Side.THRU,()" + }, + { + "symb_cls": "TextBox", + "symb_attributes": { + "text": "*=6" + }, + "y": 1, + "seq_x": 6, + "topo_gen": 6, + "ident": "6,x,Side.THRU,()" + }, + { + "symb_cls": "Circle", + "symb_attributes": { + "filled": true + }, + "y": 4, + "seq_x": 7, + "topo_gen": 7, + "ident": "7,ctrl,Side.THRU,()" + }, + { + "symb_cls": "TextBox", + "symb_attributes": { + "text": "*=6" + }, + "y": 1, + "seq_x": 7, + "topo_gen": 7, + "ident": "7,x,Side.THRU,()" + }, + { + "symb_cls": "Circle", + "symb_attributes": { + "filled": true + }, + "y": 3, + "seq_x": 8, + "topo_gen": 8, + "ident": "8,ctrl,Side.THRU,()" + }, + { + "symb_cls": "TextBox", + "symb_attributes": { + "text": "*=6" + }, + "y": 1, + "seq_x": 8, + "topo_gen": 8, + "ident": "8,x,Side.THRU,()" + }, + { + "symb_cls": "Circle", + "symb_attributes": { + "filled": true + }, + "y": 2, + "seq_x": 9, + "topo_gen": 9, + "ident": "9,ctrl,Side.THRU,()" + }, + { + "symb_cls": "TextBox", + "symb_attributes": { + "text": "*=6" + }, + "y": 1, + "seq_x": 9, + "topo_gen": 9, + "ident": "9,x,Side.THRU,()" + }, + { + "symb_cls": "RarrowTextBox", + "symb_attributes": { + "text": "[0]" + }, + "y": 2, + "seq_x": 10, + "topo_gen": 10, + "ident": "10,reg,Side.LEFT,(0,)" + }, + { + "symb_cls": "RarrowTextBox", + "symb_attributes": { + "text": "[1]" + }, + "y": 3, + "seq_x": 10, + "topo_gen": 10, + "ident": "10,reg,Side.LEFT,(1,)" + }, + { + "symb_cls": "RarrowTextBox", + "symb_attributes": { + "text": "[2]" + }, + "y": 4, + "seq_x": 10, + "topo_gen": 10, + "ident": "10,reg,Side.LEFT,(2,)" + }, + { + "symb_cls": "RarrowTextBox", + "symb_attributes": { + "text": "[3]" + }, + "y": 5, + "seq_x": 10, + "topo_gen": 10, + "ident": "10,reg,Side.LEFT,(3,)" + }, + { + "symb_cls": "RarrowTextBox", + "symb_attributes": { + "text": "[4]" + }, + "y": 6, + "seq_x": 10, + "topo_gen": 10, + "ident": "10,reg,Side.LEFT,(4,)" + }, + { + "symb_cls": "RarrowTextBox", + "symb_attributes": { + "text": "[5]" + }, + "y": 7, + "seq_x": 10, + "topo_gen": 10, + "ident": "10,reg,Side.LEFT,(5,)" + }, + { + "symb_cls": "RarrowTextBox", + "symb_attributes": { + "text": "[6]" + }, + "y": 8, + "seq_x": 10, + "topo_gen": 10, + "ident": "10,reg,Side.LEFT,(6,)" + }, + { + "symb_cls": "RarrowTextBox", + "symb_attributes": { + "text": "[7]" + }, + "y": 9, + "seq_x": 10, + "topo_gen": 10, + "ident": "10,reg,Side.LEFT,(7,)" + }, + { + "symb_cls": "LarrowTextBox", + "symb_attributes": { + "text": " " + }, + "y": 0, + "seq_x": 10, + "topo_gen": 10, + "ident": "10,reg,Side.RIGHT,()" + }, + { + "symb_cls": "Text", + "symb_attributes": { + "text": "exponent" + }, + "y": 0, + "seq_x": 11, + "topo_gen": 11, + "ident": "dang,exponent,r,()" + }, + { + "symb_cls": "Text", + "symb_attributes": { + "text": "x" + }, + "y": 1, + "seq_x": 11, + "topo_gen": 11, + "ident": "dang,x,r,()" + } + ], + "hlines": [ + { + "y": 0, + "seq_x_start": -1, + "seq_x_end": 1 + }, + { + "y": 0, + "seq_x_start": 10, + "seq_x_end": 11 + }, + { + "y": 1, + "seq_x_start": 0, + "seq_x_end": 11 + }, + { + "y": 2, + "seq_x_start": 1, + "seq_x_end": 10 + }, + { + "y": 3, + "seq_x_start": 1, + "seq_x_end": 10 + }, + { + "y": 4, + "seq_x_start": 1, + "seq_x_end": 10 + }, + { + "y": 5, + "seq_x_start": 1, + "seq_x_end": 10 + }, + { + "y": 6, + "seq_x_start": 1, + "seq_x_end": 10 + }, + { + "y": 7, + "seq_x_start": 1, + "seq_x_end": 10 + }, + { + "y": 8, + "seq_x_start": 1, + "seq_x_end": 10 + }, + { + "y": 9, + "seq_x_start": 1, + "seq_x_end": 10 + } + ], + "vlines": [ + { + "x": 0, + "top_y": 1, + "bottom_y": 1, + "label": "1" + }, + { + "x": 1, + "top_y": 9, + "bottom_y": 0, + "label": "Split" + }, + { + "x": 2, + "top_y": 9, + "bottom_y": 1, + "label": "x *= 3 % 15" + }, + { + "x": 3, + "top_y": 8, + "bottom_y": 1, + "label": "x *= 9 % 15" + }, + { + "x": 4, + "top_y": 7, + "bottom_y": 1, + "label": "x *= 6 % 15" + }, + { + "x": 5, + "top_y": 6, + "bottom_y": 1, + "label": "x *= 6 % 15" + }, + { + "x": 6, + "top_y": 5, + "bottom_y": 1, + "label": "x *= 6 % 15" + }, + { + "x": 7, + "top_y": 4, + "bottom_y": 1, + "label": "x *= 6 % 15" + }, + { + "x": 8, + "top_y": 3, + "bottom_y": 1, + "label": "x *= 6 % 15" + }, + { + "x": 9, + "top_y": 2, + "bottom_y": 1, + "label": "x *= 6 % 15" + }, + { + "x": 10, + "top_y": 9, + "bottom_y": 0, + "label": "Join" + } + ] +} \ No newline at end of file diff --git a/musical_score_example.json b/musical_score_example.json new file mode 100644 index 000000000..b5ed08cad --- /dev/null +++ b/musical_score_example.json @@ -0,0 +1,263 @@ +{ + "max_x": 3, + "max_y": 6, + "soqs": [ + { + "symb_cls": "Text", + "symb_attributes": { + "text": "ctrl[0]" + }, + "y": 0, + "seq_x": -1, + "topo_gen": 0, + "ident": "dang,ctrl,l,(0,)" + }, + { + "symb_cls": "Text", + "symb_attributes": { + "text": "ctrl[1]" + }, + "y": 1, + "seq_x": -1, + "topo_gen": 0, + "ident": "dang,ctrl,l,(1,)" + }, + { + "symb_cls": "Text", + "symb_attributes": { + "text": "ctrl[2]" + }, + "y": 2, + "seq_x": -1, + "topo_gen": 0, + "ident": "dang,ctrl,l,(2,)" + }, + { + "symb_cls": "Text", + "symb_attributes": { + "text": "ctrl[3]" + }, + "y": 3, + "seq_x": -1, + "topo_gen": 0, + "ident": "dang,ctrl,l,(3,)" + }, + { + "symb_cls": "Circle", + "symb_attributes": { + "filled": true + }, + "y": 0, + "seq_x": 0, + "topo_gen": 1, + "ident": "0,ctrl,Side.THRU,(0,)" + }, + { + "symb_cls": "Circle", + "symb_attributes": { + "filled": true + }, + "y": 1, + "seq_x": 0, + "topo_gen": 1, + "ident": "0,ctrl,Side.THRU,(1,)" + }, + { + "symb_cls": "LarrowTextBox", + "symb_attributes": { + "text": "\u2227" + }, + "y": 4, + "seq_x": 0, + "topo_gen": 1, + "ident": "0,target,Side.RIGHT,()" + }, + { + "symb_cls": "Circle", + "symb_attributes": { + "filled": true + }, + "y": 4, + "seq_x": 1, + "topo_gen": 2, + "ident": "1,ctrl,Side.THRU,(0,)" + }, + { + "symb_cls": "Circle", + "symb_attributes": { + "filled": false + }, + "y": 2, + "seq_x": 1, + "topo_gen": 2, + "ident": "1,ctrl,Side.THRU,(1,)" + }, + { + "symb_cls": "LarrowTextBox", + "symb_attributes": { + "text": "\u2227" + }, + "y": 5, + "seq_x": 1, + "topo_gen": 2, + "ident": "1,target,Side.RIGHT,()" + }, + { + "symb_cls": "Circle", + "symb_attributes": { + "filled": true + }, + "y": 5, + "seq_x": 2, + "topo_gen": 3, + "ident": "2,ctrl,Side.THRU,(0,)" + }, + { + "symb_cls": "Circle", + "symb_attributes": { + "filled": true + }, + "y": 3, + "seq_x": 2, + "topo_gen": 3, + "ident": "2,ctrl,Side.THRU,(1,)" + }, + { + "symb_cls": "LarrowTextBox", + "symb_attributes": { + "text": "\u2227" + }, + "y": 6, + "seq_x": 2, + "topo_gen": 3, + "ident": "2,target,Side.RIGHT,()" + }, + { + "symb_cls": "Text", + "symb_attributes": { + "text": "ctrl[0]" + }, + "y": 0, + "seq_x": 3, + "topo_gen": 4, + "ident": "dang,ctrl,r,(0,)" + }, + { + "symb_cls": "Text", + "symb_attributes": { + "text": "ctrl[1]" + }, + "y": 1, + "seq_x": 3, + "topo_gen": 4, + "ident": "dang,ctrl,r,(1,)" + }, + { + "symb_cls": "Text", + "symb_attributes": { + "text": "ctrl[2]" + }, + "y": 2, + "seq_x": 3, + "topo_gen": 4, + "ident": "dang,ctrl,r,(2,)" + }, + { + "symb_cls": "Text", + "symb_attributes": { + "text": "junk[0]" + }, + "y": 4, + "seq_x": 3, + "topo_gen": 4, + "ident": "dang,junk,r,(0,)" + }, + { + "symb_cls": "Text", + "symb_attributes": { + "text": "ctrl[3]" + }, + "y": 3, + "seq_x": 3, + "topo_gen": 4, + "ident": "dang,ctrl,r,(3,)" + }, + { + "symb_cls": "Text", + "symb_attributes": { + "text": "junk[1]" + }, + "y": 5, + "seq_x": 3, + "topo_gen": 4, + "ident": "dang,junk,r,(1,)" + }, + { + "symb_cls": "Text", + "symb_attributes": { + "text": "target" + }, + "y": 6, + "seq_x": 3, + "topo_gen": 4, + "ident": "dang,target,r,()" + } + ], + "hlines": [ + { + "y": 0, + "seq_x_start": -1, + "seq_x_end": 3 + }, + { + "y": 1, + "seq_x_start": -1, + "seq_x_end": 3 + }, + { + "y": 2, + "seq_x_start": -1, + "seq_x_end": 3 + }, + { + "y": 3, + "seq_x_start": -1, + "seq_x_end": 3 + }, + { + "y": 4, + "seq_x_start": 0, + "seq_x_end": 3 + }, + { + "y": 5, + "seq_x_start": 1, + "seq_x_end": 3 + }, + { + "y": 6, + "seq_x_start": 2, + "seq_x_end": 3 + } + ], + "vlines": [ + { + "x": 0, + "top_y": 4, + "bottom_y": 0, + "label": "And" + }, + { + "x": 1, + "top_y": 5, + "bottom_y": 2, + "label": "And" + }, + { + "x": 2, + "top_y": 6, + "bottom_y": 3, + "label": "And" + } + ] +} \ No newline at end of file diff --git a/qualtran/serialization/data_types.py b/qualtran/serialization/data_types.py index a9a0efc9d..c72264197 100644 --- a/qualtran/serialization/data_types.py +++ b/qualtran/serialization/data_types.py @@ -13,20 +13,25 @@ # limitations under the License. from typing import Union -from qualtran import QDType, QBit, QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt, QFxp +from qualtran import BoundedQUInt, QAny, QBit, QDType, QFxp, QInt, QIntOnesComp, QUInt from qualtran.protos import data_types_pb2 -from qualtran.serialization.args import int_or_sympy_from_proto,int_or_sympy_to_proto +from qualtran.serialization.args import int_or_sympy_from_proto, int_or_sympy_to_proto +SerializedDataTypes = Union[ + data_types_pb2.QBit, + data_types_pb2.QAny, + data_types_pb2.QInt, + data_types_pb2.QIntOnesComp, + data_types_pb2.QUInt, + data_types_pb2.BoundedQUInt, + data_types_pb2.QFxp, +] -SerializedDataTypes = Union[data_types_pb2.QBit, data_types_pb2.QAny, - data_types_pb2.QInt, data_types_pb2.QIntOnesComp, - data_types_pb2.QUInt, data_types_pb2.BoundedQUInt, - data_types_pb2.QFxp] def data_type_to_proto(data: QDType) -> SerializedDataTypes: if isinstance(data, QBit): return data_types_pb2.QBit() - + bitsize = int_or_sympy_to_proto(data.bitsize) if isinstance(data, QAny): return data_types_pb2.QAny(bitsize=bitsize) @@ -38,23 +43,23 @@ def data_type_to_proto(data: QDType) -> SerializedDataTypes: return data_types_pb2.QUInt(bitsize=bitsize) elif isinstance(data, BoundedQUInt): iteration_length = int_or_sympy_to_proto(data.iteration_length) - return data_types_pb2.BoundedQUInt(bitsize=bitsize, - iteration_length=iteration_length) + return data_types_pb2.BoundedQUInt(bitsize=bitsize, iteration_length=iteration_length) elif isinstance(data, QFxp): num_frac = int_or_sympy_to_proto(data.num_frac) - return data_types_pb2.QFxp(bitsize=bitsize, - num_frac=num_frac, - signed=data.signed) + return data_types_pb2.QFxp(bitsize=bitsize, num_frac=num_frac, signed=data.signed) else: - raise TypeError(f"Data type {type(serialized)} is not recognized."\ - " It must be of one of the following subtypes: QBit, "\ - "QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt, "\ - "QFixedPoint") + raise TypeError( + f"Data type {type(serialized)} is not recognized." + " It must be of one of the following subtypes: QBit, " + "QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt, " + "QFixedPoint" + ) + def data_type_from_proto(serialized: SerializedDataTypes) -> QDType: if isinstance(serialized, data_types_pb2.QBit): return QBit() - + bitsize = int_or_sympy_from_proto(serialized.bitsize) if isinstance(serialized, data_types_pb2.QAny): return QAny(bitsize=bitsize) @@ -70,15 +75,14 @@ def data_type_from_proto(serialized: SerializedDataTypes) -> QDType: return QUInt(bitsize=bitsize) elif isinstance(serialized, data_types_pb2.BoundedQUInt): iteration_length = int_or_sympy_from_proto(serialized.iteration_length) - return BoundedQUInt(bitsize=bitsize, - iteration_length=iteration_length) + return BoundedQUInt(bitsize=bitsize, iteration_length=iteration_length) elif isinstance(serialized, data_types_pb2.QFxp): num_frac = int_or_sympy_from_proto(serialized.num_frac) - return QFxp(bitsize=bitsize, num_frac=num_frac, - signed=serialized.signed) + return QFxp(bitsize=bitsize, num_frac=num_frac, signed=serialized.signed) else: - raise TypeError(f"Data type {type(serialized)} is not recognized."\ - " It must be of one of the following subtypes: QBit, "\ - "QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt, "\ - "QFixedPoint") - \ No newline at end of file + raise TypeError( + f"Data type {type(serialized)} is not recognized." + " It must be of one of the following subtypes: QBit, " + "QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt, " + "QFixedPoint" + ) diff --git a/qualtran/serialization/data_types_test.py b/qualtran/serialization/data_types_test.py index e9481730d..4e374752a 100644 --- a/qualtran/serialization/data_types_test.py +++ b/qualtran/serialization/data_types_test.py @@ -12,50 +12,56 @@ # See the License for the specific language governing permissions and # limitations under the License. +from typing import Union + import pytest import sympy -from typing import Union + +from qualtran import BoundedQUInt, QAny, QBit, QDType, QFxp, QInt, QIntOnesComp, QUInt from qualtran.serialization.data_types import data_type_from_proto, data_type_to_proto -from qualtran import QDType, QBit, QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt, QFxp + def round_trip(data: QDType): serialized_qbit = data_type_to_proto(data) original_qbit = data_type_from_proto(serialized_qbit) - + assert data.num_qubits == original_qbit.num_qubits - if isinstance(serialized_qbit, BoundedQUInt): + if isinstance(serialized_qbit, BoundedQUInt): assert data.iteration_length == original_qbit.iteration_length if isinstance(serialized_qbit, QFxp): assert data.num_frac == original_qbit.num_frac assert data.signed == original_qbit.signed + def test_qbit(): round_trip(QBit()) -@pytest.mark.parametrize("num_qbits", - [10, 1000, sympy.Symbol("a") * sympy.Symbol("b")]) -def test_qint_succeeds(num_qbits: Union[int, sympy.Expr]): - round_trip(QInt(num_qbits)) -@pytest.mark.parametrize("num_qbits", - [10, 1000, sympy.Symbol("a") * sympy.Symbol("b")]) -def test_basic_data_types(num_qbits:int): +@pytest.mark.parametrize("num_qbits", [10, 1000, sympy.Symbol("a") * sympy.Symbol("b")]) +def test_basic_data_types(num_qbits: Union[int, sympy.Expr]): + round_trip(QInt(num_qbits)) round_trip(QAny(num_qbits)) round_trip(QIntOnesComp(num_qbits)) round_trip(QUInt(num_qbits)) - -@pytest.mark.parametrize("num_qbits, iteration_length",[ - (10, 1), (5, 10), (1000, 1000), - (sympy.Symbol("a") * sympy.Symbol("b"), 10), - (sympy.Symbol("a"), sympy.Symbol("b")) - ]) + + +@pytest.mark.parametrize( + "num_qbits, iteration_length", + [ + (10, 1), + (5, 10), + (1000, 1000), + (sympy.Symbol("a") * sympy.Symbol("b"), 10), + (sympy.Symbol("a"), sympy.Symbol("b")), + ], +) def test_bounded_quint(num_qbits: int, iteration_length): round_trip(BoundedQUInt(num_qbits, iteration_length)) - -@pytest.mark.parametrize("num_qbits, num_frac, signed", [ - (10, 5, True), (10, 5, False), (5,5,False), - (sympy.Symbol("a"), sympy.Symbol("a"), False) - ]) -def test_qfxp(num_qbits:int, num_frac:int, signed:bool): + + +@pytest.mark.parametrize( + "num_qbits, num_frac, signed", + [(10, 5, True), (10, 5, False), (5, 5, False), (sympy.Symbol("a"), sympy.Symbol("a"), False)], +) +def test_qfxp(num_qbits: int, num_frac: int, signed: bool): round_trip(QFxp(num_qbits, num_frac, signed)) - From f1d36cab3ba0d64145a139b7f4b54ac540d97aab Mon Sep 17 00:00:00 2001 From: Arren Bustamante Date: Wed, 21 Feb 2024 00:35:12 +0000 Subject: [PATCH 08/34] Remove uncessesary files --- Untitled.ipynb | 48 ---- mod_exp_bloq.json | 76 ------ mod_exp_cbloq.json | 511 ------------------------------------- musical_score_example.json | 263 ------------------- 4 files changed, 898 deletions(-) delete mode 100644 Untitled.ipynb delete mode 100644 mod_exp_bloq.json delete mode 100644 mod_exp_cbloq.json delete mode 100644 musical_score_example.json diff --git a/Untitled.ipynb b/Untitled.ipynb deleted file mode 100644 index 0f13bb35b..000000000 --- a/Untitled.ipynb +++ /dev/null @@ -1,48 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "5e9df935", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Register(name='control', bitsize=1, shape=(), side=)" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from qualtran import Register\n", - "\n", - "Register('control', bitsize=1)" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/mod_exp_bloq.json b/mod_exp_bloq.json deleted file mode 100644 index e9cc5871b..000000000 --- a/mod_exp_bloq.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "max_x": 1, - "max_y": 1, - "soqs": [ - { - "symb_cls": "Text", - "symb_attributes": { - "text": "exponent" - }, - "y": 0, - "seq_x": -1, - "topo_gen": 0, - "ident": "dang,exponent,l,()" - }, - { - "symb_cls": "TextBox", - "symb_attributes": { - "text": "exponent" - }, - "y": 0, - "seq_x": 0, - "topo_gen": 1, - "ident": "0,exponent,Side.THRU,()" - }, - { - "symb_cls": "LarrowTextBox", - "symb_attributes": { - "text": "x" - }, - "y": 1, - "seq_x": 0, - "topo_gen": 1, - "ident": "0,x,Side.RIGHT,()" - }, - { - "symb_cls": "Text", - "symb_attributes": { - "text": "exponent" - }, - "y": 0, - "seq_x": 1, - "topo_gen": 2, - "ident": "dang,exponent,r,()" - }, - { - "symb_cls": "Text", - "symb_attributes": { - "text": "x" - }, - "y": 1, - "seq_x": 1, - "topo_gen": 2, - "ident": "dang,x,r,()" - } - ], - "hlines": [ - { - "y": 0, - "seq_x_start": -1, - "seq_x_end": 1 - }, - { - "y": 1, - "seq_x_start": 0, - "seq_x_end": 1 - } - ], - "vlines": [ - { - "x": 0, - "top_y": 1, - "bottom_y": 0, - "label": "3^e % 15" - } - ] -} \ No newline at end of file diff --git a/mod_exp_cbloq.json b/mod_exp_cbloq.json deleted file mode 100644 index 83a76c940..000000000 --- a/mod_exp_cbloq.json +++ /dev/null @@ -1,511 +0,0 @@ -{ - "max_x": 11, - "max_y": 9, - "soqs": [ - { - "symb_cls": "Text", - "symb_attributes": { - "text": "exponent" - }, - "y": 0, - "seq_x": -1, - "topo_gen": 0, - "ident": "dang,exponent,l,()" - }, - { - "symb_cls": "LarrowTextBox", - "symb_attributes": { - "text": "1" - }, - "y": 1, - "seq_x": 0, - "topo_gen": 0, - "ident": "0,val,Side.RIGHT,()" - }, - { - "symb_cls": "RarrowTextBox", - "symb_attributes": { - "text": " " - }, - "y": 0, - "seq_x": 1, - "topo_gen": 1, - "ident": "1,reg,Side.LEFT,()" - }, - { - "symb_cls": "LarrowTextBox", - "symb_attributes": { - "text": "[7]" - }, - "y": 9, - "seq_x": 1, - "topo_gen": 1, - "ident": "1,reg,Side.RIGHT,(7,)" - }, - { - "symb_cls": "LarrowTextBox", - "symb_attributes": { - "text": "[6]" - }, - "y": 8, - "seq_x": 1, - "topo_gen": 1, - "ident": "1,reg,Side.RIGHT,(6,)" - }, - { - "symb_cls": "LarrowTextBox", - "symb_attributes": { - "text": "[5]" - }, - "y": 7, - "seq_x": 1, - "topo_gen": 1, - "ident": "1,reg,Side.RIGHT,(5,)" - }, - { - "symb_cls": "LarrowTextBox", - "symb_attributes": { - "text": "[4]" - }, - "y": 6, - "seq_x": 1, - "topo_gen": 1, - "ident": "1,reg,Side.RIGHT,(4,)" - }, - { - "symb_cls": "LarrowTextBox", - "symb_attributes": { - "text": "[3]" - }, - "y": 5, - "seq_x": 1, - "topo_gen": 1, - "ident": "1,reg,Side.RIGHT,(3,)" - }, - { - "symb_cls": "LarrowTextBox", - "symb_attributes": { - "text": "[2]" - }, - "y": 4, - "seq_x": 1, - "topo_gen": 1, - "ident": "1,reg,Side.RIGHT,(2,)" - }, - { - "symb_cls": "LarrowTextBox", - "symb_attributes": { - "text": "[1]" - }, - "y": 3, - "seq_x": 1, - "topo_gen": 1, - "ident": "1,reg,Side.RIGHT,(1,)" - }, - { - "symb_cls": "LarrowTextBox", - "symb_attributes": { - "text": "[0]" - }, - "y": 2, - "seq_x": 1, - "topo_gen": 1, - "ident": "1,reg,Side.RIGHT,(0,)" - }, - { - "symb_cls": "Circle", - "symb_attributes": { - "filled": true - }, - "y": 9, - "seq_x": 2, - "topo_gen": 2, - "ident": "2,ctrl,Side.THRU,()" - }, - { - "symb_cls": "TextBox", - "symb_attributes": { - "text": "*=3" - }, - "y": 1, - "seq_x": 2, - "topo_gen": 2, - "ident": "2,x,Side.THRU,()" - }, - { - "symb_cls": "Circle", - "symb_attributes": { - "filled": true - }, - "y": 8, - "seq_x": 3, - "topo_gen": 3, - "ident": "3,ctrl,Side.THRU,()" - }, - { - "symb_cls": "TextBox", - "symb_attributes": { - "text": "*=9" - }, - "y": 1, - "seq_x": 3, - "topo_gen": 3, - "ident": "3,x,Side.THRU,()" - }, - { - "symb_cls": "Circle", - "symb_attributes": { - "filled": true - }, - "y": 7, - "seq_x": 4, - "topo_gen": 4, - "ident": "4,ctrl,Side.THRU,()" - }, - { - "symb_cls": "TextBox", - "symb_attributes": { - "text": "*=6" - }, - "y": 1, - "seq_x": 4, - "topo_gen": 4, - "ident": "4,x,Side.THRU,()" - }, - { - "symb_cls": "Circle", - "symb_attributes": { - "filled": true - }, - "y": 6, - "seq_x": 5, - "topo_gen": 5, - "ident": "5,ctrl,Side.THRU,()" - }, - { - "symb_cls": "TextBox", - "symb_attributes": { - "text": "*=6" - }, - "y": 1, - "seq_x": 5, - "topo_gen": 5, - "ident": "5,x,Side.THRU,()" - }, - { - "symb_cls": "Circle", - "symb_attributes": { - "filled": true - }, - "y": 5, - "seq_x": 6, - "topo_gen": 6, - "ident": "6,ctrl,Side.THRU,()" - }, - { - "symb_cls": "TextBox", - "symb_attributes": { - "text": "*=6" - }, - "y": 1, - "seq_x": 6, - "topo_gen": 6, - "ident": "6,x,Side.THRU,()" - }, - { - "symb_cls": "Circle", - "symb_attributes": { - "filled": true - }, - "y": 4, - "seq_x": 7, - "topo_gen": 7, - "ident": "7,ctrl,Side.THRU,()" - }, - { - "symb_cls": "TextBox", - "symb_attributes": { - "text": "*=6" - }, - "y": 1, - "seq_x": 7, - "topo_gen": 7, - "ident": "7,x,Side.THRU,()" - }, - { - "symb_cls": "Circle", - "symb_attributes": { - "filled": true - }, - "y": 3, - "seq_x": 8, - "topo_gen": 8, - "ident": "8,ctrl,Side.THRU,()" - }, - { - "symb_cls": "TextBox", - "symb_attributes": { - "text": "*=6" - }, - "y": 1, - "seq_x": 8, - "topo_gen": 8, - "ident": "8,x,Side.THRU,()" - }, - { - "symb_cls": "Circle", - "symb_attributes": { - "filled": true - }, - "y": 2, - "seq_x": 9, - "topo_gen": 9, - "ident": "9,ctrl,Side.THRU,()" - }, - { - "symb_cls": "TextBox", - "symb_attributes": { - "text": "*=6" - }, - "y": 1, - "seq_x": 9, - "topo_gen": 9, - "ident": "9,x,Side.THRU,()" - }, - { - "symb_cls": "RarrowTextBox", - "symb_attributes": { - "text": "[0]" - }, - "y": 2, - "seq_x": 10, - "topo_gen": 10, - "ident": "10,reg,Side.LEFT,(0,)" - }, - { - "symb_cls": "RarrowTextBox", - "symb_attributes": { - "text": "[1]" - }, - "y": 3, - "seq_x": 10, - "topo_gen": 10, - "ident": "10,reg,Side.LEFT,(1,)" - }, - { - "symb_cls": "RarrowTextBox", - "symb_attributes": { - "text": "[2]" - }, - "y": 4, - "seq_x": 10, - "topo_gen": 10, - "ident": "10,reg,Side.LEFT,(2,)" - }, - { - "symb_cls": "RarrowTextBox", - "symb_attributes": { - "text": "[3]" - }, - "y": 5, - "seq_x": 10, - "topo_gen": 10, - "ident": "10,reg,Side.LEFT,(3,)" - }, - { - "symb_cls": "RarrowTextBox", - "symb_attributes": { - "text": "[4]" - }, - "y": 6, - "seq_x": 10, - "topo_gen": 10, - "ident": "10,reg,Side.LEFT,(4,)" - }, - { - "symb_cls": "RarrowTextBox", - "symb_attributes": { - "text": "[5]" - }, - "y": 7, - "seq_x": 10, - "topo_gen": 10, - "ident": "10,reg,Side.LEFT,(5,)" - }, - { - "symb_cls": "RarrowTextBox", - "symb_attributes": { - "text": "[6]" - }, - "y": 8, - "seq_x": 10, - "topo_gen": 10, - "ident": "10,reg,Side.LEFT,(6,)" - }, - { - "symb_cls": "RarrowTextBox", - "symb_attributes": { - "text": "[7]" - }, - "y": 9, - "seq_x": 10, - "topo_gen": 10, - "ident": "10,reg,Side.LEFT,(7,)" - }, - { - "symb_cls": "LarrowTextBox", - "symb_attributes": { - "text": " " - }, - "y": 0, - "seq_x": 10, - "topo_gen": 10, - "ident": "10,reg,Side.RIGHT,()" - }, - { - "symb_cls": "Text", - "symb_attributes": { - "text": "exponent" - }, - "y": 0, - "seq_x": 11, - "topo_gen": 11, - "ident": "dang,exponent,r,()" - }, - { - "symb_cls": "Text", - "symb_attributes": { - "text": "x" - }, - "y": 1, - "seq_x": 11, - "topo_gen": 11, - "ident": "dang,x,r,()" - } - ], - "hlines": [ - { - "y": 0, - "seq_x_start": -1, - "seq_x_end": 1 - }, - { - "y": 0, - "seq_x_start": 10, - "seq_x_end": 11 - }, - { - "y": 1, - "seq_x_start": 0, - "seq_x_end": 11 - }, - { - "y": 2, - "seq_x_start": 1, - "seq_x_end": 10 - }, - { - "y": 3, - "seq_x_start": 1, - "seq_x_end": 10 - }, - { - "y": 4, - "seq_x_start": 1, - "seq_x_end": 10 - }, - { - "y": 5, - "seq_x_start": 1, - "seq_x_end": 10 - }, - { - "y": 6, - "seq_x_start": 1, - "seq_x_end": 10 - }, - { - "y": 7, - "seq_x_start": 1, - "seq_x_end": 10 - }, - { - "y": 8, - "seq_x_start": 1, - "seq_x_end": 10 - }, - { - "y": 9, - "seq_x_start": 1, - "seq_x_end": 10 - } - ], - "vlines": [ - { - "x": 0, - "top_y": 1, - "bottom_y": 1, - "label": "1" - }, - { - "x": 1, - "top_y": 9, - "bottom_y": 0, - "label": "Split" - }, - { - "x": 2, - "top_y": 9, - "bottom_y": 1, - "label": "x *= 3 % 15" - }, - { - "x": 3, - "top_y": 8, - "bottom_y": 1, - "label": "x *= 9 % 15" - }, - { - "x": 4, - "top_y": 7, - "bottom_y": 1, - "label": "x *= 6 % 15" - }, - { - "x": 5, - "top_y": 6, - "bottom_y": 1, - "label": "x *= 6 % 15" - }, - { - "x": 6, - "top_y": 5, - "bottom_y": 1, - "label": "x *= 6 % 15" - }, - { - "x": 7, - "top_y": 4, - "bottom_y": 1, - "label": "x *= 6 % 15" - }, - { - "x": 8, - "top_y": 3, - "bottom_y": 1, - "label": "x *= 6 % 15" - }, - { - "x": 9, - "top_y": 2, - "bottom_y": 1, - "label": "x *= 6 % 15" - }, - { - "x": 10, - "top_y": 9, - "bottom_y": 0, - "label": "Join" - } - ] -} \ No newline at end of file diff --git a/musical_score_example.json b/musical_score_example.json deleted file mode 100644 index b5ed08cad..000000000 --- a/musical_score_example.json +++ /dev/null @@ -1,263 +0,0 @@ -{ - "max_x": 3, - "max_y": 6, - "soqs": [ - { - "symb_cls": "Text", - "symb_attributes": { - "text": "ctrl[0]" - }, - "y": 0, - "seq_x": -1, - "topo_gen": 0, - "ident": "dang,ctrl,l,(0,)" - }, - { - "symb_cls": "Text", - "symb_attributes": { - "text": "ctrl[1]" - }, - "y": 1, - "seq_x": -1, - "topo_gen": 0, - "ident": "dang,ctrl,l,(1,)" - }, - { - "symb_cls": "Text", - "symb_attributes": { - "text": "ctrl[2]" - }, - "y": 2, - "seq_x": -1, - "topo_gen": 0, - "ident": "dang,ctrl,l,(2,)" - }, - { - "symb_cls": "Text", - "symb_attributes": { - "text": "ctrl[3]" - }, - "y": 3, - "seq_x": -1, - "topo_gen": 0, - "ident": "dang,ctrl,l,(3,)" - }, - { - "symb_cls": "Circle", - "symb_attributes": { - "filled": true - }, - "y": 0, - "seq_x": 0, - "topo_gen": 1, - "ident": "0,ctrl,Side.THRU,(0,)" - }, - { - "symb_cls": "Circle", - "symb_attributes": { - "filled": true - }, - "y": 1, - "seq_x": 0, - "topo_gen": 1, - "ident": "0,ctrl,Side.THRU,(1,)" - }, - { - "symb_cls": "LarrowTextBox", - "symb_attributes": { - "text": "\u2227" - }, - "y": 4, - "seq_x": 0, - "topo_gen": 1, - "ident": "0,target,Side.RIGHT,()" - }, - { - "symb_cls": "Circle", - "symb_attributes": { - "filled": true - }, - "y": 4, - "seq_x": 1, - "topo_gen": 2, - "ident": "1,ctrl,Side.THRU,(0,)" - }, - { - "symb_cls": "Circle", - "symb_attributes": { - "filled": false - }, - "y": 2, - "seq_x": 1, - "topo_gen": 2, - "ident": "1,ctrl,Side.THRU,(1,)" - }, - { - "symb_cls": "LarrowTextBox", - "symb_attributes": { - "text": "\u2227" - }, - "y": 5, - "seq_x": 1, - "topo_gen": 2, - "ident": "1,target,Side.RIGHT,()" - }, - { - "symb_cls": "Circle", - "symb_attributes": { - "filled": true - }, - "y": 5, - "seq_x": 2, - "topo_gen": 3, - "ident": "2,ctrl,Side.THRU,(0,)" - }, - { - "symb_cls": "Circle", - "symb_attributes": { - "filled": true - }, - "y": 3, - "seq_x": 2, - "topo_gen": 3, - "ident": "2,ctrl,Side.THRU,(1,)" - }, - { - "symb_cls": "LarrowTextBox", - "symb_attributes": { - "text": "\u2227" - }, - "y": 6, - "seq_x": 2, - "topo_gen": 3, - "ident": "2,target,Side.RIGHT,()" - }, - { - "symb_cls": "Text", - "symb_attributes": { - "text": "ctrl[0]" - }, - "y": 0, - "seq_x": 3, - "topo_gen": 4, - "ident": "dang,ctrl,r,(0,)" - }, - { - "symb_cls": "Text", - "symb_attributes": { - "text": "ctrl[1]" - }, - "y": 1, - "seq_x": 3, - "topo_gen": 4, - "ident": "dang,ctrl,r,(1,)" - }, - { - "symb_cls": "Text", - "symb_attributes": { - "text": "ctrl[2]" - }, - "y": 2, - "seq_x": 3, - "topo_gen": 4, - "ident": "dang,ctrl,r,(2,)" - }, - { - "symb_cls": "Text", - "symb_attributes": { - "text": "junk[0]" - }, - "y": 4, - "seq_x": 3, - "topo_gen": 4, - "ident": "dang,junk,r,(0,)" - }, - { - "symb_cls": "Text", - "symb_attributes": { - "text": "ctrl[3]" - }, - "y": 3, - "seq_x": 3, - "topo_gen": 4, - "ident": "dang,ctrl,r,(3,)" - }, - { - "symb_cls": "Text", - "symb_attributes": { - "text": "junk[1]" - }, - "y": 5, - "seq_x": 3, - "topo_gen": 4, - "ident": "dang,junk,r,(1,)" - }, - { - "symb_cls": "Text", - "symb_attributes": { - "text": "target" - }, - "y": 6, - "seq_x": 3, - "topo_gen": 4, - "ident": "dang,target,r,()" - } - ], - "hlines": [ - { - "y": 0, - "seq_x_start": -1, - "seq_x_end": 3 - }, - { - "y": 1, - "seq_x_start": -1, - "seq_x_end": 3 - }, - { - "y": 2, - "seq_x_start": -1, - "seq_x_end": 3 - }, - { - "y": 3, - "seq_x_start": -1, - "seq_x_end": 3 - }, - { - "y": 4, - "seq_x_start": 0, - "seq_x_end": 3 - }, - { - "y": 5, - "seq_x_start": 1, - "seq_x_end": 3 - }, - { - "y": 6, - "seq_x_start": 2, - "seq_x_end": 3 - } - ], - "vlines": [ - { - "x": 0, - "top_y": 4, - "bottom_y": 0, - "label": "And" - }, - { - "x": 1, - "top_y": 5, - "bottom_y": 2, - "label": "And" - }, - { - "x": 2, - "top_y": 6, - "bottom_y": 3, - "label": "And" - } - ] -} \ No newline at end of file From ecca62a645e2210f26cbbe203e5075eadb735992 Mon Sep 17 00:00:00 2001 From: Arren Bustamante Date: Wed, 21 Feb 2024 00:46:20 +0000 Subject: [PATCH 09/34] Fix data type in formatted string in error message --- qualtran/serialization/data_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qualtran/serialization/data_types.py b/qualtran/serialization/data_types.py index c72264197..0d0760384 100644 --- a/qualtran/serialization/data_types.py +++ b/qualtran/serialization/data_types.py @@ -49,7 +49,7 @@ def data_type_to_proto(data: QDType) -> SerializedDataTypes: return data_types_pb2.QFxp(bitsize=bitsize, num_frac=num_frac, signed=data.signed) else: raise TypeError( - f"Data type {type(serialized)} is not recognized." + f"Data type {type(data)} is not recognized." " It must be of one of the following subtypes: QBit, " "QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt, " "QFixedPoint" From c99e000163b4772cbe8df443499f194ec7d1e1cd Mon Sep 17 00:00:00 2001 From: Tanuj Khattar Date: Tue, 20 Feb 2024 16:56:16 -0800 Subject: [PATCH 10/34] Update qualtran/serialization/data_types_test.py --- qualtran/serialization/data_types_test.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/qualtran/serialization/data_types_test.py b/qualtran/serialization/data_types_test.py index 4e374752a..defd3f739 100644 --- a/qualtran/serialization/data_types_test.py +++ b/qualtran/serialization/data_types_test.py @@ -25,12 +25,7 @@ def round_trip(data: QDType): serialized_qbit = data_type_to_proto(data) original_qbit = data_type_from_proto(serialized_qbit) - assert data.num_qubits == original_qbit.num_qubits - if isinstance(serialized_qbit, BoundedQUInt): - assert data.iteration_length == original_qbit.iteration_length - if isinstance(serialized_qbit, QFxp): - assert data.num_frac == original_qbit.num_frac - assert data.signed == original_qbit.signed + assert data == original_qbit def test_qbit(): From b53db7176a99270dfac47dc6b38b666d5a7b7832 Mon Sep 17 00:00:00 2001 From: local_linix Date: Mon, 1 Apr 2024 16:16:21 -0700 Subject: [PATCH 11/34] Added Sympy serialization. Sympy expressions can now be serialized through a recursive proto. --- qualtran/protos/bloq.proto | 3 +- qualtran/protos/bloq_pb2.py | 35 +++++----- qualtran/protos/bloq_pb2.pyi | 8 ++- qualtran/protos/sympy.proto | 50 ++++++++++++++ qualtran/serialization/bloq.py | 110 +++++++++++++++++++++++++++++- qualtran/serialization/scratch.py | 10 +++ 6 files changed, 193 insertions(+), 23 deletions(-) create mode 100644 qualtran/protos/sympy.proto create mode 100644 qualtran/serialization/scratch.py diff --git a/qualtran/protos/bloq.proto b/qualtran/protos/bloq.proto index 08617e2fc..1e7a4c5fe 100644 --- a/qualtran/protos/bloq.proto +++ b/qualtran/protos/bloq.proto @@ -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; @@ -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. diff --git a/qualtran/protos/bloq_pb2.py b/qualtran/protos/bloq_pb2.py index ce0c02302..3706415b8 100644 --- a/qualtran/protos/bloq_pb2.py +++ b/qualtran/protos/bloq_pb2.py @@ -17,9 +17,10 @@ from qualtran.protos import registers_pb2 as qualtran_dot_protos_dot_registers__pb2 from qualtran.protos import data_types_pb2 as qualtran_dot_protos_dot_data__types__pb2 from qualtran.protos import ctrl_spec_pb2 as qualtran_dot_protos_dot_ctrl__spec__pb2 +from qualtran.protos import sympy_pb2 as qualtran_dot_protos_dot_sympy__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1aqualtran/protos/bloq.proto\x12\x08qualtran\x1a!qualtran/protos/annotations.proto\x1a\x1aqualtran/protos/args.proto\x1a\x1fqualtran/protos/registers.proto\x1a qualtran/protos/data_types.proto\x1a\x1fqualtran/protos/ctrl_spec.proto\"\xeb\x02\n\x07\x42loqArg\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x11\n\x07int_val\x18\x02 \x01(\x03H\x00\x12\x13\n\tfloat_val\x18\x03 \x01(\x01H\x00\x12\x14\n\nstring_val\x18\x04 \x01(\tH\x00\x12\x14\n\nsympy_expr\x18\x05 \x01(\tH\x00\x12$\n\x07ndarray\x18\x06 \x01(\x0b\x32\x11.qualtran.NDArrayH\x00\x12\x11\n\x07subbloq\x18\x07 \x01(\x05H\x00\x12\x18\n\x0e\x63irq_json_gzip\x18\x08 \x01(\x0cH\x00\x12)\n\nqdata_type\x18\t \x01(\x0b\x32\x13.qualtran.QDataTypeH\x00\x12&\n\x08register\x18\n \x01(\x0b\x32\x12.qualtran.RegisterH\x00\x12(\n\tregisters\x18\x0b \x01(\x0b\x32\x13.qualtran.RegistersH\x00\x12\'\n\tctrl_spec\x18\x0c \x01(\x0b\x32\x12.qualtran.CtrlSpecH\x00\x42\x05\n\x03val\"\xe8\x02\n\x0b\x42loqLibrary\x12\x0c\n\x04name\x18\x01 \x01(\t\x12:\n\x05table\x18\x02 \x03(\x0b\x32+.qualtran.BloqLibrary.BloqWithDecomposition\x1a\x8e\x02\n\x15\x42loqWithDecomposition\x12\x0f\n\x07\x62loq_id\x18\x01 \x01(\x05\x12+\n\rdecomposition\x18\x02 \x03(\x0b\x32\x14.qualtran.Connection\x12P\n\x0b\x62loq_counts\x18\x03 \x03(\x0b\x32;.qualtran.BloqLibrary.BloqWithDecomposition.BloqCountsEntry\x12\x1c\n\x04\x62loq\x18\x04 \x01(\x0b\x32\x0e.qualtran.Bloq\x1aG\n\x0f\x42loqCountsEntry\x12\x0b\n\x03key\x18\x01 \x01(\x05\x12#\n\x05value\x18\x02 \x01(\x0b\x32\x14.qualtran.IntOrSympy:\x02\x38\x01\"\x8a\x01\n\x04\x42loq\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x1f\n\x04\x61rgs\x18\x02 \x03(\x0b\x32\x11.qualtran.BloqArg\x12&\n\tregisters\x18\x03 \x01(\x0b\x32\x13.qualtran.Registers\x12+\n\x0ct_complexity\x18\x04 \x01(\x0b\x32\x15.qualtran.TComplexity\"4\n\x0c\x42loqInstance\x12\x13\n\x0binstance_id\x18\x01 \x01(\x05\x12\x0f\n\x07\x62loq_id\x18\x02 \x01(\x05\"\x8d\x01\n\x06Soquet\x12/\n\rbloq_instance\x18\x01 \x01(\x0b\x32\x16.qualtran.BloqInstanceH\x00\x12\x14\n\ndangling_t\x18\x02 \x01(\tH\x00\x12$\n\x08register\x18\x03 \x01(\x0b\x32\x12.qualtran.Register\x12\r\n\x05index\x18\x04 \x03(\x05\x42\x07\n\x05\x62inst\"M\n\nConnection\x12\x1e\n\x04left\x18\x01 \x01(\x0b\x32\x10.qualtran.Soquet\x12\x1f\n\x05right\x18\x02 \x01(\x0b\x32\x10.qualtran.Soquetb\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1aqualtran/protos/bloq.proto\x12\x08qualtran\x1a!qualtran/protos/annotations.proto\x1a\x1aqualtran/protos/args.proto\x1a\x1fqualtran/protos/registers.proto\x1a qualtran/protos/data_types.proto\x1a\x1fqualtran/protos/ctrl_spec.proto\x1a\x1bqualtran/protos/sympy.proto\"\xfb\x02\n\x07\x42loqArg\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x11\n\x07int_val\x18\x02 \x01(\x03H\x00\x12\x13\n\tfloat_val\x18\x03 \x01(\x01H\x00\x12\x14\n\nstring_val\x18\x04 \x01(\tH\x00\x12$\n\nsympy_expr\x18\x05 \x01(\x0b\x32\x0e.qualtran.TermH\x00\x12$\n\x07ndarray\x18\x06 \x01(\x0b\x32\x11.qualtran.NDArrayH\x00\x12\x11\n\x07subbloq\x18\x07 \x01(\x05H\x00\x12\x18\n\x0e\x63irq_json_gzip\x18\x08 \x01(\x0cH\x00\x12)\n\nqdata_type\x18\t \x01(\x0b\x32\x13.qualtran.QDataTypeH\x00\x12&\n\x08register\x18\n \x01(\x0b\x32\x12.qualtran.RegisterH\x00\x12(\n\tregisters\x18\x0b \x01(\x0b\x32\x13.qualtran.RegistersH\x00\x12\'\n\tctrl_spec\x18\x0c \x01(\x0b\x32\x12.qualtran.CtrlSpecH\x00\x42\x05\n\x03val\"\xe8\x02\n\x0b\x42loqLibrary\x12\x0c\n\x04name\x18\x01 \x01(\t\x12:\n\x05table\x18\x02 \x03(\x0b\x32+.qualtran.BloqLibrary.BloqWithDecomposition\x1a\x8e\x02\n\x15\x42loqWithDecomposition\x12\x0f\n\x07\x62loq_id\x18\x01 \x01(\x05\x12+\n\rdecomposition\x18\x02 \x03(\x0b\x32\x14.qualtran.Connection\x12P\n\x0b\x62loq_counts\x18\x03 \x03(\x0b\x32;.qualtran.BloqLibrary.BloqWithDecomposition.BloqCountsEntry\x12\x1c\n\x04\x62loq\x18\x04 \x01(\x0b\x32\x0e.qualtran.Bloq\x1aG\n\x0f\x42loqCountsEntry\x12\x0b\n\x03key\x18\x01 \x01(\x05\x12#\n\x05value\x18\x02 \x01(\x0b\x32\x14.qualtran.IntOrSympy:\x02\x38\x01\"\x8a\x01\n\x04\x42loq\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x1f\n\x04\x61rgs\x18\x02 \x03(\x0b\x32\x11.qualtran.BloqArg\x12&\n\tregisters\x18\x03 \x01(\x0b\x32\x13.qualtran.Registers\x12+\n\x0ct_complexity\x18\x04 \x01(\x0b\x32\x15.qualtran.TComplexity\"4\n\x0c\x42loqInstance\x12\x13\n\x0binstance_id\x18\x01 \x01(\x05\x12\x0f\n\x07\x62loq_id\x18\x02 \x01(\x05\"\x8d\x01\n\x06Soquet\x12/\n\rbloq_instance\x18\x01 \x01(\x0b\x32\x16.qualtran.BloqInstanceH\x00\x12\x14\n\ndangling_t\x18\x02 \x01(\tH\x00\x12$\n\x08register\x18\x03 \x01(\x0b\x32\x12.qualtran.Register\x12\r\n\x05index\x18\x04 \x03(\x05\x42\x07\n\x05\x62inst\"M\n\nConnection\x12\x1e\n\x04left\x18\x01 \x01(\x0b\x32\x10.qualtran.Soquet\x12\x1f\n\x05right\x18\x02 \x01(\x0b\x32\x10.qualtran.Soquetb\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) @@ -28,20 +29,20 @@ DESCRIPTOR._options = None _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION_BLOQCOUNTSENTRY']._options = None _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION_BLOQCOUNTSENTRY']._serialized_options = b'8\001' - _globals['_BLOQARG']._serialized_start=204 - _globals['_BLOQARG']._serialized_end=567 - _globals['_BLOQLIBRARY']._serialized_start=570 - _globals['_BLOQLIBRARY']._serialized_end=930 - _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION']._serialized_start=660 - _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION']._serialized_end=930 - _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION_BLOQCOUNTSENTRY']._serialized_start=859 - _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION_BLOQCOUNTSENTRY']._serialized_end=930 - _globals['_BLOQ']._serialized_start=933 - _globals['_BLOQ']._serialized_end=1071 - _globals['_BLOQINSTANCE']._serialized_start=1073 - _globals['_BLOQINSTANCE']._serialized_end=1125 - _globals['_SOQUET']._serialized_start=1128 - _globals['_SOQUET']._serialized_end=1269 - _globals['_CONNECTION']._serialized_start=1271 - _globals['_CONNECTION']._serialized_end=1348 + _globals['_BLOQARG']._serialized_start=233 + _globals['_BLOQARG']._serialized_end=612 + _globals['_BLOQLIBRARY']._serialized_start=615 + _globals['_BLOQLIBRARY']._serialized_end=975 + _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION']._serialized_start=705 + _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION']._serialized_end=975 + _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION_BLOQCOUNTSENTRY']._serialized_start=904 + _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION_BLOQCOUNTSENTRY']._serialized_end=975 + _globals['_BLOQ']._serialized_start=978 + _globals['_BLOQ']._serialized_end=1116 + _globals['_BLOQINSTANCE']._serialized_start=1118 + _globals['_BLOQINSTANCE']._serialized_end=1170 + _globals['_SOQUET']._serialized_start=1173 + _globals['_SOQUET']._serialized_end=1314 + _globals['_CONNECTION']._serialized_start=1316 + _globals['_CONNECTION']._serialized_end=1393 # @@protoc_insertion_point(module_scope) diff --git a/qualtran/protos/bloq_pb2.pyi b/qualtran/protos/bloq_pb2.pyi index e923ae1ac..01fcbe1b1 100644 --- a/qualtran/protos/bloq_pb2.pyi +++ b/qualtran/protos/bloq_pb2.pyi @@ -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): @@ -55,8 +56,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.""" @@ -83,7 +85,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 = ..., diff --git a/qualtran/protos/sympy.proto b/qualtran/protos/sympy.proto new file mode 100644 index 000000000..3f89d75dd --- /dev/null +++ b/qualtran/protos/sympy.proto @@ -0,0 +1,50 @@ +/* + 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 { + NONE = 0; + ADDITION = 1; + MULTIPLICATION = 2; + POWER = 3; + MOD = 4; + +} + +// A single parameter of a sympy expression. +message Parameter { + oneof parameter { + int32 const_int = 1; + string symbol = 2; + // A constant that cannot be expressed by an integer or a division operation will be irrational. + string const_irrat = 3; + } +} + +message Operand { + oneof operand { + Term term = 1; + Parameter parameter = 2; + } +} + +message Term { + Function function = 1; + repeated Operand operands = 2; +} diff --git a/qualtran/serialization/bloq.py b/qualtran/serialization/bloq.py index 6fe0f30cf..97baf5866 100644 --- a/qualtran/serialization/bloq.py +++ b/qualtran/serialization/bloq.py @@ -21,6 +21,7 @@ import numpy as np import sympy from sympy.parsing.sympy_parser import parse_expr +from qualtran.protos import sympy_pb2 from qualtran import ( Bloq, @@ -48,6 +49,111 @@ resolver_dict, ) +# example +# mult = sympy_pb2.Function.MULTIPLICATION +# parameter1 = sympy_pb2.Parameter(const_int=-1) +# parameter2 = sympy_pb2.Parameter(const_int=5) +# operand1 = sympy_pb2.Operand(parameter=parameter1) +# operand2 = sympy_pb2.Operand(parameter=parameter2) +# sympy_pb2.Term(function=mult, operand=[operand1, operand2]) + +def _get_sympy_function_type(expr: sympy.Expr)->int: + if isinstance(expr, sympy.core.mul.Mul): + return sympy_pb2.Function.MULTIPLICATION + if isinstance(expr, sympy.core.add.Add): + return sympy_pb2.Function.ADDITION + if isinstance(expr, sympy.core.power.Pow): + return sympy_pb2.Function.POWER + if isinstance(expr, sympy.core.Mod): + return sympy_pb2.Function.MOD + else: + return sympy_pb2.Function.NONE + # if isinstance(expr, sympy.core.symbol.Symbol) or issubclass(expr.__class__, sympy.core.numbers.Number): + # return sympy_pb2.Function.TERM + +def _get_sympy_from_enum(enum: int): + enum_to_sympy = { + sympy_pb2.Function.MULTIPLICATION: sympy.core.mul.Mul, + sympy_pb2.Function.ADDITION: sympy.core.add.Add, + sympy_pb2.Function.POWER: sympy.core.power.Pow, + sympy_pb2.Function.MOD: sympy.core.Mod, + sympy_pb2.Function.NONE: None + } + + # DO NOT SUBMIT: Remove this line + if enum == sympy_pb2.Function.MULTIPLICATION: + print("here") + + return enum_to_sympy[enum] + +def _get_sympy_operand(expr: sympy.Expr): + if isinstance(expr, sympy.core.symbol.Symbol): + return sympy_pb2.Parameter(symbol=str(expr)) + if issubclass(expr.__class__, sympy.core.numbers.Integer): + result = expr.numerator + if not isinstance(result, int): + raise NotImplementedError(f"Sympy expression {str(expr)} cannot be serialized.") + return sympy_pb2.Parameter(const_int=result) + if issubclass(expr.__class__, sympy.core.numbers.Number): + return sympy_pb2.Parameter(const_irrat=expr.name) + + +def decompose_sympy(expr: sympy.Expr): + function = _get_sympy_function_type(expr) + operands = [] + if function == sympy_pb2.Function.NONE: + parameter = _get_sympy_operand(expr) + operands.append(sympy_pb2.Operand(parameter=parameter)) + + else: + for term in expr.args: + inner_term = decompose_sympy(term) + + operands.append(sympy_pb2.Operand(term=inner_term)) + + return sympy_pb2.Term(function=function, operands=operands) + +def _get_parameter(operand): + parameter_type = operand.parameter.WhichOneof("parameter") + if parameter_type == "symbol": + parameter = sympy.symbols(operand.parameter.symbol) + elif parameter_type == "const_int": + parameter = operand.parameter.const_int + elif parameter_type == "const_irrat": + # TODO: Check that this works + parameter = sympy.parse_expr(operand.parameter.const_irrat) + + return parameter + +def _set_function(function, parameters): + return function(parameters) + +def compose_sympy(expr: sympy.Expr): + function = _get_sympy_from_enum(expr.function) + parameters = [] + for operand in expr.operands: + if operand.HasField("term"): + parameters.append(compose_sympy(operand.term)) + else: + parameter = _get_parameter(operand) + parameters.append(parameter) + + if function: + return function(*parameters) + else: + if len(parameters) == 1: + return parameters[0] + + + + + +# expr.operands[1].term.operands[0].term.operands[0].term.operands[0].parameter.symbol + + + + + def arg_to_proto(*, name: str, val: Any) -> bloq_pb2.BloqArg: if isinstance(val, int): @@ -57,7 +163,7 @@ def arg_to_proto(*, name: str, val: Any) -> bloq_pb2.BloqArg: if isinstance(val, str): return bloq_pb2.BloqArg(name=name, string_val=val) if isinstance(val, sympy.Expr): - return bloq_pb2.BloqArg(name=name, sympy_expr=str(val)) + return bloq_pb2.BloqArg(name=name, sympy_expr=decompose_sympy(val)) if isinstance(val, Register): return bloq_pb2.BloqArg(name=name, register=registers.register_to_proto(val)) if isinstance(val, tuple) and all(isinstance(x, Register) for x in val): @@ -81,7 +187,7 @@ def arg_from_proto(arg: bloq_pb2.BloqArg) -> Dict[str, Any]: if arg.HasField("string_val"): return {arg.name: arg.string_val} if arg.HasField("sympy_expr"): - return {arg.name: parse_expr(arg.sympy_expr)} + return {arg.name: compose_sympy(arg.sympy_expr)} if arg.HasField("register"): return {arg.name: registers.register_from_proto(arg.register)} if arg.HasField("registers"): diff --git a/qualtran/serialization/scratch.py b/qualtran/serialization/scratch.py new file mode 100644 index 000000000..4d74343c4 --- /dev/null +++ b/qualtran/serialization/scratch.py @@ -0,0 +1,10 @@ +from qualtran.serialization.bloq import bloqs_from_proto, bloqs_to_proto +import sympy +from qualtran.bloqs.factoring.mod_mul import CtrlModMul + +k, N, n_x = sympy.symbols('k N n_x') +bloq = CtrlModMul(k=k, mod=N, bitsize=n_x) + +proto = bloqs_to_proto(bloq) +clone = bloqs_from_proto(proto) +print("here") \ No newline at end of file From 831195ca13c2ecf33af03f427663d7a53c65aa42 Mon Sep 17 00:00:00 2001 From: local_linix Date: Mon, 1 Apr 2024 17:18:14 -0700 Subject: [PATCH 12/34] Clean up workspace --- qualtran/protos/__init__.py | 1 - qualtran/protos/sympy_pb2.py | 32 ++++++++ qualtran/protos/sympy_pb2.pyi | 122 ++++++++++++++++++++++++++++++ qualtran/serialization/bloq.py | 37 +++------ qualtran/serialization/scratch.py | 10 --- 5 files changed, 165 insertions(+), 37 deletions(-) create mode 100644 qualtran/protos/sympy_pb2.py create mode 100644 qualtran/protos/sympy_pb2.pyi delete mode 100644 qualtran/serialization/scratch.py diff --git a/qualtran/protos/__init__.py b/qualtran/protos/__init__.py index a1c0721cb..ce76a8d10 100644 --- a/qualtran/protos/__init__.py +++ b/qualtran/protos/__init__.py @@ -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. - diff --git a/qualtran/protos/sympy_pb2.py b/qualtran/protos/sympy_pb2.py new file mode 100644 index 000000000..8670d1bc2 --- /dev/null +++ b/qualtran/protos/sympy_pb2.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: qualtran/protos/sympy.proto +# Protobuf Python Version: 4.25.1 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1bqualtran/protos/sympy.proto\x12\x08qualtran\"V\n\tParameter\x12\x13\n\tconst_int\x18\x01 \x01(\x05H\x00\x12\x10\n\x06symbol\x18\x02 \x01(\tH\x00\x12\x15\n\x0b\x63onst_irrat\x18\x03 \x01(\tH\x00\x42\x0b\n\tparameter\"^\n\x07Operand\x12\x1e\n\x04term\x18\x01 \x01(\x0b\x32\x0e.qualtran.TermH\x00\x12(\n\tparameter\x18\x02 \x01(\x0b\x32\x13.qualtran.ParameterH\x00\x42\t\n\x07operand\"Q\n\x04Term\x12$\n\x08\x66unction\x18\x01 \x01(\x0e\x32\x12.qualtran.Function\x12#\n\x08operands\x18\x02 \x03(\x0b\x32\x11.qualtran.Operand*J\n\x08\x46unction\x12\x08\n\x04NONE\x10\x00\x12\x0c\n\x08\x41\x44\x44ITION\x10\x01\x12\x12\n\x0eMULTIPLICATION\x10\x02\x12\t\n\x05POWER\x10\x03\x12\x07\n\x03MOD\x10\x04\x62\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'qualtran.protos.sympy_pb2', _globals) +if _descriptor._USE_C_DESCRIPTORS == False: + DESCRIPTOR._options = None + _globals['_FUNCTION']._serialized_start=308 + _globals['_FUNCTION']._serialized_end=382 + _globals['_PARAMETER']._serialized_start=41 + _globals['_PARAMETER']._serialized_end=127 + _globals['_OPERAND']._serialized_start=129 + _globals['_OPERAND']._serialized_end=223 + _globals['_TERM']._serialized_start=225 + _globals['_TERM']._serialized_end=306 +# @@protoc_insertion_point(module_scope) diff --git a/qualtran/protos/sympy_pb2.pyi b/qualtran/protos/sympy_pb2.pyi new file mode 100644 index 000000000..98adbde6f --- /dev/null +++ b/qualtran/protos/sympy_pb2.pyi @@ -0,0 +1,122 @@ +""" +@generated by mypy-protobuf. Do not edit manually! +isort:skip_file + +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. +""" +import builtins +import collections.abc +import google.protobuf.descriptor +import google.protobuf.internal.containers +import google.protobuf.internal.enum_type_wrapper +import google.protobuf.message +import sys +import typing + +if sys.version_info >= (3, 10): + import typing as typing_extensions +else: + import typing_extensions + +DESCRIPTOR: google.protobuf.descriptor.FileDescriptor + +class _Function: + ValueType = typing.NewType("ValueType", builtins.int) + V: typing_extensions.TypeAlias = ValueType + +class _FunctionEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[_Function.ValueType], builtins.type): + DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor + NONE: _Function.ValueType # 0 + ADDITION: _Function.ValueType # 1 + MULTIPLICATION: _Function.ValueType # 2 + POWER: _Function.ValueType # 3 + MOD: _Function.ValueType # 4 + +class Function(_Function, metaclass=_FunctionEnumTypeWrapper): + """A function sympy expression.""" + +NONE: Function.ValueType # 0 +ADDITION: Function.ValueType # 1 +MULTIPLICATION: Function.ValueType # 2 +POWER: Function.ValueType # 3 +MOD: Function.ValueType # 4 +global___Function = Function + +@typing_extensions.final +class Parameter(google.protobuf.message.Message): + """A single parameter of a sympy expression.""" + + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + CONST_INT_FIELD_NUMBER: builtins.int + SYMBOL_FIELD_NUMBER: builtins.int + CONST_IRRAT_FIELD_NUMBER: builtins.int + const_int: builtins.int + symbol: builtins.str + const_irrat: builtins.str + """A constant that cannot be expressed by an integer or a division operation will be irrational.""" + def __init__( + self, + *, + const_int: builtins.int = ..., + symbol: builtins.str = ..., + const_irrat: builtins.str = ..., + ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["const_int", b"const_int", "const_irrat", b"const_irrat", "parameter", b"parameter", "symbol", b"symbol"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["const_int", b"const_int", "const_irrat", b"const_irrat", "parameter", b"parameter", "symbol", b"symbol"]) -> None: ... + def WhichOneof(self, oneof_group: typing_extensions.Literal["parameter", b"parameter"]) -> typing_extensions.Literal["const_int", "symbol", "const_irrat"] | None: ... + +global___Parameter = Parameter + +@typing_extensions.final +class Operand(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + TERM_FIELD_NUMBER: builtins.int + PARAMETER_FIELD_NUMBER: builtins.int + @property + def term(self) -> global___Term: ... + @property + def parameter(self) -> global___Parameter: ... + def __init__( + self, + *, + term: global___Term | None = ..., + parameter: global___Parameter | None = ..., + ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["operand", b"operand", "parameter", b"parameter", "term", b"term"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["operand", b"operand", "parameter", b"parameter", "term", b"term"]) -> None: ... + def WhichOneof(self, oneof_group: typing_extensions.Literal["operand", b"operand"]) -> typing_extensions.Literal["term", "parameter"] | None: ... + +global___Operand = Operand + +@typing_extensions.final +class Term(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + FUNCTION_FIELD_NUMBER: builtins.int + OPERANDS_FIELD_NUMBER: builtins.int + function: global___Function.ValueType + @property + def operands(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___Operand]: ... + def __init__( + self, + *, + function: global___Function.ValueType = ..., + operands: collections.abc.Iterable[global___Operand] | None = ..., + ) -> None: ... + def ClearField(self, field_name: typing_extensions.Literal["function", b"function", "operands", b"operands"]) -> None: ... + +global___Term = Term diff --git a/qualtran/serialization/bloq.py b/qualtran/serialization/bloq.py index 97baf5866..7a3900b9b 100644 --- a/qualtran/serialization/bloq.py +++ b/qualtran/serialization/bloq.py @@ -21,7 +21,6 @@ import numpy as np import sympy from sympy.parsing.sympy_parser import parse_expr -from qualtran.protos import sympy_pb2 from qualtran import ( Bloq, @@ -39,7 +38,7 @@ Signature, Soquet, ) -from qualtran.protos import bloq_pb2 +from qualtran.protos import bloq_pb2, sympy_pb2 from qualtran.serialization import ( annotations, args, @@ -49,15 +48,8 @@ resolver_dict, ) -# example -# mult = sympy_pb2.Function.MULTIPLICATION -# parameter1 = sympy_pb2.Parameter(const_int=-1) -# parameter2 = sympy_pb2.Parameter(const_int=5) -# operand1 = sympy_pb2.Operand(parameter=parameter1) -# operand2 = sympy_pb2.Operand(parameter=parameter2) -# sympy_pb2.Term(function=mult, operand=[operand1, operand2]) -def _get_sympy_function_type(expr: sympy.Expr)->int: +def _get_sympy_function_type(expr: sympy.Expr) -> int: if isinstance(expr, sympy.core.mul.Mul): return sympy_pb2.Function.MULTIPLICATION if isinstance(expr, sympy.core.add.Add): @@ -68,8 +60,7 @@ def _get_sympy_function_type(expr: sympy.Expr)->int: return sympy_pb2.Function.MOD else: return sympy_pb2.Function.NONE - # if isinstance(expr, sympy.core.symbol.Symbol) or issubclass(expr.__class__, sympy.core.numbers.Number): - # return sympy_pb2.Function.TERM + def _get_sympy_from_enum(enum: int): enum_to_sympy = { @@ -77,7 +68,7 @@ def _get_sympy_from_enum(enum: int): sympy_pb2.Function.ADDITION: sympy.core.add.Add, sympy_pb2.Function.POWER: sympy.core.power.Pow, sympy_pb2.Function.MOD: sympy.core.Mod, - sympy_pb2.Function.NONE: None + sympy_pb2.Function.NONE: None, } # DO NOT SUBMIT: Remove this line @@ -86,6 +77,7 @@ def _get_sympy_from_enum(enum: int): return enum_to_sympy[enum] + def _get_sympy_operand(expr: sympy.Expr): if isinstance(expr, sympy.core.symbol.Symbol): return sympy_pb2.Parameter(symbol=str(expr)) @@ -113,6 +105,7 @@ def decompose_sympy(expr: sympy.Expr): return sympy_pb2.Term(function=function, operands=operands) + def _get_parameter(operand): parameter_type = operand.parameter.WhichOneof("parameter") if parameter_type == "symbol": @@ -120,14 +113,15 @@ def _get_parameter(operand): elif parameter_type == "const_int": parameter = operand.parameter.const_int elif parameter_type == "const_irrat": - # TODO: Check that this works parameter = sympy.parse_expr(operand.parameter.const_irrat) return parameter + def _set_function(function, parameters): return function(parameters) + def compose_sympy(expr: sympy.Expr): function = _get_sympy_from_enum(expr.function) parameters = [] @@ -140,19 +134,10 @@ def compose_sympy(expr: sympy.Expr): if function: return function(*parameters) + elif len(parameters) == 1: + return parameters[0] else: - if len(parameters) == 1: - return parameters[0] - - - - - -# expr.operands[1].term.operands[0].term.operands[0].term.operands[0].parameter.symbol - - - - + raise NotImplementedError(f"{expr.function} has not been fully implimented.") def arg_to_proto(*, name: str, val: Any) -> bloq_pb2.BloqArg: diff --git a/qualtran/serialization/scratch.py b/qualtran/serialization/scratch.py deleted file mode 100644 index 4d74343c4..000000000 --- a/qualtran/serialization/scratch.py +++ /dev/null @@ -1,10 +0,0 @@ -from qualtran.serialization.bloq import bloqs_from_proto, bloqs_to_proto -import sympy -from qualtran.bloqs.factoring.mod_mul import CtrlModMul - -k, N, n_x = sympy.symbols('k N n_x') -bloq = CtrlModMul(k=k, mod=N, bitsize=n_x) - -proto = bloqs_to_proto(bloq) -clone = bloqs_from_proto(proto) -print("here") \ No newline at end of file From 8c8d82f51571c5fdf1bbcc9482d433c1fedb5766 Mon Sep 17 00:00:00 2001 From: local_linix Date: Tue, 2 Apr 2024 14:07:50 -0700 Subject: [PATCH 13/34] Remote large tests from get_bloq_examples() --- Untitled.ipynb | 63 + Untitled1.ipynb | 2604 +++++++++++++++++ dev_tools/qualtran_dev_tools/bloq_finder.py | 6 +- .../qualtran_dev_tools/bloq_report_card.py | 4 +- 4 files changed, 2675 insertions(+), 2 deletions(-) create mode 100644 Untitled.ipynb create mode 100644 Untitled1.ipynb diff --git a/Untitled.ipynb b/Untitled.ipynb new file mode 100644 index 000000000..be9b8cf66 --- /dev/null +++ b/Untitled.ipynb @@ -0,0 +1,63 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 6, + "id": "1a96f9e5-2094-48ff-867b-9b98e20cf314", + "metadata": {}, + "outputs": [], + "source": [ + "from dev_tools.qualtran_dev_tools.bloq_report_card import get_bloq_report_card, show_bloq_report_card" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b8ce3d39-3972-42ae-b167-e4ed6241ba1c", + "metadata": {}, + "outputs": [], + "source": [ + "df = get_bloq_report_card()\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "79ab63fe-1b60-4b38-a2c6-42e89c9a1293", + "metadata": {}, + "outputs": [], + "source": [ + "print(\"hello\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "01f2964e-90c8-4c75-8969-f31e65557ed2", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Untitled1.ipynb b/Untitled1.ipynb new file mode 100644 index 000000000..c9aa22dc5 --- /dev/null +++ b/Untitled1.ipynb @@ -0,0 +1,2604 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "355be5a3-6919-4f2b-a6a3-47758a0c9f50", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hello world\n" + ] + } + ], + "source": [ + "print(\"hello world\")" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "aa81a78a-e308-4ea9-9a3a-29ff1cb27bb5", + "metadata": {}, + "outputs": [], + "source": [ + "from dev_tools.qualtran_dev_tools.bloq_report_card import get_bloq_report_card, show_bloq_report_card" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "90ea5580-ab8f-4568-ab74-059459f22a02", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "add_k_large\n", + "add_k_small\n", + "add_k_symb\n", + "add_large\n", + "add_oop_large\n", + "add_oop_small\n", + "add_oop_symb\n", + "add_small\n", + "add_symb\n", + "simple_add_k_large\n", + "simple_add_k_small\n", + "bi_qubits_mixer\n", + "eq_k\n", + "greater_than\n", + "gt_k\n", + "leq\n", + "leq_symb\n", + "lt_k\n", + "lt_k_symb\n", + "sq_cmp\n", + "signed_to_twos\n", + "to_contg_index\n", + "multiply_two_reals\n", + "plus_equal_product\n", + "product\n", + "scale_int_by_real\n", + "square\n", + "square_real_number\n", + "sum_of_squares\n", + "bitonic_sort\n", + "cmp_symb\n", + "cnot\n", + "global_phase\n", + "hadamard\n", + "rx\n", + "ry\n", + "rz\n", + "x_pow\n", + "y_pow\n", + "z_pow\n", + "s_gate\n", + "hadamard\n", + "su2_rotation_gate\n", + "t_gate\n", + "cswap_large\n", + "cswap_small\n", + "cswap_symb\n", + "swap_small\n", + "t_gate\n", + "toffoli\n", + "minus_effect\n", + "minus_state\n", + "plus_effect\n", + "plus_state\n", + "int_effect\n", + "int_state\n", + "one_effect\n", + "one_state\n", + "zero_effect\n", + "zero_state\n", + "zgate\n", + "black_box_block_bloq\n", + "black_box_prepare\n", + "black_box_select\n", + "chebyshev_poly\n", + "df_block_encoding\n", + "df_one_body\n", + "indexed_data\n", + "prep_inner\n", + "prep_outer\n", + "prepare_t\n", + "prepare_uv\n", + "prep_mu_proj\n", + "prep_nu_proj\n", + "prep_power_two_proj\n", + "prep_t_proj\n", + "prep_uv_proj\n", + "prep_first_quant\n", + "sel_first_quant\n", + "sel_t_proj\n", + "sel_uv_proj\n", + "prep_first_quant\n", + "sel_first_quant\n", + "select_t\n", + "select_uv\n", + "prep_inner\n", + "prep_outer\n", + "select\n", + "sf_block_encoding\n", + "sf_one_body\n", + "prep_sparse\n", + "sel_sparse\n", + "thc_prep\n", + "thc_uni\n", + "thc_sel\n", + "nr_inv_sqrt\n", + "poly_inv_sqrt\n", + "kinetic_energy\n", + "pair_potential\n", + "potential_energy\n", + "qvr\n", + "hopping_tile\n", + "plaquette\n", + "interaction\n", + "ising_x\n", + "ising_zz\n", + "trott_unitary\n", + "qrom_multi_data\n", + "qrom_multi_dim\n", + "qrom_small\n", + "modexp\n", + "modexp_small\n", + "modexp_symb\n", + "modmul\n", + "modmul_symb\n", + "and_bloq\n", + "multi_and\n", + "c_multi_not\n", + "c_multi_not_symb\n", + "ccpauli\n", + "apply_z_to_odd\n", + "select_pauli_lcu\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/linux_environment/miniconda3/envs/quantum/lib/python3.10/site-packages/sympy/core/function.py:297: SymPyDeprecationWarning: \n", + "\n", + "The string fallback in sympify() is deprecated.\n", + "\n", + "To explicitly convert the string form of an object, use\n", + "sympify(str(obj)). To add define sympify behavior on custom\n", + "objects, use sympy.core.sympify.converter or define obj._sympy_\n", + "(see the sympify() docstring).\n", + "\n", + "sympify() performed the string fallback resulting in the following string:\n", + "\n", + "''\n", + "\n", + "See https://docs.sympy.org/latest/explanation/active-deprecations.html#deprecated-sympify-string-fallback\n", + "for details.\n", + "\n", + "This has been deprecated since SymPy version 1.6. It\n", + "will be removed in a future version of SymPy.\n", + "\n", + " args = list(map(sympify, args))\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "lp_resource_state_small\n", + "lp_resource_state_symbolic\n", + "lprs_interim_prep\n", + "textbook_qpe_from_precision_and_delta\n", + "textbook_qpe_from_standard_deviation_eps\n", + "textbook_qpe_small\n", + "textbook_qpe_using_m_bits\n", + "approximate_qft_from_epsilon\n", + "approximate_qft_small\n", + "two_bit_ffft\n", + "walk_op\n", + "reflection\n", + "square_via_phase_gradient\n", + "square_via_zpow_phasing\n", + "qvr_phase_gradient\n", + "qvr_zpow\n", + "c_prep_uniform\n", + "prep_uniform\n", + "state_prep_alias\n", + "state_prep_via_rotation\n", + "approx_cswap_large\n", + "approx_cswap_small\n", + "approx_cswap_symb\n", + "multiplexed_cswap\n", + "swz\n", + "swz_small\n" + ] + } + ], + "source": [ + "df = get_bloq_report_card()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "3e281f1b-6067-4cf7-aac3-e490ec849cd7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 packagebloq_clsnamemakedecompcountsserialize
84arithmeticAddadd_largepasspassfailpass
88arithmeticAddadd_smallpasspassfailpass
89arithmeticAddadd_symbpassnaunverifiedpass
81arithmeticAddConstantModadd_k_largepassmissingunverifiedpass
82arithmeticAddConstantModadd_k_smallpassmissingunverifiedpass
83arithmeticAddConstantModadd_k_symbpassnaunverifiedpass
92arithmeticBiQubitsMixerbi_qubits_mixerpasspassunverifiedpass
110arithmeticBitonicSortbitonic_sortpassmissingmissingpass
111arithmeticComparatorcmp_symbpassmissingmissingpass
93arithmeticEqualsAConstanteq_kpassmissingunverifiedpass
94arithmeticGreaterThangreater_thanpassmissingunverifiedpass
95arithmeticGreaterThanConstantgt_kpassmissingunverifiedpass
53arithmeticHammingWeightCompute-missingmissingmissingmissing
98arithmeticLessThanConstantlt_kpasspassunverifiedpass
99arithmeticLessThanConstantlt_k_symbpassnamissingpass
96arithmeticLessThanEqualleqpasspassunverifiedpass
97arithmeticLessThanEqualleq_symbpassnamissingpass
59arithmeticLinearDepthGreaterThan-missingmissingmissingmissing
103arithmeticMultiplyTwoRealsmultiply_two_realspassmissingunverifiedpass
85arithmeticOutOfPlaceAdderadd_oop_largepasspassfailpass
86arithmeticOutOfPlaceAdderadd_oop_smallpasspassfailpass
87arithmeticOutOfPlaceAdderadd_oop_symbpassnaunverifiedpass
104arithmeticPlusEqualProductplus_equal_productpassmissingunverifiedpass
105arithmeticProductproductpassmissingunverifiedpass
106arithmeticScaleIntByRealscale_int_by_realpassmissingunverifiedpass
101arithmeticSignedIntegerToTwosComplementsigned_to_twospassmissingunverifiedpass
90arithmeticSimpleAddConstantsimple_add_k_largepasspassunverifiedpass
91arithmeticSimpleAddConstantsimple_add_k_smallpasspassunverifiedpass
100arithmeticSingleQubitComparesq_cmppasspassunverifiedpass
107arithmeticSquaresquarepassmissingunverifiedpass
108arithmeticSquareRealNumbersquare_real_numberpassmissingunverifiedpass
109arithmeticSumOfSquaressum_of_squarespassmissingunverifiedpass
102arithmeticToContiguousIndexto_contg_indexpassmissingunverifiedpass
112basic_gatesCNOTcnotpassnamissingpass
125basic_gatesCSwapcswap_largepasspasspasspass
126basic_gatesCSwapcswap_smallpasspasspasspass
127basic_gatesCSwapcswap_symbpassnaunverifiedpass
23basic_gatesCZPowGate-missingmissingmissingmissing
113basic_gatesGlobalPhaseglobal_phasepassnamissingpass
114basic_gatesHadamardhadamardpassnamissingpass
135basic_gatesIntEffectint_effectpasspassfailpass
136basic_gatesIntStateint_statepasspassfailpass
131basic_gatesMinusEffectminus_effectpassmissingmissingpass
132basic_gatesMinusStateminus_statepassmissingmissingpass
1basic_gatesOnEach-missingmissingmissingmissing
137basic_gatesOneEffectone_effectpassnamissingpass
138basic_gatesOneStateone_statepassnamissingpass
133basic_gatesPlusEffectplus_effectpassmissingmissingpass
134basic_gatesPlusStateplus_statepassmissingmissingpass
115basic_gatesRxrxpassnamissingpass
116basic_gatesRyrypassnamissingpass
117basic_gatesRzrzpassnamissingpass
121basic_gatesSGates_gatepassmissingmissingpass
122basic_gatesSU2RotationGatehadamardpasspassunverifiedpass
123basic_gatesSU2RotationGatesu2_rotation_gatepasspassunverifiedpass
124basic_gatesSU2RotationGatet_gatepasspassunverifiedpass
128basic_gatesSwapswap_smallpasspasspasspass
129basic_gatesTGatet_gatepassmissingmissingpass
130basic_gatesToffolitoffolipassmissingunverifiedpass
22basic_gatesTwoBitCSwap-missingmissingmissingmissing
26basic_gatesTwoBitSwap-missingmissingmissingmissing
45basic_gatesXGate-missingmissingmissingmissing
118basic_gatesXPowGatex_powpassnamissingpass
54basic_gatesYGate-missingmissingmissingmissing
119basic_gatesYPowGatey_powpassnamissingpass
141basic_gatesZGatezgatepassnamissingpass
120basic_gatesZPowGatez_powpassnamissingpass
139basic_gatesZeroEffectzero_effectpassnamissingpass
140basic_gatesZeroStatezero_statepassnamissingpass
15chemistryApplyControlledZs-missingmissingmissingmissing
78chemistryQROAM-missingmissingmissingmissing
5chemistryQROAMTwoRegs-missingmissingmissingmissing
146chemistry.dfDoubleFactorizationBlockEncodingdf_block_encodingpasspassunverifiedpass
147chemistry.dfDoubleFactorizationOneBodydf_one_bodypasspassfailpass
149chemistry.dfInnerPrepareDoubleFactorizationprep_innerpassmissingunverifiedpass
150chemistry.dfOuterPrepareDoubleFactorizationprep_outerpassmissingunverifiedpass
148chemistry.dfOutputIndexedDataindexed_datapassmissingunverifiedpass
55chemistry.dfProgRotGateArray-missingmissingmissingmissing
48chemistry.pbc.first_quantizationApplyNuclearPhase-missingmissingmissingmissing
76chemistry.pbc.first_quantizationFlagZeroAsFailure-missingmissingmissingmissing
2chemistry.pbc.first_quantizationMultiplexedCSwap3D-missingmissingmissingmissing
162chemistry.pbc.first_quantizationPrepareFirstQuantizationprep_first_quantpasspassunverifiedpass
50chemistry.pbc.first_quantizationPrepareMuUnaryEncodedOneHot-missingmissingmissingmissing
29chemistry.pbc.first_quantizationPrepareNuState-missingmissingmissingmissing
13chemistry.pbc.first_quantizationPrepareNuSuperPositionState-missingmissingmissingmissing
51chemistry.pbc.first_quantizationPreparePowerTwoState-missingmissingmissingmissing
151chemistry.pbc.first_quantizationPrepareTFirstQuantizationprepare_tpasspassfailpass
63chemistry.pbc.first_quantizationPrepareTUVSuperpositions-missingmissingmissingmissing
152chemistry.pbc.first_quantizationPrepareUVFirstQuantizationprepare_uvpasspasspasspass
66chemistry.pbc.first_quantizationPrepareZetaState-missingmissingmissingmissing
163chemistry.pbc.first_quantizationSelectFirstQuantizationsel_first_quantpasspassunverifiedpass
164chemistry.pbc.first_quantizationSelectTFirstQuantizationselect_tpassmissingunverifiedpass
165chemistry.pbc.first_quantizationSelectUVFirstQuantizationselect_uvpassmissingunverifiedpass
30chemistry.pbc.first_quantizationTestNuInequality-missingmissingmissingmissing
49chemistry.pbc.first_quantizationTestNuLessThanMu-missingmissingmissingmissing
11chemistry.pbc.first_quantizationUniformSuperpostionIJFirstQuantization-missingmissingmissingmissing
25chemistry.pbc.first_quantizationUniformSuperpostionIJFirstQuantization-missingmissingmissingmissing
60chemistry.pbc.first_quantization.projectileControlledMultiplexedCSwap3D-missingmissingmissingmissing
158chemistry.pbc.first_quantization.projectilePrepareFirstQuantizationWithProjprep_first_quantpasspassunverifiedpass
153chemistry.pbc.first_quantization.projectilePrepareMuUnaryEncodedOneHotWithProjprep_mu_projpassmissingunverifiedpass
154chemistry.pbc.first_quantization.projectilePrepareNuStateWithProjprep_nu_projpasspassfailpass
155chemistry.pbc.first_quantization.projectilePreparePowerTwoStateWithProjprep_power_two_projpassmissingunverifiedpass
156chemistry.pbc.first_quantization.projectilePrepareTFirstQuantizationWithProjprep_t_projpassmissingunverifiedpass
70chemistry.pbc.first_quantization.projectilePrepareTUVSuperpositions-missingmissingmissingmissing
157chemistry.pbc.first_quantization.projectilePrepareUVFirstQuantizationWithProjprep_uv_projpasspasspasspass
159chemistry.pbc.first_quantization.projectileSelectFirstQuantizationWithProjsel_first_quantpasspassunverifiedpass
160chemistry.pbc.first_quantization.projectileSelectTFirstQuantizationWithProjsel_t_projpassmissingunverifiedpass
161chemistry.pbc.first_quantization.projectileSelectUVFirstQuantizationWithProjsel_uv_projpassmissingunverifiedpass
166chemistry.sfInnerPrepareSingleFactorizationprep_innerpassmissingunverifiedpass
167chemistry.sfOuterPrepareSingleFactorizationprep_outerpassmissingunverifiedpass
168chemistry.sfSelectSingleFactorizationselectpassmissingunverifiedpass
169chemistry.sfSingleFactorizationBlockEncodingsf_block_encodingpasspassunverifiedpass
170chemistry.sfSingleFactorizationOneBodysf_one_bodypasspasspasspass
171chemistry.sparsePrepareSparseprep_sparsepasspassfailfail
172chemistry.sparseSelectSparsesel_sparsepasspassfailpass
173chemistry.thcPrepareTHCthc_preppasspassfailfail
175chemistry.thcSelectTHCthc_selpasspassunverifiedpass
43chemistry.thcTHCRotations-missingmissingmissingmissing
174chemistry.thcUniformSuperpositionTHCthc_unipasspassunverifiedpass
187chemistry.trotterTrotterizedUnitarytrott_unitarypasspassunverifiedfail
178chemistry.trotter.grid_hamKineticEnergykinetic_energypasspassunverifiedpass
176chemistry.trotter.grid_hamNewtonRaphsonApproxInverseSquareRootnr_inv_sqrtpassmissingunverifiedpass
179chemistry.trotter.grid_hamPairPotentialpair_potentialpasspassunverifiedpass
177chemistry.trotter.grid_hamPolynmomialEvaluationInverseSquareRootpoly_inv_sqrtpassmissingunverifiedpass
180chemistry.trotter.grid_hamPotentialEnergypotential_energypasspassunverifiedpass
181chemistry.trotter.grid_hamQuantumVariableRotationqvrpassmissingunverifiedpass
183chemistry.trotter.hubbardHoppingPlaquetteplaquettepassmissingunverifiedpass
182chemistry.trotter.hubbardHoppingTilehopping_tilepassmissingunverifiedpass
184chemistry.trotter.hubbardInteractioninteractionpassmissingunverifiedpass
185chemistry.trotter.isingIsingXUnitaryising_xpasspassunverifiedpass
186chemistry.trotter.isingIsingZZUnitaryising_zzpasspassunverifiedpass
188data_loadingQROMqrom_multi_datapasspassfailpass
189data_loadingQROMqrom_multi_dimpasspassfailpass
190data_loadingQROMqrom_smallpasspassfailpass
75data_loadingSelectSwapQROM-missingmissingmissingmissing
38factoringCtrlAddK-missingmissingmissingmissing
64factoringCtrlModAddK-missingmissingmissingmissing
194factoringCtrlModMulmodmulpasspasspasspass
195factoringCtrlModMulmodmul_symbpasspasspassfail
21factoringCtrlScaleModAdd-missingmissingmissingmissing
191factoringModExpmodexppasspasspassfail
192factoringModExpmodexp_smallpasspasspassfail
193factoringModExpmodexp_symbpassnaunverifiedfail
6factoringMontgomeryModAdd-missingmissingmissingmissing
79factoringMontgomeryModDbl-missingmissingmissingmissing
61factoringMontgomeryModNeg-missingmissingmissingmissing
67factoringMontgomeryModSub-missingmissingmissingmissing
41for_testingInteriorAlloc-missingmissingmissingmissing
73for_testingTestAtom-missingmissingmissingmissing
77for_testingTestBloqWithCallGraph-missingmissingmissingmissing
71for_testingTestBoundedQUInt-missingmissingmissingmissing
39for_testingTestCastToFrom-missingmissingmissingmissing
33for_testingTestIndependentParallelCombo-missingmissingmissingmissing
42for_testingTestMultiRegister-missingmissingmissingmissing
16for_testingTestMultiTypedRegister-missingmissingmissingmissing
74for_testingTestParallelCombo-missingmissingmissingmissing
28for_testingTestQFxp-missingmissingmissingmissing
32for_testingTestSerialCombo-missingmissingmissingmissing
3for_testingTestTwoBitOp-missingmissingmissingmissing
196mcmtAndand_bloqpasspasspasspass
197mcmtMultiAndmulti_andpasspasspasspass
200mcmtMultiControlPauliccpaulipasspasspasspass
12mcmtMultiControlX-missingmissingmissingmissing
198mcmtMultiTargetCNOTc_multi_notpasspassunverifiedpass
199mcmtMultiTargetCNOTc_multi_not_symbpassnamissingpass
69mean_estimationArcTan-missingmissingmissingmissing
46mean_estimationComplexPhaseOracle-missingmissingmissingmissing
37mean_estimationMeanEstimationOperator-missingmissingmissingmissing
201multiplexersApplyGateToLthQubitapply_z_to_oddpasspasspassfail
202multiplexersSelectPauliLCUselect_pauli_lcupasspasspassfail
68multiplexersSelectedMajoranaFermion-missingmissingmissingmissing
0multiplexersUnaryIterationGate-missingmissingmissingmissing
205phase_estimationLPRSInterimPreplprs_interim_preppasspassfailpass
203phase_estimationLPResourceStatelp_resource_state_smallpasspassfailpass
204phase_estimationLPResourceStatelp_resource_state_symbolicpassnaerrorfail
40phase_estimationQubitizationQPE-missingmissingmissingmissing
206phase_estimationTextbookQPEtextbook_qpe_from_precision_and_deltapassnaunverifiedfail
207phase_estimationTextbookQPEtextbook_qpe_from_standard_deviation_epspassnaunverifiedfail
208phase_estimationTextbookQPEtextbook_qpe_smallpasspassfailpass
209phase_estimationTextbookQPEtextbook_qpe_using_m_bitspassnaunverifiedfail
210qftApproximateQFTapproximate_qft_from_epsilonpasspassfailpass
211qftApproximateQFTapproximate_qft_smallpasspassfailpass
9qftQFTPhaseGradient-missingmissingmissingmissing
62qftQFTTextBook-missingmissingmissingmissing
212qftTwoBitFFFTtwo_bit_ffftpasspassfailpass
44qualtran.bloqsAllocate-missingmissingmissingmissing
17qualtran.bloqsArbitraryClifford-missingmissingmissingmissing
142qualtran.bloqsBlackBoxBlockEncodingblack_box_block_bloqpasspassunverifiedpass
143qualtran.bloqsBlackBoxPrepareblack_box_preparepasspassunverifiedpass
144qualtran.bloqsBlackBoxSelectblack_box_selectpasspassunverifiedpass
58qualtran.bloqsCast-missingmissingmissingmissing
145qualtran.bloqsChebyshevPolynomialchebyshev_polypasspasspasspass
52qualtran.bloqsFree-missingmissingmissingmissing
20qualtran.bloqsGeneralizedQSP-missingmissingmissingmissing
18qualtran.bloqsJoin-missingmissingmissingmissing
24qualtran.bloqsPartition-missingmissingmissingmissing
27qualtran.bloqsPower-missingmissingmissingmissing
80qualtran.bloqsPrepareHubbard-missingmissingmissingmissing
8qualtran.bloqsPrepareOracle-missingmissingmissingmissing
213qualtran.bloqsQubitizationWalkOperatorwalk_oppasspassunverifiedfail
214qualtran.bloqsReflectionreflectionpasspassfailpass
35qualtran.bloqsReflectionUsingPrepare-missingmissingmissingmissing
72qualtran.bloqsSelectHubbard-missingmissingmissingmissing
56qualtran.bloqsSelectOracle-missingmissingmissingmissing
19qualtran.bloqsSplit-missingmissingmissingmissing
47rotationsAddIntoPhaseGrad-missingmissingmissingmissing
57rotationsAddScaledValIntoPhaseReg-missingmissingmissingmissing
14rotationsHammingWeightPhasing-missingmissingmissingmissing
31rotationsHammingWeightPhasingViaPhaseGradient-missingmissingmissingmissing
10rotationsPhaseGradientState-missingmissingmissingmissing
34rotationsPhaseGradientUnitary-missingmissingmissingmissing
215rotationsPhasingViaCostFunctionsquare_via_phase_gradientpasspassunverifiedpass
216rotationsPhasingViaCostFunctionsquare_via_zpow_phasingpasspassunverifiedpass
36rotationsProgrammableRotationGateArray-missingmissingmissingmissing
7rotationsProgrammableRotationGateArrayBase-missingmissingmissingmissing
65rotationsQvrInterface-missingmissingmissingmissing
217rotationsQvrPhaseGradientqvr_phase_gradientpasspasspasspass
218rotationsQvrZPowqvr_zpowpasspassfailpass
4state_preparationPRGAViaPhaseGradient-missingmissingmissingmissing
219state_preparationPrepareUniformSuperpositionc_prep_uniformpasspassunverifiedpass
220state_preparationPrepareUniformSuperpositionprep_uniformpasspassunverifiedpass
221state_preparationStatePreparationAliasSamplingstate_prep_aliaspasspassunverifiedpass
222state_preparationStatePreparationViaRotationsstate_prep_via_rotationpasspassunverifiedpass
223swap_networkCSwapApproxapprox_cswap_largepasspasspasspass
224swap_networkCSwapApproxapprox_cswap_smallpasspasspasspass
225swap_networkCSwapApproxapprox_cswap_symbpassnaunverifiedpass
226swap_networkMultiplexedCSwapmultiplexed_cswappasspasspasspass
227swap_networkSwapWithZeroswzpasspasspasspass
228swap_networkSwapWithZeroswz_smallpasspasspasspass
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "show_bloq_report_card(df)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a6307cc0-96d2-42a4-93d2-6eaf5c338b54", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/dev_tools/qualtran_dev_tools/bloq_finder.py b/dev_tools/qualtran_dev_tools/bloq_finder.py index e0b0d12b4..f0d3c3a3a 100644 --- a/dev_tools/qualtran_dev_tools/bloq_finder.py +++ b/dev_tools/qualtran_dev_tools/bloq_finder.py @@ -121,10 +121,14 @@ def get_bloq_examples() -> List[BloqExample]: bloqs_root = reporoot / 'qualtran/bloqs' paths = get_bloq_module_paths(bloqs_root) + # These examples are too large to run. + REJECTED_BEXAMPLES = set(["qubitization_qpe_hubbard_model_large","qubitization_qpe_hubbard_model_small"]) + bexamples: List[BloqExample] = [] for path in paths: for modname, name, be in modpath_to_bloq_exs(path): - bexamples.append(be) + if be.name not in REJECTED_BEXAMPLES: + bexamples.append(be) return bexamples diff --git a/dev_tools/qualtran_dev_tools/bloq_report_card.py b/dev_tools/qualtran_dev_tools/bloq_report_card.py index 14366c22f..c0c54d6a4 100644 --- a/dev_tools/qualtran_dev_tools/bloq_report_card.py +++ b/dev_tools/qualtran_dev_tools/bloq_report_card.py @@ -82,6 +82,7 @@ def record_for_class_with_no_examples(k: Type[Bloq]) -> Dict[str, Any]: def record_for_bloq_example(be: BloqExample) -> Dict[str, Any]: + print(be.name) return { 'bloq_cls': be.bloq_cls.__name__, 'package': _get_package(be.bloq_cls), @@ -102,6 +103,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: @@ -110,7 +112,7 @@ def get_bloq_report_card( records = [] missing_bclasses = bloq_classes_with_no_examples(bclasses, bexamples) records.extend(record_for_class_with_no_examples(k) for k in missing_bclasses) - records.extend(record_for_bloq_example(be) for be in bexamples) + records.extend(record_for_bloq_example(be) for be in bexamples if be.name) df = pd.DataFrame(records) df['package'] = df['package'].str.removeprefix(package_prefix) From ffba71296eeed05e00d1ab7c69cb71a3cac7ab6c Mon Sep 17 00:00:00 2001 From: local_linix Date: Tue, 2 Apr 2024 16:02:13 -0700 Subject: [PATCH 14/34] Remove qpe_hubbard_model tests The qpe_hubbard_model is too large to test and causes developer friction. We have disabled the tests for now --- dev_tools/qualtran_dev_tools/bloq_finder.py | 8 ++++- qualtran/protos/bloq_pb2.py | 35 +++++++++++---------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/dev_tools/qualtran_dev_tools/bloq_finder.py b/dev_tools/qualtran_dev_tools/bloq_finder.py index e0b0d12b4..eaef0f161 100644 --- a/dev_tools/qualtran_dev_tools/bloq_finder.py +++ b/dev_tools/qualtran_dev_tools/bloq_finder.py @@ -121,10 +121,16 @@ def get_bloq_examples() -> List[BloqExample]: bloqs_root = reporoot / 'qualtran/bloqs' paths = get_bloq_module_paths(bloqs_root) + # These examples are too large to run. + REJECTED_BEXAMPLES = set( + ["qubitization_qpe_hubbard_model_large", "qubitization_qpe_hubbard_model_small"] + ) + bexamples: List[BloqExample] = [] for path in paths: for modname, name, be in modpath_to_bloq_exs(path): - bexamples.append(be) + if be.name not in REJECTED_BEXAMPLES: + bexamples.append(be) return bexamples diff --git a/qualtran/protos/bloq_pb2.py b/qualtran/protos/bloq_pb2.py index c8b631096..bec27c2e7 100644 --- a/qualtran/protos/bloq_pb2.py +++ b/qualtran/protos/bloq_pb2.py @@ -17,9 +17,10 @@ from qualtran.protos import registers_pb2 as qualtran_dot_protos_dot_registers__pb2 from qualtran.protos import data_types_pb2 as qualtran_dot_protos_dot_data__types__pb2 from qualtran.protos import ctrl_spec_pb2 as qualtran_dot_protos_dot_ctrl__spec__pb2 +from qualtran.protos import sympy_pb2 as qualtran_dot_protos_dot_sympy__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1aqualtran/protos/bloq.proto\x12\x08qualtran\x1a!qualtran/protos/annotations.proto\x1a\x1aqualtran/protos/args.proto\x1a\x1fqualtran/protos/registers.proto\x1a qualtran/protos/data_types.proto\x1a\x1fqualtran/protos/ctrl_spec.proto\"\x95\x03\n\x07\x42loqArg\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x11\n\x07int_val\x18\x02 \x01(\x03H\x00\x12\x13\n\tfloat_val\x18\x03 \x01(\x01H\x00\x12\x14\n\nstring_val\x18\x04 \x01(\tH\x00\x12\x14\n\nsympy_expr\x18\x05 \x01(\tH\x00\x12$\n\x07ndarray\x18\x06 \x01(\x0b\x32\x11.qualtran.NDArrayH\x00\x12\x11\n\x07subbloq\x18\x07 \x01(\x05H\x00\x12\x18\n\x0e\x63irq_json_gzip\x18\x08 \x01(\x0cH\x00\x12)\n\nqdata_type\x18\t \x01(\x0b\x32\x13.qualtran.QDataTypeH\x00\x12&\n\x08register\x18\n \x01(\x0b\x32\x12.qualtran.RegisterH\x00\x12(\n\tregisters\x18\x0b \x01(\x0b\x32\x13.qualtran.RegistersH\x00\x12\'\n\tctrl_spec\x18\x0c \x01(\x0b\x32\x12.qualtran.CtrlSpecH\x00\x12(\n\x0b\x63omplex_val\x18\r \x01(\x0b\x32\x11.qualtran.ComplexH\x00\x42\x05\n\x03val\"\xe8\x02\n\x0b\x42loqLibrary\x12\x0c\n\x04name\x18\x01 \x01(\t\x12:\n\x05table\x18\x02 \x03(\x0b\x32+.qualtran.BloqLibrary.BloqWithDecomposition\x1a\x8e\x02\n\x15\x42loqWithDecomposition\x12\x0f\n\x07\x62loq_id\x18\x01 \x01(\x05\x12+\n\rdecomposition\x18\x02 \x03(\x0b\x32\x14.qualtran.Connection\x12P\n\x0b\x62loq_counts\x18\x03 \x03(\x0b\x32;.qualtran.BloqLibrary.BloqWithDecomposition.BloqCountsEntry\x12\x1c\n\x04\x62loq\x18\x04 \x01(\x0b\x32\x0e.qualtran.Bloq\x1aG\n\x0f\x42loqCountsEntry\x12\x0b\n\x03key\x18\x01 \x01(\x05\x12#\n\x05value\x18\x02 \x01(\x0b\x32\x14.qualtran.IntOrSympy:\x02\x38\x01\"\x8a\x01\n\x04\x42loq\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x1f\n\x04\x61rgs\x18\x02 \x03(\x0b\x32\x11.qualtran.BloqArg\x12&\n\tregisters\x18\x03 \x01(\x0b\x32\x13.qualtran.Registers\x12+\n\x0ct_complexity\x18\x04 \x01(\x0b\x32\x15.qualtran.TComplexity\"4\n\x0c\x42loqInstance\x12\x13\n\x0binstance_id\x18\x01 \x01(\x05\x12\x0f\n\x07\x62loq_id\x18\x02 \x01(\x05\"\x8d\x01\n\x06Soquet\x12/\n\rbloq_instance\x18\x01 \x01(\x0b\x32\x16.qualtran.BloqInstanceH\x00\x12\x14\n\ndangling_t\x18\x02 \x01(\tH\x00\x12$\n\x08register\x18\x03 \x01(\x0b\x32\x12.qualtran.Register\x12\r\n\x05index\x18\x04 \x03(\x05\x42\x07\n\x05\x62inst\"M\n\nConnection\x12\x1e\n\x04left\x18\x01 \x01(\x0b\x32\x10.qualtran.Soquet\x12\x1f\n\x05right\x18\x02 \x01(\x0b\x32\x10.qualtran.Soquetb\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1aqualtran/protos/bloq.proto\x12\x08qualtran\x1a!qualtran/protos/annotations.proto\x1a\x1aqualtran/protos/args.proto\x1a\x1fqualtran/protos/registers.proto\x1a qualtran/protos/data_types.proto\x1a\x1fqualtran/protos/ctrl_spec.proto\x1a\x1bqualtran/protos/sympy.proto\"\xa5\x03\n\x07\x42loqArg\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x11\n\x07int_val\x18\x02 \x01(\x03H\x00\x12\x13\n\tfloat_val\x18\x03 \x01(\x01H\x00\x12\x14\n\nstring_val\x18\x04 \x01(\tH\x00\x12$\n\nsympy_expr\x18\x05 \x01(\x0b\x32\x0e.qualtran.TermH\x00\x12$\n\x07ndarray\x18\x06 \x01(\x0b\x32\x11.qualtran.NDArrayH\x00\x12\x11\n\x07subbloq\x18\x07 \x01(\x05H\x00\x12\x18\n\x0e\x63irq_json_gzip\x18\x08 \x01(\x0cH\x00\x12)\n\nqdata_type\x18\t \x01(\x0b\x32\x13.qualtran.QDataTypeH\x00\x12&\n\x08register\x18\n \x01(\x0b\x32\x12.qualtran.RegisterH\x00\x12(\n\tregisters\x18\x0b \x01(\x0b\x32\x13.qualtran.RegistersH\x00\x12\'\n\tctrl_spec\x18\x0c \x01(\x0b\x32\x12.qualtran.CtrlSpecH\x00\x12(\n\x0b\x63omplex_val\x18\r \x01(\x0b\x32\x11.qualtran.ComplexH\x00\x42\x05\n\x03val\"\xe8\x02\n\x0b\x42loqLibrary\x12\x0c\n\x04name\x18\x01 \x01(\t\x12:\n\x05table\x18\x02 \x03(\x0b\x32+.qualtran.BloqLibrary.BloqWithDecomposition\x1a\x8e\x02\n\x15\x42loqWithDecomposition\x12\x0f\n\x07\x62loq_id\x18\x01 \x01(\x05\x12+\n\rdecomposition\x18\x02 \x03(\x0b\x32\x14.qualtran.Connection\x12P\n\x0b\x62loq_counts\x18\x03 \x03(\x0b\x32;.qualtran.BloqLibrary.BloqWithDecomposition.BloqCountsEntry\x12\x1c\n\x04\x62loq\x18\x04 \x01(\x0b\x32\x0e.qualtran.Bloq\x1aG\n\x0f\x42loqCountsEntry\x12\x0b\n\x03key\x18\x01 \x01(\x05\x12#\n\x05value\x18\x02 \x01(\x0b\x32\x14.qualtran.IntOrSympy:\x02\x38\x01\"\x8a\x01\n\x04\x42loq\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x1f\n\x04\x61rgs\x18\x02 \x03(\x0b\x32\x11.qualtran.BloqArg\x12&\n\tregisters\x18\x03 \x01(\x0b\x32\x13.qualtran.Registers\x12+\n\x0ct_complexity\x18\x04 \x01(\x0b\x32\x15.qualtran.TComplexity\"4\n\x0c\x42loqInstance\x12\x13\n\x0binstance_id\x18\x01 \x01(\x05\x12\x0f\n\x07\x62loq_id\x18\x02 \x01(\x05\"\x8d\x01\n\x06Soquet\x12/\n\rbloq_instance\x18\x01 \x01(\x0b\x32\x16.qualtran.BloqInstanceH\x00\x12\x14\n\ndangling_t\x18\x02 \x01(\tH\x00\x12$\n\x08register\x18\x03 \x01(\x0b\x32\x12.qualtran.Register\x12\r\n\x05index\x18\x04 \x03(\x05\x42\x07\n\x05\x62inst\"M\n\nConnection\x12\x1e\n\x04left\x18\x01 \x01(\x0b\x32\x10.qualtran.Soquet\x12\x1f\n\x05right\x18\x02 \x01(\x0b\x32\x10.qualtran.Soquetb\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) @@ -28,20 +29,20 @@ DESCRIPTOR._options = None _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION_BLOQCOUNTSENTRY']._options = None _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION_BLOQCOUNTSENTRY']._serialized_options = b'8\001' - _globals['_BLOQARG']._serialized_start=204 - _globals['_BLOQARG']._serialized_end=609 - _globals['_BLOQLIBRARY']._serialized_start=612 - _globals['_BLOQLIBRARY']._serialized_end=972 - _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION']._serialized_start=702 - _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION']._serialized_end=972 - _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION_BLOQCOUNTSENTRY']._serialized_start=901 - _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION_BLOQCOUNTSENTRY']._serialized_end=972 - _globals['_BLOQ']._serialized_start=975 - _globals['_BLOQ']._serialized_end=1113 - _globals['_BLOQINSTANCE']._serialized_start=1115 - _globals['_BLOQINSTANCE']._serialized_end=1167 - _globals['_SOQUET']._serialized_start=1170 - _globals['_SOQUET']._serialized_end=1311 - _globals['_CONNECTION']._serialized_start=1313 - _globals['_CONNECTION']._serialized_end=1390 + _globals['_BLOQARG']._serialized_start=233 + _globals['_BLOQARG']._serialized_end=654 + _globals['_BLOQLIBRARY']._serialized_start=657 + _globals['_BLOQLIBRARY']._serialized_end=1017 + _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION']._serialized_start=747 + _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION']._serialized_end=1017 + _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION_BLOQCOUNTSENTRY']._serialized_start=946 + _globals['_BLOQLIBRARY_BLOQWITHDECOMPOSITION_BLOQCOUNTSENTRY']._serialized_end=1017 + _globals['_BLOQ']._serialized_start=1020 + _globals['_BLOQ']._serialized_end=1158 + _globals['_BLOQINSTANCE']._serialized_start=1160 + _globals['_BLOQINSTANCE']._serialized_end=1212 + _globals['_SOQUET']._serialized_start=1215 + _globals['_SOQUET']._serialized_end=1356 + _globals['_CONNECTION']._serialized_start=1358 + _globals['_CONNECTION']._serialized_end=1435 # @@protoc_insertion_point(module_scope) From 97fcd1304390333f5918d40977175ab1fa7d81b2 Mon Sep 17 00:00:00 2001 From: local_linix Date: Tue, 2 Apr 2024 16:07:50 -0700 Subject: [PATCH 15/34] Remove qpe_hubbard tests These tests are very large and will cause problems when running. These tests are now disabled. --- dev_tools/qualtran_dev_tools/bloq_finder.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dev_tools/qualtran_dev_tools/bloq_finder.py b/dev_tools/qualtran_dev_tools/bloq_finder.py index f0d3c3a3a..eaef0f161 100644 --- a/dev_tools/qualtran_dev_tools/bloq_finder.py +++ b/dev_tools/qualtran_dev_tools/bloq_finder.py @@ -122,7 +122,9 @@ def get_bloq_examples() -> List[BloqExample]: paths = get_bloq_module_paths(bloqs_root) # These examples are too large to run. - REJECTED_BEXAMPLES = set(["qubitization_qpe_hubbard_model_large","qubitization_qpe_hubbard_model_small"]) + REJECTED_BEXAMPLES = set( + ["qubitization_qpe_hubbard_model_large", "qubitization_qpe_hubbard_model_small"] + ) bexamples: List[BloqExample] = [] for path in paths: From 16d988bd3d8a67f779a0d078893b0992599378e9 Mon Sep 17 00:00:00 2001 From: local_linix Date: Tue, 2 Apr 2024 16:17:11 -0700 Subject: [PATCH 16/34] Cleanup branch --- Untitled.ipynb | 63 - Untitled1.ipynb | 2604 ----------------- .../qualtran_dev_tools/bloq_report_card.py | 4 +- 3 files changed, 1 insertion(+), 2670 deletions(-) delete mode 100644 Untitled.ipynb delete mode 100644 Untitled1.ipynb diff --git a/Untitled.ipynb b/Untitled.ipynb deleted file mode 100644 index be9b8cf66..000000000 --- a/Untitled.ipynb +++ /dev/null @@ -1,63 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 6, - "id": "1a96f9e5-2094-48ff-867b-9b98e20cf314", - "metadata": {}, - "outputs": [], - "source": [ - "from dev_tools.qualtran_dev_tools.bloq_report_card import get_bloq_report_card, show_bloq_report_card" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b8ce3d39-3972-42ae-b167-e4ed6241ba1c", - "metadata": {}, - "outputs": [], - "source": [ - "df = get_bloq_report_card()\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "79ab63fe-1b60-4b38-a2c6-42e89c9a1293", - "metadata": {}, - "outputs": [], - "source": [ - "print(\"hello\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "01f2964e-90c8-4c75-8969-f31e65557ed2", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/Untitled1.ipynb b/Untitled1.ipynb deleted file mode 100644 index c9aa22dc5..000000000 --- a/Untitled1.ipynb +++ /dev/null @@ -1,2604 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "355be5a3-6919-4f2b-a6a3-47758a0c9f50", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "hello world\n" - ] - } - ], - "source": [ - "print(\"hello world\")" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "aa81a78a-e308-4ea9-9a3a-29ff1cb27bb5", - "metadata": {}, - "outputs": [], - "source": [ - "from dev_tools.qualtran_dev_tools.bloq_report_card import get_bloq_report_card, show_bloq_report_card" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "90ea5580-ab8f-4568-ab74-059459f22a02", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "add_k_large\n", - "add_k_small\n", - "add_k_symb\n", - "add_large\n", - "add_oop_large\n", - "add_oop_small\n", - "add_oop_symb\n", - "add_small\n", - "add_symb\n", - "simple_add_k_large\n", - "simple_add_k_small\n", - "bi_qubits_mixer\n", - "eq_k\n", - "greater_than\n", - "gt_k\n", - "leq\n", - "leq_symb\n", - "lt_k\n", - "lt_k_symb\n", - "sq_cmp\n", - "signed_to_twos\n", - "to_contg_index\n", - "multiply_two_reals\n", - "plus_equal_product\n", - "product\n", - "scale_int_by_real\n", - "square\n", - "square_real_number\n", - "sum_of_squares\n", - "bitonic_sort\n", - "cmp_symb\n", - "cnot\n", - "global_phase\n", - "hadamard\n", - "rx\n", - "ry\n", - "rz\n", - "x_pow\n", - "y_pow\n", - "z_pow\n", - "s_gate\n", - "hadamard\n", - "su2_rotation_gate\n", - "t_gate\n", - "cswap_large\n", - "cswap_small\n", - "cswap_symb\n", - "swap_small\n", - "t_gate\n", - "toffoli\n", - "minus_effect\n", - "minus_state\n", - "plus_effect\n", - "plus_state\n", - "int_effect\n", - "int_state\n", - "one_effect\n", - "one_state\n", - "zero_effect\n", - "zero_state\n", - "zgate\n", - "black_box_block_bloq\n", - "black_box_prepare\n", - "black_box_select\n", - "chebyshev_poly\n", - "df_block_encoding\n", - "df_one_body\n", - "indexed_data\n", - "prep_inner\n", - "prep_outer\n", - "prepare_t\n", - "prepare_uv\n", - "prep_mu_proj\n", - "prep_nu_proj\n", - "prep_power_two_proj\n", - "prep_t_proj\n", - "prep_uv_proj\n", - "prep_first_quant\n", - "sel_first_quant\n", - "sel_t_proj\n", - "sel_uv_proj\n", - "prep_first_quant\n", - "sel_first_quant\n", - "select_t\n", - "select_uv\n", - "prep_inner\n", - "prep_outer\n", - "select\n", - "sf_block_encoding\n", - "sf_one_body\n", - "prep_sparse\n", - "sel_sparse\n", - "thc_prep\n", - "thc_uni\n", - "thc_sel\n", - "nr_inv_sqrt\n", - "poly_inv_sqrt\n", - "kinetic_energy\n", - "pair_potential\n", - "potential_energy\n", - "qvr\n", - "hopping_tile\n", - "plaquette\n", - "interaction\n", - "ising_x\n", - "ising_zz\n", - "trott_unitary\n", - "qrom_multi_data\n", - "qrom_multi_dim\n", - "qrom_small\n", - "modexp\n", - "modexp_small\n", - "modexp_symb\n", - "modmul\n", - "modmul_symb\n", - "and_bloq\n", - "multi_and\n", - "c_multi_not\n", - "c_multi_not_symb\n", - "ccpauli\n", - "apply_z_to_odd\n", - "select_pauli_lcu\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/home/linux_environment/miniconda3/envs/quantum/lib/python3.10/site-packages/sympy/core/function.py:297: SymPyDeprecationWarning: \n", - "\n", - "The string fallback in sympify() is deprecated.\n", - "\n", - "To explicitly convert the string form of an object, use\n", - "sympify(str(obj)). To add define sympify behavior on custom\n", - "objects, use sympy.core.sympify.converter or define obj._sympy_\n", - "(see the sympify() docstring).\n", - "\n", - "sympify() performed the string fallback resulting in the following string:\n", - "\n", - "''\n", - "\n", - "See https://docs.sympy.org/latest/explanation/active-deprecations.html#deprecated-sympify-string-fallback\n", - "for details.\n", - "\n", - "This has been deprecated since SymPy version 1.6. It\n", - "will be removed in a future version of SymPy.\n", - "\n", - " args = list(map(sympify, args))\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "lp_resource_state_small\n", - "lp_resource_state_symbolic\n", - "lprs_interim_prep\n", - "textbook_qpe_from_precision_and_delta\n", - "textbook_qpe_from_standard_deviation_eps\n", - "textbook_qpe_small\n", - "textbook_qpe_using_m_bits\n", - "approximate_qft_from_epsilon\n", - "approximate_qft_small\n", - "two_bit_ffft\n", - "walk_op\n", - "reflection\n", - "square_via_phase_gradient\n", - "square_via_zpow_phasing\n", - "qvr_phase_gradient\n", - "qvr_zpow\n", - "c_prep_uniform\n", - "prep_uniform\n", - "state_prep_alias\n", - "state_prep_via_rotation\n", - "approx_cswap_large\n", - "approx_cswap_small\n", - "approx_cswap_symb\n", - "multiplexed_cswap\n", - "swz\n", - "swz_small\n" - ] - } - ], - "source": [ - "df = get_bloq_report_card()" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "3e281f1b-6067-4cf7-aac3-e490ec849cd7", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 packagebloq_clsnamemakedecompcountsserialize
84arithmeticAddadd_largepasspassfailpass
88arithmeticAddadd_smallpasspassfailpass
89arithmeticAddadd_symbpassnaunverifiedpass
81arithmeticAddConstantModadd_k_largepassmissingunverifiedpass
82arithmeticAddConstantModadd_k_smallpassmissingunverifiedpass
83arithmeticAddConstantModadd_k_symbpassnaunverifiedpass
92arithmeticBiQubitsMixerbi_qubits_mixerpasspassunverifiedpass
110arithmeticBitonicSortbitonic_sortpassmissingmissingpass
111arithmeticComparatorcmp_symbpassmissingmissingpass
93arithmeticEqualsAConstanteq_kpassmissingunverifiedpass
94arithmeticGreaterThangreater_thanpassmissingunverifiedpass
95arithmeticGreaterThanConstantgt_kpassmissingunverifiedpass
53arithmeticHammingWeightCompute-missingmissingmissingmissing
98arithmeticLessThanConstantlt_kpasspassunverifiedpass
99arithmeticLessThanConstantlt_k_symbpassnamissingpass
96arithmeticLessThanEqualleqpasspassunverifiedpass
97arithmeticLessThanEqualleq_symbpassnamissingpass
59arithmeticLinearDepthGreaterThan-missingmissingmissingmissing
103arithmeticMultiplyTwoRealsmultiply_two_realspassmissingunverifiedpass
85arithmeticOutOfPlaceAdderadd_oop_largepasspassfailpass
86arithmeticOutOfPlaceAdderadd_oop_smallpasspassfailpass
87arithmeticOutOfPlaceAdderadd_oop_symbpassnaunverifiedpass
104arithmeticPlusEqualProductplus_equal_productpassmissingunverifiedpass
105arithmeticProductproductpassmissingunverifiedpass
106arithmeticScaleIntByRealscale_int_by_realpassmissingunverifiedpass
101arithmeticSignedIntegerToTwosComplementsigned_to_twospassmissingunverifiedpass
90arithmeticSimpleAddConstantsimple_add_k_largepasspassunverifiedpass
91arithmeticSimpleAddConstantsimple_add_k_smallpasspassunverifiedpass
100arithmeticSingleQubitComparesq_cmppasspassunverifiedpass
107arithmeticSquaresquarepassmissingunverifiedpass
108arithmeticSquareRealNumbersquare_real_numberpassmissingunverifiedpass
109arithmeticSumOfSquaressum_of_squarespassmissingunverifiedpass
102arithmeticToContiguousIndexto_contg_indexpassmissingunverifiedpass
112basic_gatesCNOTcnotpassnamissingpass
125basic_gatesCSwapcswap_largepasspasspasspass
126basic_gatesCSwapcswap_smallpasspasspasspass
127basic_gatesCSwapcswap_symbpassnaunverifiedpass
23basic_gatesCZPowGate-missingmissingmissingmissing
113basic_gatesGlobalPhaseglobal_phasepassnamissingpass
114basic_gatesHadamardhadamardpassnamissingpass
135basic_gatesIntEffectint_effectpasspassfailpass
136basic_gatesIntStateint_statepasspassfailpass
131basic_gatesMinusEffectminus_effectpassmissingmissingpass
132basic_gatesMinusStateminus_statepassmissingmissingpass
1basic_gatesOnEach-missingmissingmissingmissing
137basic_gatesOneEffectone_effectpassnamissingpass
138basic_gatesOneStateone_statepassnamissingpass
133basic_gatesPlusEffectplus_effectpassmissingmissingpass
134basic_gatesPlusStateplus_statepassmissingmissingpass
115basic_gatesRxrxpassnamissingpass
116basic_gatesRyrypassnamissingpass
117basic_gatesRzrzpassnamissingpass
121basic_gatesSGates_gatepassmissingmissingpass
122basic_gatesSU2RotationGatehadamardpasspassunverifiedpass
123basic_gatesSU2RotationGatesu2_rotation_gatepasspassunverifiedpass
124basic_gatesSU2RotationGatet_gatepasspassunverifiedpass
128basic_gatesSwapswap_smallpasspasspasspass
129basic_gatesTGatet_gatepassmissingmissingpass
130basic_gatesToffolitoffolipassmissingunverifiedpass
22basic_gatesTwoBitCSwap-missingmissingmissingmissing
26basic_gatesTwoBitSwap-missingmissingmissingmissing
45basic_gatesXGate-missingmissingmissingmissing
118basic_gatesXPowGatex_powpassnamissingpass
54basic_gatesYGate-missingmissingmissingmissing
119basic_gatesYPowGatey_powpassnamissingpass
141basic_gatesZGatezgatepassnamissingpass
120basic_gatesZPowGatez_powpassnamissingpass
139basic_gatesZeroEffectzero_effectpassnamissingpass
140basic_gatesZeroStatezero_statepassnamissingpass
15chemistryApplyControlledZs-missingmissingmissingmissing
78chemistryQROAM-missingmissingmissingmissing
5chemistryQROAMTwoRegs-missingmissingmissingmissing
146chemistry.dfDoubleFactorizationBlockEncodingdf_block_encodingpasspassunverifiedpass
147chemistry.dfDoubleFactorizationOneBodydf_one_bodypasspassfailpass
149chemistry.dfInnerPrepareDoubleFactorizationprep_innerpassmissingunverifiedpass
150chemistry.dfOuterPrepareDoubleFactorizationprep_outerpassmissingunverifiedpass
148chemistry.dfOutputIndexedDataindexed_datapassmissingunverifiedpass
55chemistry.dfProgRotGateArray-missingmissingmissingmissing
48chemistry.pbc.first_quantizationApplyNuclearPhase-missingmissingmissingmissing
76chemistry.pbc.first_quantizationFlagZeroAsFailure-missingmissingmissingmissing
2chemistry.pbc.first_quantizationMultiplexedCSwap3D-missingmissingmissingmissing
162chemistry.pbc.first_quantizationPrepareFirstQuantizationprep_first_quantpasspassunverifiedpass
50chemistry.pbc.first_quantizationPrepareMuUnaryEncodedOneHot-missingmissingmissingmissing
29chemistry.pbc.first_quantizationPrepareNuState-missingmissingmissingmissing
13chemistry.pbc.first_quantizationPrepareNuSuperPositionState-missingmissingmissingmissing
51chemistry.pbc.first_quantizationPreparePowerTwoState-missingmissingmissingmissing
151chemistry.pbc.first_quantizationPrepareTFirstQuantizationprepare_tpasspassfailpass
63chemistry.pbc.first_quantizationPrepareTUVSuperpositions-missingmissingmissingmissing
152chemistry.pbc.first_quantizationPrepareUVFirstQuantizationprepare_uvpasspasspasspass
66chemistry.pbc.first_quantizationPrepareZetaState-missingmissingmissingmissing
163chemistry.pbc.first_quantizationSelectFirstQuantizationsel_first_quantpasspassunverifiedpass
164chemistry.pbc.first_quantizationSelectTFirstQuantizationselect_tpassmissingunverifiedpass
165chemistry.pbc.first_quantizationSelectUVFirstQuantizationselect_uvpassmissingunverifiedpass
30chemistry.pbc.first_quantizationTestNuInequality-missingmissingmissingmissing
49chemistry.pbc.first_quantizationTestNuLessThanMu-missingmissingmissingmissing
11chemistry.pbc.first_quantizationUniformSuperpostionIJFirstQuantization-missingmissingmissingmissing
25chemistry.pbc.first_quantizationUniformSuperpostionIJFirstQuantization-missingmissingmissingmissing
60chemistry.pbc.first_quantization.projectileControlledMultiplexedCSwap3D-missingmissingmissingmissing
158chemistry.pbc.first_quantization.projectilePrepareFirstQuantizationWithProjprep_first_quantpasspassunverifiedpass
153chemistry.pbc.first_quantization.projectilePrepareMuUnaryEncodedOneHotWithProjprep_mu_projpassmissingunverifiedpass
154chemistry.pbc.first_quantization.projectilePrepareNuStateWithProjprep_nu_projpasspassfailpass
155chemistry.pbc.first_quantization.projectilePreparePowerTwoStateWithProjprep_power_two_projpassmissingunverifiedpass
156chemistry.pbc.first_quantization.projectilePrepareTFirstQuantizationWithProjprep_t_projpassmissingunverifiedpass
70chemistry.pbc.first_quantization.projectilePrepareTUVSuperpositions-missingmissingmissingmissing
157chemistry.pbc.first_quantization.projectilePrepareUVFirstQuantizationWithProjprep_uv_projpasspasspasspass
159chemistry.pbc.first_quantization.projectileSelectFirstQuantizationWithProjsel_first_quantpasspassunverifiedpass
160chemistry.pbc.first_quantization.projectileSelectTFirstQuantizationWithProjsel_t_projpassmissingunverifiedpass
161chemistry.pbc.first_quantization.projectileSelectUVFirstQuantizationWithProjsel_uv_projpassmissingunverifiedpass
166chemistry.sfInnerPrepareSingleFactorizationprep_innerpassmissingunverifiedpass
167chemistry.sfOuterPrepareSingleFactorizationprep_outerpassmissingunverifiedpass
168chemistry.sfSelectSingleFactorizationselectpassmissingunverifiedpass
169chemistry.sfSingleFactorizationBlockEncodingsf_block_encodingpasspassunverifiedpass
170chemistry.sfSingleFactorizationOneBodysf_one_bodypasspasspasspass
171chemistry.sparsePrepareSparseprep_sparsepasspassfailfail
172chemistry.sparseSelectSparsesel_sparsepasspassfailpass
173chemistry.thcPrepareTHCthc_preppasspassfailfail
175chemistry.thcSelectTHCthc_selpasspassunverifiedpass
43chemistry.thcTHCRotations-missingmissingmissingmissing
174chemistry.thcUniformSuperpositionTHCthc_unipasspassunverifiedpass
187chemistry.trotterTrotterizedUnitarytrott_unitarypasspassunverifiedfail
178chemistry.trotter.grid_hamKineticEnergykinetic_energypasspassunverifiedpass
176chemistry.trotter.grid_hamNewtonRaphsonApproxInverseSquareRootnr_inv_sqrtpassmissingunverifiedpass
179chemistry.trotter.grid_hamPairPotentialpair_potentialpasspassunverifiedpass
177chemistry.trotter.grid_hamPolynmomialEvaluationInverseSquareRootpoly_inv_sqrtpassmissingunverifiedpass
180chemistry.trotter.grid_hamPotentialEnergypotential_energypasspassunverifiedpass
181chemistry.trotter.grid_hamQuantumVariableRotationqvrpassmissingunverifiedpass
183chemistry.trotter.hubbardHoppingPlaquetteplaquettepassmissingunverifiedpass
182chemistry.trotter.hubbardHoppingTilehopping_tilepassmissingunverifiedpass
184chemistry.trotter.hubbardInteractioninteractionpassmissingunverifiedpass
185chemistry.trotter.isingIsingXUnitaryising_xpasspassunverifiedpass
186chemistry.trotter.isingIsingZZUnitaryising_zzpasspassunverifiedpass
188data_loadingQROMqrom_multi_datapasspassfailpass
189data_loadingQROMqrom_multi_dimpasspassfailpass
190data_loadingQROMqrom_smallpasspassfailpass
75data_loadingSelectSwapQROM-missingmissingmissingmissing
38factoringCtrlAddK-missingmissingmissingmissing
64factoringCtrlModAddK-missingmissingmissingmissing
194factoringCtrlModMulmodmulpasspasspasspass
195factoringCtrlModMulmodmul_symbpasspasspassfail
21factoringCtrlScaleModAdd-missingmissingmissingmissing
191factoringModExpmodexppasspasspassfail
192factoringModExpmodexp_smallpasspasspassfail
193factoringModExpmodexp_symbpassnaunverifiedfail
6factoringMontgomeryModAdd-missingmissingmissingmissing
79factoringMontgomeryModDbl-missingmissingmissingmissing
61factoringMontgomeryModNeg-missingmissingmissingmissing
67factoringMontgomeryModSub-missingmissingmissingmissing
41for_testingInteriorAlloc-missingmissingmissingmissing
73for_testingTestAtom-missingmissingmissingmissing
77for_testingTestBloqWithCallGraph-missingmissingmissingmissing
71for_testingTestBoundedQUInt-missingmissingmissingmissing
39for_testingTestCastToFrom-missingmissingmissingmissing
33for_testingTestIndependentParallelCombo-missingmissingmissingmissing
42for_testingTestMultiRegister-missingmissingmissingmissing
16for_testingTestMultiTypedRegister-missingmissingmissingmissing
74for_testingTestParallelCombo-missingmissingmissingmissing
28for_testingTestQFxp-missingmissingmissingmissing
32for_testingTestSerialCombo-missingmissingmissingmissing
3for_testingTestTwoBitOp-missingmissingmissingmissing
196mcmtAndand_bloqpasspasspasspass
197mcmtMultiAndmulti_andpasspasspasspass
200mcmtMultiControlPauliccpaulipasspasspasspass
12mcmtMultiControlX-missingmissingmissingmissing
198mcmtMultiTargetCNOTc_multi_notpasspassunverifiedpass
199mcmtMultiTargetCNOTc_multi_not_symbpassnamissingpass
69mean_estimationArcTan-missingmissingmissingmissing
46mean_estimationComplexPhaseOracle-missingmissingmissingmissing
37mean_estimationMeanEstimationOperator-missingmissingmissingmissing
201multiplexersApplyGateToLthQubitapply_z_to_oddpasspasspassfail
202multiplexersSelectPauliLCUselect_pauli_lcupasspasspassfail
68multiplexersSelectedMajoranaFermion-missingmissingmissingmissing
0multiplexersUnaryIterationGate-missingmissingmissingmissing
205phase_estimationLPRSInterimPreplprs_interim_preppasspassfailpass
203phase_estimationLPResourceStatelp_resource_state_smallpasspassfailpass
204phase_estimationLPResourceStatelp_resource_state_symbolicpassnaerrorfail
40phase_estimationQubitizationQPE-missingmissingmissingmissing
206phase_estimationTextbookQPEtextbook_qpe_from_precision_and_deltapassnaunverifiedfail
207phase_estimationTextbookQPEtextbook_qpe_from_standard_deviation_epspassnaunverifiedfail
208phase_estimationTextbookQPEtextbook_qpe_smallpasspassfailpass
209phase_estimationTextbookQPEtextbook_qpe_using_m_bitspassnaunverifiedfail
210qftApproximateQFTapproximate_qft_from_epsilonpasspassfailpass
211qftApproximateQFTapproximate_qft_smallpasspassfailpass
9qftQFTPhaseGradient-missingmissingmissingmissing
62qftQFTTextBook-missingmissingmissingmissing
212qftTwoBitFFFTtwo_bit_ffftpasspassfailpass
44qualtran.bloqsAllocate-missingmissingmissingmissing
17qualtran.bloqsArbitraryClifford-missingmissingmissingmissing
142qualtran.bloqsBlackBoxBlockEncodingblack_box_block_bloqpasspassunverifiedpass
143qualtran.bloqsBlackBoxPrepareblack_box_preparepasspassunverifiedpass
144qualtran.bloqsBlackBoxSelectblack_box_selectpasspassunverifiedpass
58qualtran.bloqsCast-missingmissingmissingmissing
145qualtran.bloqsChebyshevPolynomialchebyshev_polypasspasspasspass
52qualtran.bloqsFree-missingmissingmissingmissing
20qualtran.bloqsGeneralizedQSP-missingmissingmissingmissing
18qualtran.bloqsJoin-missingmissingmissingmissing
24qualtran.bloqsPartition-missingmissingmissingmissing
27qualtran.bloqsPower-missingmissingmissingmissing
80qualtran.bloqsPrepareHubbard-missingmissingmissingmissing
8qualtran.bloqsPrepareOracle-missingmissingmissingmissing
213qualtran.bloqsQubitizationWalkOperatorwalk_oppasspassunverifiedfail
214qualtran.bloqsReflectionreflectionpasspassfailpass
35qualtran.bloqsReflectionUsingPrepare-missingmissingmissingmissing
72qualtran.bloqsSelectHubbard-missingmissingmissingmissing
56qualtran.bloqsSelectOracle-missingmissingmissingmissing
19qualtran.bloqsSplit-missingmissingmissingmissing
47rotationsAddIntoPhaseGrad-missingmissingmissingmissing
57rotationsAddScaledValIntoPhaseReg-missingmissingmissingmissing
14rotationsHammingWeightPhasing-missingmissingmissingmissing
31rotationsHammingWeightPhasingViaPhaseGradient-missingmissingmissingmissing
10rotationsPhaseGradientState-missingmissingmissingmissing
34rotationsPhaseGradientUnitary-missingmissingmissingmissing
215rotationsPhasingViaCostFunctionsquare_via_phase_gradientpasspassunverifiedpass
216rotationsPhasingViaCostFunctionsquare_via_zpow_phasingpasspassunverifiedpass
36rotationsProgrammableRotationGateArray-missingmissingmissingmissing
7rotationsProgrammableRotationGateArrayBase-missingmissingmissingmissing
65rotationsQvrInterface-missingmissingmissingmissing
217rotationsQvrPhaseGradientqvr_phase_gradientpasspasspasspass
218rotationsQvrZPowqvr_zpowpasspassfailpass
4state_preparationPRGAViaPhaseGradient-missingmissingmissingmissing
219state_preparationPrepareUniformSuperpositionc_prep_uniformpasspassunverifiedpass
220state_preparationPrepareUniformSuperpositionprep_uniformpasspassunverifiedpass
221state_preparationStatePreparationAliasSamplingstate_prep_aliaspasspassunverifiedpass
222state_preparationStatePreparationViaRotationsstate_prep_via_rotationpasspassunverifiedpass
223swap_networkCSwapApproxapprox_cswap_largepasspasspasspass
224swap_networkCSwapApproxapprox_cswap_smallpasspasspasspass
225swap_networkCSwapApproxapprox_cswap_symbpassnaunverifiedpass
226swap_networkMultiplexedCSwapmultiplexed_cswappasspasspasspass
227swap_networkSwapWithZeroswzpasspasspasspass
228swap_networkSwapWithZeroswz_smallpasspasspasspass
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "show_bloq_report_card(df)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a6307cc0-96d2-42a4-93d2-6eaf5c338b54", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/dev_tools/qualtran_dev_tools/bloq_report_card.py b/dev_tools/qualtran_dev_tools/bloq_report_card.py index c0c54d6a4..14366c22f 100644 --- a/dev_tools/qualtran_dev_tools/bloq_report_card.py +++ b/dev_tools/qualtran_dev_tools/bloq_report_card.py @@ -82,7 +82,6 @@ def record_for_class_with_no_examples(k: Type[Bloq]) -> Dict[str, Any]: def record_for_bloq_example(be: BloqExample) -> Dict[str, Any]: - print(be.name) return { 'bloq_cls': be.bloq_cls.__name__, 'package': _get_package(be.bloq_cls), @@ -103,7 +102,6 @@ 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: @@ -112,7 +110,7 @@ def get_bloq_report_card( records = [] missing_bclasses = bloq_classes_with_no_examples(bclasses, bexamples) records.extend(record_for_class_with_no_examples(k) for k in missing_bclasses) - records.extend(record_for_bloq_example(be) for be in bexamples if be.name) + records.extend(record_for_bloq_example(be) for be in bexamples) df = pd.DataFrame(records) df['package'] = df['package'].str.removeprefix(package_prefix) From 391191e17db82d07dda36e1b4c362df25f969bb2 Mon Sep 17 00:00:00 2001 From: local_linix Date: Wed, 3 Apr 2024 16:54:07 -0700 Subject: [PATCH 17/34] Only remove the serialization tests from the large bloq.s Move the changes from bloq_finder.py to bloq_report_card.py. This way, only the serialization portion of the test is affected. --- dev_tools/qualtran_dev_tools/bloq_finder.py | 8 +------- dev_tools/qualtran_dev_tools/bloq_report_card.py | 8 +++++++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dev_tools/qualtran_dev_tools/bloq_finder.py b/dev_tools/qualtran_dev_tools/bloq_finder.py index eaef0f161..e0b0d12b4 100644 --- a/dev_tools/qualtran_dev_tools/bloq_finder.py +++ b/dev_tools/qualtran_dev_tools/bloq_finder.py @@ -121,16 +121,10 @@ def get_bloq_examples() -> List[BloqExample]: bloqs_root = reporoot / 'qualtran/bloqs' paths = get_bloq_module_paths(bloqs_root) - # These examples are too large to run. - REJECTED_BEXAMPLES = set( - ["qubitization_qpe_hubbard_model_large", "qubitization_qpe_hubbard_model_small"] - ) - bexamples: List[BloqExample] = [] for path in paths: for modname, name, be in modpath_to_bloq_exs(path): - if be.name not in REJECTED_BEXAMPLES: - bexamples.append(be) + bexamples.append(be) return bexamples diff --git a/dev_tools/qualtran_dev_tools/bloq_report_card.py b/dev_tools/qualtran_dev_tools/bloq_report_card.py index 14366c22f..9e0bebde3 100644 --- a/dev_tools/qualtran_dev_tools/bloq_report_card.py +++ b/dev_tools/qualtran_dev_tools/bloq_report_card.py @@ -102,6 +102,12 @@ def get_bloq_report_card( bexamples: Optional[Iterable[BloqExample]] = None, package_prefix: str = 'qualtran.bloqs.', ) -> pd.DataFrame: + + # These examples are too large to run. + REJECTED_BEXAMPLES = set( + ["qubitization_qpe_hubbard_model_large", "qubitization_qpe_hubbard_model_small"] + ) + if bclasses is None: bclasses = get_bloq_classes() if bexamples is None: @@ -110,7 +116,7 @@ def get_bloq_report_card( records = [] missing_bclasses = bloq_classes_with_no_examples(bclasses, bexamples) records.extend(record_for_class_with_no_examples(k) for k in missing_bclasses) - records.extend(record_for_bloq_example(be) for be in bexamples) + records.extend(record_for_bloq_example(be) for be in bexamples if be.name not in REJECTED_BEXAMPLES) df = pd.DataFrame(records) df['package'] = df['package'].str.removeprefix(package_prefix) From 32f849586b67427aecd9806431bcc11437bacffa Mon Sep 17 00:00:00 2001 From: local_linix Date: Wed, 3 Apr 2024 17:55:05 -0700 Subject: [PATCH 18/34] Address issues with failing sympy tests. Added support for fraction constant parameters. Fixed issue with cwap test assertion which expected sympy in the old string format. --- Untitled.ipynb | 48 +++++++++++++++++++++++++++++ qualtran/protos/sympy.proto | 8 ++++- qualtran/protos/sympy_pb2.py | 20 ++++++------ qualtran/protos/sympy_pb2.pyi | 31 ++++++++++++++++--- qualtran/serialization/bloq.py | 20 +++++++++--- qualtran/serialization/bloq_test.py | 4 +-- 6 files changed, 110 insertions(+), 21 deletions(-) create mode 100644 Untitled.ipynb diff --git a/Untitled.ipynb b/Untitled.ipynb new file mode 100644 index 000000000..480c52241 --- /dev/null +++ b/Untitled.ipynb @@ -0,0 +1,48 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "c895c2c6-ff65-46f0-b6ec-2d2b36a84d1e", + "metadata": {}, + "outputs": [], + "source": [ + "# Put this into dev_tools\n", + "from dev_tools.qualtran_dev_tools.bloq_report_card import get_bloq_report_card, show_bloq_report_card, record_for_bloq_example, check_bloq_example_serialize, get_bloq_examples\n", + "from qualtran.serialization.bloq import bloqs_from_proto, bloqs_to_proto\n", + "\n", + "df = get_bloq_report_card()\n", + "show_bloq_report_card(df)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ca34f824-b1ab-4620-bbb9-d2c8941dc324", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/qualtran/protos/sympy.proto b/qualtran/protos/sympy.proto index 3f89d75dd..1c54f1f5e 100644 --- a/qualtran/protos/sympy.proto +++ b/qualtran/protos/sympy.proto @@ -27,13 +27,19 @@ enum Function { } +// Represents a constant, rational number. +message Fraction { + int32 numerator = 1; + int32 denominator = 2; +} + // A single parameter of a sympy expression. message Parameter { oneof parameter { int32 const_int = 1; string symbol = 2; - // A constant that cannot be expressed by an integer or a division operation will be irrational. string const_irrat = 3; + Fraction const_rat = 4; } } diff --git a/qualtran/protos/sympy_pb2.py b/qualtran/protos/sympy_pb2.py index 8670d1bc2..bb0a30fb6 100644 --- a/qualtran/protos/sympy_pb2.py +++ b/qualtran/protos/sympy_pb2.py @@ -14,19 +14,21 @@ -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1bqualtran/protos/sympy.proto\x12\x08qualtran\"V\n\tParameter\x12\x13\n\tconst_int\x18\x01 \x01(\x05H\x00\x12\x10\n\x06symbol\x18\x02 \x01(\tH\x00\x12\x15\n\x0b\x63onst_irrat\x18\x03 \x01(\tH\x00\x42\x0b\n\tparameter\"^\n\x07Operand\x12\x1e\n\x04term\x18\x01 \x01(\x0b\x32\x0e.qualtran.TermH\x00\x12(\n\tparameter\x18\x02 \x01(\x0b\x32\x13.qualtran.ParameterH\x00\x42\t\n\x07operand\"Q\n\x04Term\x12$\n\x08\x66unction\x18\x01 \x01(\x0e\x32\x12.qualtran.Function\x12#\n\x08operands\x18\x02 \x03(\x0b\x32\x11.qualtran.Operand*J\n\x08\x46unction\x12\x08\n\x04NONE\x10\x00\x12\x0c\n\x08\x41\x44\x44ITION\x10\x01\x12\x12\n\x0eMULTIPLICATION\x10\x02\x12\t\n\x05POWER\x10\x03\x12\x07\n\x03MOD\x10\x04\x62\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1bqualtran/protos/sympy.proto\x12\x08qualtran\"2\n\x08\x46raction\x12\x11\n\tnumerator\x18\x01 \x01(\x05\x12\x13\n\x0b\x64\x65nominator\x18\x02 \x01(\x05\"\x7f\n\tParameter\x12\x13\n\tconst_int\x18\x01 \x01(\x05H\x00\x12\x10\n\x06symbol\x18\x02 \x01(\tH\x00\x12\x15\n\x0b\x63onst_irrat\x18\x03 \x01(\tH\x00\x12\'\n\tconst_rat\x18\x04 \x01(\x0b\x32\x12.qualtran.FractionH\x00\x42\x0b\n\tparameter\"^\n\x07Operand\x12\x1e\n\x04term\x18\x01 \x01(\x0b\x32\x0e.qualtran.TermH\x00\x12(\n\tparameter\x18\x02 \x01(\x0b\x32\x13.qualtran.ParameterH\x00\x42\t\n\x07operand\"Q\n\x04Term\x12$\n\x08\x66unction\x18\x01 \x01(\x0e\x32\x12.qualtran.Function\x12#\n\x08operands\x18\x02 \x03(\x0b\x32\x11.qualtran.Operand*J\n\x08\x46unction\x12\x08\n\x04NONE\x10\x00\x12\x0c\n\x08\x41\x44\x44ITION\x10\x01\x12\x12\n\x0eMULTIPLICATION\x10\x02\x12\t\n\x05POWER\x10\x03\x12\x07\n\x03MOD\x10\x04\x62\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'qualtran.protos.sympy_pb2', _globals) if _descriptor._USE_C_DESCRIPTORS == False: DESCRIPTOR._options = None - _globals['_FUNCTION']._serialized_start=308 - _globals['_FUNCTION']._serialized_end=382 - _globals['_PARAMETER']._serialized_start=41 - _globals['_PARAMETER']._serialized_end=127 - _globals['_OPERAND']._serialized_start=129 - _globals['_OPERAND']._serialized_end=223 - _globals['_TERM']._serialized_start=225 - _globals['_TERM']._serialized_end=306 + _globals['_FUNCTION']._serialized_start=401 + _globals['_FUNCTION']._serialized_end=475 + _globals['_FRACTION']._serialized_start=41 + _globals['_FRACTION']._serialized_end=91 + _globals['_PARAMETER']._serialized_start=93 + _globals['_PARAMETER']._serialized_end=220 + _globals['_OPERAND']._serialized_start=222 + _globals['_OPERAND']._serialized_end=316 + _globals['_TERM']._serialized_start=318 + _globals['_TERM']._serialized_end=399 # @@protoc_insertion_point(module_scope) diff --git a/qualtran/protos/sympy_pb2.pyi b/qualtran/protos/sympy_pb2.pyi index 98adbde6f..c9b1fd611 100644 --- a/qualtran/protos/sympy_pb2.pyi +++ b/qualtran/protos/sympy_pb2.pyi @@ -54,6 +54,26 @@ POWER: Function.ValueType # 3 MOD: Function.ValueType # 4 global___Function = Function +@typing_extensions.final +class Fraction(google.protobuf.message.Message): + """Represents a constant, rational number.""" + + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + NUMERATOR_FIELD_NUMBER: builtins.int + DENOMINATOR_FIELD_NUMBER: builtins.int + numerator: builtins.int + denominator: builtins.int + def __init__( + self, + *, + numerator: builtins.int = ..., + denominator: builtins.int = ..., + ) -> None: ... + def ClearField(self, field_name: typing_extensions.Literal["denominator", b"denominator", "numerator", b"numerator"]) -> None: ... + +global___Fraction = Fraction + @typing_extensions.final class Parameter(google.protobuf.message.Message): """A single parameter of a sympy expression.""" @@ -63,20 +83,23 @@ class Parameter(google.protobuf.message.Message): CONST_INT_FIELD_NUMBER: builtins.int SYMBOL_FIELD_NUMBER: builtins.int CONST_IRRAT_FIELD_NUMBER: builtins.int + CONST_RAT_FIELD_NUMBER: builtins.int const_int: builtins.int symbol: builtins.str const_irrat: builtins.str - """A constant that cannot be expressed by an integer or a division operation will be irrational.""" + @property + def const_rat(self) -> global___Fraction: ... def __init__( self, *, const_int: builtins.int = ..., symbol: builtins.str = ..., const_irrat: builtins.str = ..., + const_rat: global___Fraction | None = ..., ) -> None: ... - def HasField(self, field_name: typing_extensions.Literal["const_int", b"const_int", "const_irrat", b"const_irrat", "parameter", b"parameter", "symbol", b"symbol"]) -> builtins.bool: ... - def ClearField(self, field_name: typing_extensions.Literal["const_int", b"const_int", "const_irrat", b"const_irrat", "parameter", b"parameter", "symbol", b"symbol"]) -> None: ... - def WhichOneof(self, oneof_group: typing_extensions.Literal["parameter", b"parameter"]) -> typing_extensions.Literal["const_int", "symbol", "const_irrat"] | None: ... + def HasField(self, field_name: typing_extensions.Literal["const_int", b"const_int", "const_irrat", b"const_irrat", "const_rat", b"const_rat", "parameter", b"parameter", "symbol", b"symbol"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["const_int", b"const_int", "const_irrat", b"const_irrat", "const_rat", b"const_rat", "parameter", b"parameter", "symbol", b"symbol"]) -> None: ... + def WhichOneof(self, oneof_group: typing_extensions.Literal["parameter", b"parameter"]) -> typing_extensions.Literal["const_int", "symbol", "const_irrat", "const_rat"] | None: ... global___Parameter = Parameter diff --git a/qualtran/serialization/bloq.py b/qualtran/serialization/bloq.py index a3f0b43a5..923212ef6 100644 --- a/qualtran/serialization/bloq.py +++ b/qualtran/serialization/bloq.py @@ -20,7 +20,6 @@ import cirq import numpy as np import sympy -from sympy.parsing.sympy_parser import parse_expr from qualtran import ( Bloq, @@ -69,24 +68,32 @@ def _get_sympy_from_enum(enum: int): sympy_pb2.Function.POWER: sympy.core.power.Pow, sympy_pb2.Function.MOD: sympy.core.Mod, sympy_pb2.Function.NONE: None, - } - # DO NOT SUBMIT: Remove this line - if enum == sympy_pb2.Function.MULTIPLICATION: - print("here") + } return enum_to_sympy[enum] def _get_sympy_operand(expr: sympy.Expr): + + # Expression is a single variable. if isinstance(expr, sympy.core.symbol.Symbol): return sympy_pb2.Parameter(symbol=str(expr)) + + # Expression is an integer if issubclass(expr.__class__, sympy.core.numbers.Integer): result = expr.numerator if not isinstance(result, int): raise NotImplementedError(f"Sympy expression {str(expr)} cannot be serialized.") return sympy_pb2.Parameter(const_int=result) + + # Expression cannot be broken down further, but is a constant. if issubclass(expr.__class__, sympy.core.numbers.Number): + if isinstance(expr, sympy.core.numbers.Rational): + fraction = sympy_pb2.Fraction(numerator=expr.numerator, denominator=expr.denominator) + return sympy_pb2.Parameter(const_rat=fraction) + + # If it is not a rational number, then it must be an irrational constant. return sympy_pb2.Parameter(const_irrat=expr.name) @@ -114,6 +121,9 @@ def _get_parameter(operand): parameter = operand.parameter.const_int elif parameter_type == "const_irrat": parameter = sympy.parse_expr(operand.parameter.const_irrat) + elif parameter_type == "const_rat": + fraction = operand.parameter.const_rat + parameter = sympy.Rational(fraction.numerator, fraction.denominator) return parameter diff --git a/qualtran/serialization/bloq_test.py b/qualtran/serialization/bloq_test.py index 485298ede..91613b23b 100644 --- a/qualtran/serialization/bloq_test.py +++ b/qualtran/serialization/bloq_test.py @@ -30,7 +30,7 @@ from qualtran.protos import registers_pb2 from qualtran.serialization import bloq as bloq_serialization from qualtran.serialization import resolver_dict - +from qualtran.serialization.bloq import arg_from_proto @pytest.mark.parametrize( 'arg', @@ -123,7 +123,7 @@ def test_cbloq_to_proto_test_two_cswap(): assert cswap_proto.name.split('.')[-1] == "TestCSwap" assert len(cswap_proto.args) == 1 assert cswap_proto.args[0].name == "bitsize" - assert sympy.parse_expr(cswap_proto.args[0].sympy_expr) == bitsize + assert arg_from_proto(cswap_proto.args[0])['bitsize'] == bitsize assert len(cswap_proto.registers.registers) == 3 assert TestCSwap(bitsize) in bloq_serialization.bloqs_from_proto(cswap_proto_lib) From fe55ec8d7c9fc7cd38e50b0c85b48589d5e93d5a Mon Sep 17 00:00:00 2001 From: local_linix Date: Wed, 3 Apr 2024 17:59:17 -0700 Subject: [PATCH 19/34] Fix formatting --- dev_tools/qualtran_dev_tools/bloq_report_card.py | 4 +++- qualtran/bloqs/chemistry/trotter/hubbard/hopping.py | 4 +++- qualtran/protos/__init__.py | 1 - 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dev_tools/qualtran_dev_tools/bloq_report_card.py b/dev_tools/qualtran_dev_tools/bloq_report_card.py index 9e0bebde3..9a87d3f7d 100644 --- a/dev_tools/qualtran_dev_tools/bloq_report_card.py +++ b/dev_tools/qualtran_dev_tools/bloq_report_card.py @@ -116,7 +116,9 @@ def get_bloq_report_card( records = [] missing_bclasses = bloq_classes_with_no_examples(bclasses, bexamples) records.extend(record_for_class_with_no_examples(k) for k in missing_bclasses) - records.extend(record_for_bloq_example(be) for be in bexamples if be.name not in REJECTED_BEXAMPLES) + records.extend( + record_for_bloq_example(be) for be in bexamples if be.name not in REJECTED_BEXAMPLES + ) df = pd.DataFrame(records) df['package'] = df['package'].str.removeprefix(package_prefix) diff --git a/qualtran/bloqs/chemistry/trotter/hubbard/hopping.py b/qualtran/bloqs/chemistry/trotter/hubbard/hopping.py index 98ed7975f..bf7778c52 100644 --- a/qualtran/bloqs/chemistry/trotter/hubbard/hopping.py +++ b/qualtran/bloqs/chemistry/trotter/hubbard/hopping.py @@ -129,7 +129,9 @@ def signature(self) -> Signature: def build_call_graph(self, ssa: 'SympySymbolAllocator') -> Set['BloqCountT']: # Page 5, text after Eq. 22. There are L^2 / 4 plaquettes of a given colour and x2 for spin. - return {(HoppingPlaquette(kappa=self.tau * self.angle, eps=self.eps), self.length**2 // 2)} + return { + (HoppingPlaquette(kappa=self.tau * self.angle, eps=self.eps), self.length**2 // 2) + } @bloq_example diff --git a/qualtran/protos/__init__.py b/qualtran/protos/__init__.py index a1c0721cb..ce76a8d10 100644 --- a/qualtran/protos/__init__.py +++ b/qualtran/protos/__init__.py @@ -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. - From 25530b95cdae31f1b8a64b74b539258183699721 Mon Sep 17 00:00:00 2001 From: local_linix Date: Wed, 3 Apr 2024 18:01:03 -0700 Subject: [PATCH 20/34] Fix formatting --- qualtran/serialization/bloq.py | 1 - qualtran/serialization/bloq_test.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/qualtran/serialization/bloq.py b/qualtran/serialization/bloq.py index 923212ef6..f04717ab8 100644 --- a/qualtran/serialization/bloq.py +++ b/qualtran/serialization/bloq.py @@ -68,7 +68,6 @@ def _get_sympy_from_enum(enum: int): sympy_pb2.Function.POWER: sympy.core.power.Pow, sympy_pb2.Function.MOD: sympy.core.Mod, sympy_pb2.Function.NONE: None, - } return enum_to_sympy[enum] diff --git a/qualtran/serialization/bloq_test.py b/qualtran/serialization/bloq_test.py index 91613b23b..fffd55bed 100644 --- a/qualtran/serialization/bloq_test.py +++ b/qualtran/serialization/bloq_test.py @@ -32,6 +32,7 @@ from qualtran.serialization import resolver_dict from qualtran.serialization.bloq import arg_from_proto + @pytest.mark.parametrize( 'arg', [ From 7b95c0b9ed265ed499847e5cd86e3bf45e72f09f Mon Sep 17 00:00:00 2001 From: Epsilon1024 <50683403+Epsilon1024@users.noreply.github.com> Date: Wed, 3 Apr 2024 18:03:13 -0700 Subject: [PATCH 21/34] Delete Untitled.ipynb Delete scratch notebook --- Untitled.ipynb | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) delete mode 100644 Untitled.ipynb diff --git a/Untitled.ipynb b/Untitled.ipynb deleted file mode 100644 index 480c52241..000000000 --- a/Untitled.ipynb +++ /dev/null @@ -1,48 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "id": "c895c2c6-ff65-46f0-b6ec-2d2b36a84d1e", - "metadata": {}, - "outputs": [], - "source": [ - "# Put this into dev_tools\n", - "from dev_tools.qualtran_dev_tools.bloq_report_card import get_bloq_report_card, show_bloq_report_card, record_for_bloq_example, check_bloq_example_serialize, get_bloq_examples\n", - "from qualtran.serialization.bloq import bloqs_from_proto, bloqs_to_proto\n", - "\n", - "df = get_bloq_report_card()\n", - "show_bloq_report_card(df)\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ca34f824-b1ab-4620-bbb9-d2c8941dc324", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} From 8efb139301696368309dc642dfe5a4ff57fea071 Mon Sep 17 00:00:00 2001 From: local_linix Date: Wed, 3 Apr 2024 18:12:06 -0700 Subject: [PATCH 22/34] Cleanup after merging local branches. (Old changes were accidentally left in). --- dev_tools/qualtran_dev_tools/bloq_finder.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/dev_tools/qualtran_dev_tools/bloq_finder.py b/dev_tools/qualtran_dev_tools/bloq_finder.py index eaef0f161..e0b0d12b4 100644 --- a/dev_tools/qualtran_dev_tools/bloq_finder.py +++ b/dev_tools/qualtran_dev_tools/bloq_finder.py @@ -121,16 +121,10 @@ def get_bloq_examples() -> List[BloqExample]: bloqs_root = reporoot / 'qualtran/bloqs' paths = get_bloq_module_paths(bloqs_root) - # These examples are too large to run. - REJECTED_BEXAMPLES = set( - ["qubitization_qpe_hubbard_model_large", "qubitization_qpe_hubbard_model_small"] - ) - bexamples: List[BloqExample] = [] for path in paths: for modname, name, be in modpath_to_bloq_exs(path): - if be.name not in REJECTED_BEXAMPLES: - bexamples.append(be) + bexamples.append(be) return bexamples From 2ed6c0704bf3fa324a37f9aed172e204b61124fa Mon Sep 17 00:00:00 2001 From: local_linix Date: Thu, 4 Apr 2024 11:27:21 -0700 Subject: [PATCH 23/34] Remove changes from PR#849 Rather than building on top of #849, we keep the changes separate. --- dev_tools/qualtran_dev_tools/bloq_report_card.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/dev_tools/qualtran_dev_tools/bloq_report_card.py b/dev_tools/qualtran_dev_tools/bloq_report_card.py index 9a87d3f7d..ea94ac1b0 100644 --- a/dev_tools/qualtran_dev_tools/bloq_report_card.py +++ b/dev_tools/qualtran_dev_tools/bloq_report_card.py @@ -103,11 +103,6 @@ def get_bloq_report_card( package_prefix: str = 'qualtran.bloqs.', ) -> pd.DataFrame: - # These examples are too large to run. - REJECTED_BEXAMPLES = set( - ["qubitization_qpe_hubbard_model_large", "qubitization_qpe_hubbard_model_small"] - ) - if bclasses is None: bclasses = get_bloq_classes() if bexamples is None: @@ -116,9 +111,7 @@ def get_bloq_report_card( records = [] missing_bclasses = bloq_classes_with_no_examples(bclasses, bexamples) records.extend(record_for_class_with_no_examples(k) for k in missing_bclasses) - records.extend( - record_for_bloq_example(be) for be in bexamples if be.name not in REJECTED_BEXAMPLES - ) + records.extend(record_for_bloq_example(be) for be in bexamples) df = pd.DataFrame(records) df['package'] = df['package'].str.removeprefix(package_prefix) From 780a7a564fe4913d41b96354aeb46daa1e46ecc5 Mon Sep 17 00:00:00 2001 From: local_linix Date: Fri, 12 Apr 2024 13:18:27 -0700 Subject: [PATCH 24/34] Fixed assortment of bugs in fraction, and constant symbol serialization --- qualtran/protos/sympy.proto | 34 ++++++--- qualtran/protos/sympy_pb2.py | 22 +++--- qualtran/protos/sympy_pb2.pyi | 82 ++++++++++++++++------ qualtran/scratch.py | 34 +++++++++ qualtran/serialization/bloq.py | 121 +++++++++++++++++++++++++-------- 5 files changed, 228 insertions(+), 65 deletions(-) create mode 100644 qualtran/scratch.py diff --git a/qualtran/protos/sympy.proto b/qualtran/protos/sympy.proto index 1c54f1f5e..d0f23b04e 100644 --- a/qualtran/protos/sympy.proto +++ b/qualtran/protos/sympy.proto @@ -20,17 +20,32 @@ package qualtran; // A function sympy expression. enum Function { NONE = 0; - ADDITION = 1; - MULTIPLICATION = 2; - POWER = 3; - MOD = 4; - + 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 Fraction { - int32 numerator = 1; - int32 denominator = 2; + 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. @@ -38,8 +53,11 @@ message Parameter { oneof parameter { int32 const_int = 1; string symbol = 2; - string const_irrat = 3; + // string const_irrat = 3; ConstSymbol replaces the need for const_irrat Fraction const_rat = 4; + float const_float = 5; + ConstSymbol const_symbol = 6; + } } diff --git a/qualtran/protos/sympy_pb2.py b/qualtran/protos/sympy_pb2.py index bb0a30fb6..11e4216a5 100644 --- a/qualtran/protos/sympy_pb2.py +++ b/qualtran/protos/sympy_pb2.py @@ -14,21 +14,23 @@ -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1bqualtran/protos/sympy.proto\x12\x08qualtran\"2\n\x08\x46raction\x12\x11\n\tnumerator\x18\x01 \x01(\x05\x12\x13\n\x0b\x64\x65nominator\x18\x02 \x01(\x05\"\x7f\n\tParameter\x12\x13\n\tconst_int\x18\x01 \x01(\x05H\x00\x12\x10\n\x06symbol\x18\x02 \x01(\tH\x00\x12\x15\n\x0b\x63onst_irrat\x18\x03 \x01(\tH\x00\x12\'\n\tconst_rat\x18\x04 \x01(\x0b\x32\x12.qualtran.FractionH\x00\x42\x0b\n\tparameter\"^\n\x07Operand\x12\x1e\n\x04term\x18\x01 \x01(\x0b\x32\x0e.qualtran.TermH\x00\x12(\n\tparameter\x18\x02 \x01(\x0b\x32\x13.qualtran.ParameterH\x00\x42\t\n\x07operand\"Q\n\x04Term\x12$\n\x08\x66unction\x18\x01 \x01(\x0e\x32\x12.qualtran.Function\x12#\n\x08operands\x18\x02 \x03(\x0b\x32\x11.qualtran.Operand*J\n\x08\x46unction\x12\x08\n\x04NONE\x10\x00\x12\x0c\n\x08\x41\x44\x44ITION\x10\x01\x12\x12\n\x0eMULTIPLICATION\x10\x02\x12\t\n\x05POWER\x10\x03\x12\x07\n\x03MOD\x10\x04\x62\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1bqualtran/protos/sympy.proto\x12\x08qualtran\"\\\n\x08\x46raction\x12&\n\tnumerator\x18\x01 \x01(\x0b\x32\x13.qualtran.Parameter\x12(\n\x0b\x64\x65nominator\x18\x02 \x01(\x0b\x32\x13.qualtran.Parameter\"\xae\x01\n\tParameter\x12\x13\n\tconst_int\x18\x01 \x01(\x05H\x00\x12\x10\n\x06symbol\x18\x02 \x01(\tH\x00\x12\'\n\tconst_rat\x18\x04 \x01(\x0b\x32\x12.qualtran.FractionH\x00\x12\x15\n\x0b\x63onst_float\x18\x05 \x01(\x02H\x00\x12-\n\x0c\x63onst_symbol\x18\x06 \x01(\x0e\x32\x15.qualtran.ConstSymbolH\x00\x42\x0b\n\tparameter\"^\n\x07Operand\x12\x1e\n\x04term\x18\x01 \x01(\x0b\x32\x0e.qualtran.TermH\x00\x12(\n\tparameter\x18\x02 \x01(\x0b\x32\x13.qualtran.ParameterH\x00\x42\t\n\x07operand\"Q\n\x04Term\x12$\n\x08\x66unction\x18\x01 \x01(\x0e\x32\x12.qualtran.Function\x12#\n\x08operands\x18\x02 \x03(\x0b\x32\x11.qualtran.Operand*\x86\x01\n\x08\x46unction\x12\x08\n\x04NONE\x10\x00\x12\x07\n\x03\x41\x64\x64\x10\x01\x12\x07\n\x03Mul\x10\x02\x12\x07\n\x03Pow\x10\x03\x12\x07\n\x03Mod\x10\x04\x12\x07\n\x03Log\x10\x05\x12\t\n\x05\x46loor\x10\x06\x12\x0b\n\x07\x43\x65iling\x10\x07\x12\x07\n\x03Max\x10\x08\x12\x07\n\x03Min\x10\t\x12\x07\n\x03Sin\x10\n\x12\x07\n\x03\x43os\x10\x0b\x12\x07\n\x03Tan\x10\x0c*M\n\x0b\x43onstSymbol\x12\x06\n\x02Pi\x10\x00\x12\x05\n\x01\x45\x10\x01\x12\x0e\n\nEulerGamma\x10\x02\x12\x0c\n\x08Infinity\x10\x03\x12\x11\n\rImaginaryUnit\x10\x04\x62\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'qualtran.protos.sympy_pb2', _globals) if _descriptor._USE_C_DESCRIPTORS == False: DESCRIPTOR._options = None - _globals['_FUNCTION']._serialized_start=401 - _globals['_FUNCTION']._serialized_end=475 + _globals['_FUNCTION']._serialized_start=492 + _globals['_FUNCTION']._serialized_end=626 + _globals['_CONSTSYMBOL']._serialized_start=628 + _globals['_CONSTSYMBOL']._serialized_end=705 _globals['_FRACTION']._serialized_start=41 - _globals['_FRACTION']._serialized_end=91 - _globals['_PARAMETER']._serialized_start=93 - _globals['_PARAMETER']._serialized_end=220 - _globals['_OPERAND']._serialized_start=222 - _globals['_OPERAND']._serialized_end=316 - _globals['_TERM']._serialized_start=318 - _globals['_TERM']._serialized_end=399 + _globals['_FRACTION']._serialized_end=133 + _globals['_PARAMETER']._serialized_start=136 + _globals['_PARAMETER']._serialized_end=310 + _globals['_OPERAND']._serialized_start=312 + _globals['_OPERAND']._serialized_end=406 + _globals['_TERM']._serialized_start=408 + _globals['_TERM']._serialized_end=489 # @@protoc_insertion_point(module_scope) diff --git a/qualtran/protos/sympy_pb2.pyi b/qualtran/protos/sympy_pb2.pyi index c9b1fd611..eb907a614 100644 --- a/qualtran/protos/sympy_pb2.pyi +++ b/qualtran/protos/sympy_pb2.pyi @@ -39,21 +39,58 @@ class _Function: class _FunctionEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[_Function.ValueType], builtins.type): DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor NONE: _Function.ValueType # 0 - ADDITION: _Function.ValueType # 1 - MULTIPLICATION: _Function.ValueType # 2 - POWER: _Function.ValueType # 3 - MOD: _Function.ValueType # 4 + Add: _Function.ValueType # 1 + Mul: _Function.ValueType # 2 + Pow: _Function.ValueType # 3 + Mod: _Function.ValueType # 4 + Log: _Function.ValueType # 5 + Floor: _Function.ValueType # 6 + Ceiling: _Function.ValueType # 7 + Max: _Function.ValueType # 8 + Min: _Function.ValueType # 9 + Sin: _Function.ValueType # 10 + Cos: _Function.ValueType # 11 + Tan: _Function.ValueType # 12 class Function(_Function, metaclass=_FunctionEnumTypeWrapper): """A function sympy expression.""" NONE: Function.ValueType # 0 -ADDITION: Function.ValueType # 1 -MULTIPLICATION: Function.ValueType # 2 -POWER: Function.ValueType # 3 -MOD: Function.ValueType # 4 +Add: Function.ValueType # 1 +Mul: Function.ValueType # 2 +Pow: Function.ValueType # 3 +Mod: Function.ValueType # 4 +Log: Function.ValueType # 5 +Floor: Function.ValueType # 6 +Ceiling: Function.ValueType # 7 +Max: Function.ValueType # 8 +Min: Function.ValueType # 9 +Sin: Function.ValueType # 10 +Cos: Function.ValueType # 11 +Tan: Function.ValueType # 12 global___Function = Function +class _ConstSymbol: + ValueType = typing.NewType("ValueType", builtins.int) + V: typing_extensions.TypeAlias = ValueType + +class _ConstSymbolEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[_ConstSymbol.ValueType], builtins.type): + DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor + Pi: _ConstSymbol.ValueType # 0 + E: _ConstSymbol.ValueType # 1 + EulerGamma: _ConstSymbol.ValueType # 2 + Infinity: _ConstSymbol.ValueType # 3 + ImaginaryUnit: _ConstSymbol.ValueType # 4 + +class ConstSymbol(_ConstSymbol, metaclass=_ConstSymbolEnumTypeWrapper): ... + +Pi: ConstSymbol.ValueType # 0 +E: ConstSymbol.ValueType # 1 +EulerGamma: ConstSymbol.ValueType # 2 +Infinity: ConstSymbol.ValueType # 3 +ImaginaryUnit: ConstSymbol.ValueType # 4 +global___ConstSymbol = ConstSymbol + @typing_extensions.final class Fraction(google.protobuf.message.Message): """Represents a constant, rational number.""" @@ -62,14 +99,17 @@ class Fraction(google.protobuf.message.Message): NUMERATOR_FIELD_NUMBER: builtins.int DENOMINATOR_FIELD_NUMBER: builtins.int - numerator: builtins.int - denominator: builtins.int + @property + def numerator(self) -> global___Parameter: ... + @property + def denominator(self) -> global___Parameter: ... def __init__( self, *, - numerator: builtins.int = ..., - denominator: builtins.int = ..., + numerator: global___Parameter | None = ..., + denominator: global___Parameter | None = ..., ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["denominator", b"denominator", "numerator", b"numerator"]) -> builtins.bool: ... def ClearField(self, field_name: typing_extensions.Literal["denominator", b"denominator", "numerator", b"numerator"]) -> None: ... global___Fraction = Fraction @@ -82,24 +122,28 @@ class Parameter(google.protobuf.message.Message): CONST_INT_FIELD_NUMBER: builtins.int SYMBOL_FIELD_NUMBER: builtins.int - CONST_IRRAT_FIELD_NUMBER: builtins.int CONST_RAT_FIELD_NUMBER: builtins.int + CONST_FLOAT_FIELD_NUMBER: builtins.int + CONST_SYMBOL_FIELD_NUMBER: builtins.int const_int: builtins.int symbol: builtins.str - const_irrat: builtins.str @property - def const_rat(self) -> global___Fraction: ... + def const_rat(self) -> global___Fraction: + """string const_irrat = 3; ConstSymbol replaces the need for const_irrat""" + const_float: builtins.float + const_symbol: global___ConstSymbol.ValueType def __init__( self, *, const_int: builtins.int = ..., symbol: builtins.str = ..., - const_irrat: builtins.str = ..., const_rat: global___Fraction | None = ..., + const_float: builtins.float = ..., + const_symbol: global___ConstSymbol.ValueType = ..., ) -> None: ... - def HasField(self, field_name: typing_extensions.Literal["const_int", b"const_int", "const_irrat", b"const_irrat", "const_rat", b"const_rat", "parameter", b"parameter", "symbol", b"symbol"]) -> builtins.bool: ... - def ClearField(self, field_name: typing_extensions.Literal["const_int", b"const_int", "const_irrat", b"const_irrat", "const_rat", b"const_rat", "parameter", b"parameter", "symbol", b"symbol"]) -> None: ... - def WhichOneof(self, oneof_group: typing_extensions.Literal["parameter", b"parameter"]) -> typing_extensions.Literal["const_int", "symbol", "const_irrat", "const_rat"] | None: ... + def HasField(self, field_name: typing_extensions.Literal["const_float", b"const_float", "const_int", b"const_int", "const_rat", b"const_rat", "const_symbol", b"const_symbol", "parameter", b"parameter", "symbol", b"symbol"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["const_float", b"const_float", "const_int", b"const_int", "const_rat", b"const_rat", "const_symbol", b"const_symbol", "parameter", b"parameter", "symbol", b"symbol"]) -> None: ... + def WhichOneof(self, oneof_group: typing_extensions.Literal["parameter", b"parameter"]) -> typing_extensions.Literal["const_int", "symbol", "const_rat", "const_float", "const_symbol"] | None: ... global___Parameter = Parameter diff --git a/qualtran/scratch.py b/qualtran/scratch.py new file mode 100644 index 000000000..563be1138 --- /dev/null +++ b/qualtran/scratch.py @@ -0,0 +1,34 @@ +from bloqs.factoring.mod_mul import CtrlModMul +from qualtran.serialization.bloq import bloqs_from_proto, bloqs_to_proto +from qualtran.serialization.bloq import arg_to_proto, arg_from_proto +import sympy +# sympy.pi +# sympy.E +# sympy.EulerGamma +# sympy.core.numbers.Infinity +# sympy.core.numbers.ImaginaryUnit + + +def parameter_test(): + const_int = sympy.parse_expr("5") + symbol = sympy.symbols("x") + fraction = sympy.parse_expr("1/2") + const_symbol = sympy.pi + const_complex = sympy.parse_expr("2j") + + expr = const_int + symbol + fraction + const_symbol + const_complex + + serialized = arg_to_proto(name="test", val=expr) + expr_clone = arg_from_proto(serialized)['test'] + print("done") + +# parameter_test() + + + +k, N, n_x = sympy.symbols('k N n_x') +bloq = CtrlModMul(k=k, mod=N, bitsize=n_x) + +serialized = bloqs_to_proto(bloq) +reconstructed = bloqs_from_proto(serialized) +# diff --git a/qualtran/serialization/bloq.py b/qualtran/serialization/bloq.py index f04717ab8..24eedd734 100644 --- a/qualtran/serialization/bloq.py +++ b/qualtran/serialization/bloq.py @@ -14,7 +14,7 @@ import dataclasses import inspect -from typing import Any, Callable, Dict, List, Optional +from typing import Any, Callable, Dict, List, Optional, Union import attrs import cirq @@ -50,32 +50,79 @@ def _get_sympy_function_type(expr: sympy.Expr) -> int: if isinstance(expr, sympy.core.mul.Mul): - return sympy_pb2.Function.MULTIPLICATION - if isinstance(expr, sympy.core.add.Add): - return sympy_pb2.Function.ADDITION - if isinstance(expr, sympy.core.power.Pow): - return sympy_pb2.Function.POWER - if isinstance(expr, sympy.core.Mod): - return sympy_pb2.Function.MOD + return sympy_pb2.Function.Mul + elif isinstance(expr, sympy.core.add.Add): + return sympy_pb2.Function.Add + elif isinstance(expr, sympy.core.power.Pow): + return sympy_pb2.Function.Pow + elif isinstance(expr, sympy.core.Mod): + return sympy_pb2.Function.Mod + elif isinstance(expr, sympy.functions.elementary.exponential.log): + return sympy_pb2.Function.Log + elif isinstance(expr, sympy.functions.elementary.integers.floor): + return sympy_pb2.Function.Floor + elif isinstance(expr, sympy.functions.elementary.integers.ceiling): + return sympy_pb2.Function.Ceiling + elif isinstance(expr, sympy.functions.elementary.miscellaneous.Max): + return sympy_pb2.Function.Max + elif isinstance(expr, sympy.functions.elementary.miscellaneous.Min): + return sympy_pb2.Function.Min + elif isinstance(expr, sympy.functions.elementary.trigonometric.sin): + return sympy_pb2.Function.Sin + elif isinstance(expr, sympy.functions.elementary.trigonometric.cos): + return sympy_pb2.Function.Cos + elif isinstance(expr, sympy.functions.elementary.trigonometric.tan): + return sympy_pb2.Function.Tan else: return sympy_pb2.Function.NONE def _get_sympy_from_enum(enum: int): enum_to_sympy = { - sympy_pb2.Function.MULTIPLICATION: sympy.core.mul.Mul, - sympy_pb2.Function.ADDITION: sympy.core.add.Add, - sympy_pb2.Function.POWER: sympy.core.power.Pow, - sympy_pb2.Function.MOD: sympy.core.Mod, + sympy_pb2.Function.Mul: sympy.core.mul.Mul, + sympy_pb2.Function.Add: sympy.core.add.Add, + sympy_pb2.Function.Pow: sympy.core.power.Pow, + sympy_pb2.Function.Mod: sympy.core.Mod, + sympy_pb2.Function.Log: sympy.functions.elementary.exponential.log, + sympy_pb2.Function.Floor: sympy.functions.elementary.integers.floor, + sympy_pb2.Function.Ceiling: sympy.functions.elementary.integers.ceiling, + sympy_pb2.Function.Max: sympy.functions.elementary.miscellaneous.Max, + sympy_pb2.Function.Min: sympy.functions.elementary.miscellaneous.Min, + sympy_pb2.Function.Sin: sympy.functions.elementary.trigonometric.sin, + sympy_pb2.Function.Cos: sympy.functions.elementary.trigonometric.cos, + sympy_pb2.Function.Tan: sympy.functions.elementary.trigonometric.tan, sympy_pb2.Function.NONE: None, } return enum_to_sympy[enum] +def _get_sympy_const_from_enum(enum: int): + enum_to_sympy = { + sympy_pb2.ConstSymbol.Pi: sympy.pi, + sympy_pb2.ConstSymbol.E: sympy.E, + sympy_pb2.ConstSymbol.EulerGamma: sympy.EulerGamma, + sympy_pb2.ConstSymbol.Infinity: sympy.core.numbers.Infinity(), + sympy_pb2.ConstSymbol.ImaginaryUnit: sympy.core.numbers.ImaginaryUnit() + } + return enum_to_sympy[enum] -def _get_sympy_operand(expr: sympy.Expr): +def _get_const_symbolic_operand(expr: sympy.Expr): + if expr == sympy.pi: + return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.Pi) + if expr == sympy.E: + return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.E) + if expr == sympy.EulerGamma: + return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.EulerGamma) + if isinstance(expr,sympy.core.numbers.Infinity): + return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.Infinity) + if isinstance(expr, sympy.core.numbers.ImaginaryUnit): + return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.ImaginaryUnit) + else: + raise NotImplementedError(f"Sympy expression {str(expr)} cannot be serialized.") + +def _get_sympy_operand(expr: Union[sympy.Expr, int, float])->sympy_pb2.Parameter: - # Expression is a single variable. + # Expression is a single, symbolic variable. if isinstance(expr, sympy.core.symbol.Symbol): return sympy_pb2.Parameter(symbol=str(expr)) @@ -88,13 +135,21 @@ def _get_sympy_operand(expr: sympy.Expr): # Expression cannot be broken down further, but is a constant. if issubclass(expr.__class__, sympy.core.numbers.Number): + if isinstance(expr, sympy.core.numbers.Float): + return sympy_pb2.Parameter(const_float=float(expr)) if isinstance(expr, sympy.core.numbers.Rational): - fraction = sympy_pb2.Fraction(numerator=expr.numerator, denominator=expr.denominator) + numerator = _get_sympy_operand(expr.numerator) + denominator = _get_sympy_operand(expr.denominator) + fraction = sympy_pb2.Fraction(numerator=numerator, denominator=denominator) return sympy_pb2.Parameter(const_rat=fraction) - - # If it is not a rational number, then it must be an irrational constant. - return sympy_pb2.Parameter(const_irrat=expr.name) - + else: + raise NotImplementedError(f"Sympy expression {str(expr)} cannot be serialized.") + if type(expr) == int: + return sympy_pb2.Parameter(const_int=expr) + if type(expr) == float: + return sympy_pb2.Parameter(const_float=expr) + else: + return _get_const_symbolic_operand(expr) def decompose_sympy(expr: sympy.Expr): function = _get_sympy_function_type(expr) @@ -111,20 +166,30 @@ def decompose_sympy(expr: sympy.Expr): return sympy_pb2.Term(function=function, operands=operands) +def _get_parameter(serialized_input: Union[sympy_pb2.Operand, sympy_pb2.Parameter]): + if isinstance(serialized_input, sympy_pb2.Operand): + serialized_parameter = serialized_input.parameter + else: + serialized_parameter = serialized_input -def _get_parameter(operand): - parameter_type = operand.parameter.WhichOneof("parameter") + parameter_type = serialized_parameter.WhichOneof("parameter") if parameter_type == "symbol": - parameter = sympy.symbols(operand.parameter.symbol) + deserialized_parameter = sympy.symbols(serialized_parameter.symbol) elif parameter_type == "const_int": - parameter = operand.parameter.const_int - elif parameter_type == "const_irrat": - parameter = sympy.parse_expr(operand.parameter.const_irrat) + deserialized_parameter = serialized_parameter.const_int elif parameter_type == "const_rat": - fraction = operand.parameter.const_rat - parameter = sympy.Rational(fraction.numerator, fraction.denominator) + fraction = serialized_parameter.const_rat + numerator = _get_parameter(fraction.numerator) + denominator = _get_parameter(fraction.denominator) + deserialized_parameter = sympy.Rational(numerator, denominator) + elif parameter_type == "const_float": + deserialized_parameter = serialized_parameter.const_float + elif parameter_type == "const_symbol": + deserialized_parameter = _get_sympy_const_from_enum(serialized_parameter.const_symbol) + else: + raise TypeError(f"Type is not supported for {serialized_input}") - return parameter + return deserialized_parameter def _set_function(function, parameters): From 87f87422f85bf87b9c8d7098675c9f7d7ad63161 Mon Sep 17 00:00:00 2001 From: local_linix Date: Fri, 12 Apr 2024 13:22:44 -0700 Subject: [PATCH 25/34] Scratch test --- qualtran/serialization/bloq.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qualtran/serialization/bloq.py b/qualtran/serialization/bloq.py index 24eedd734..f2bda7de9 100644 --- a/qualtran/serialization/bloq.py +++ b/qualtran/serialization/bloq.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. + +# Test Do not submit import dataclasses import inspect from typing import Any, Callable, Dict, List, Optional, Union From fbf36c4e7cfc3fb2b57f357949f4d7dfc65d5c34 Mon Sep 17 00:00:00 2001 From: local_linix Date: Mon, 15 Apr 2024 14:22:24 -0700 Subject: [PATCH 26/34] Fixed bad reference to resolver dict by bloq module name. --- qualtran/scratch.py | 1 + qualtran/serialization/bloq.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/qualtran/scratch.py b/qualtran/scratch.py index 563be1138..2aa6ff63f 100644 --- a/qualtran/scratch.py +++ b/qualtran/scratch.py @@ -31,4 +31,5 @@ def parameter_test(): serialized = bloqs_to_proto(bloq) reconstructed = bloqs_from_proto(serialized) +print("Done") # diff --git a/qualtran/serialization/bloq.py b/qualtran/serialization/bloq.py index f2bda7de9..288f4a8af 100644 --- a/qualtran/serialization/bloq.py +++ b/qualtran/serialization/bloq.py @@ -487,6 +487,8 @@ def _bloq_to_proto(bloq: Bloq, *, bloq_to_idx: Dict[Bloq, int]) -> bloq_pb2.Bloq t_complexity = None name = bloq.__module__ + "." + bloq.__class__.__qualname__ + if not name.startswith("qualtran."): + name = "qualtran."+name return bloq_pb2.Bloq( name=name, registers=registers.registers_to_proto(bloq.signature), From 74bd9e9a9ef15192e7c67fee39d5e1d1cb3d0b93 Mon Sep 17 00:00:00 2001 From: local_linix Date: Mon, 15 Apr 2024 17:14:25 -0700 Subject: [PATCH 27/34] Minor refactoring --- Untitled.ipynb | 2868 +++++++++++++++++ .../qualtran_dev_tools/bloq_report_card.py | 4 +- qualtran/_infra/bloq.py | 2 + qualtran/bloqs/factoring/mod_mul.py | 2 + qualtran/protos/sympy.proto | 7 +- qualtran/scratch.py | 74 +- qualtran/serialization/bloq.py | 181 +- qualtran/serialization/sympy.py | 212 ++ qualtran/serialization/sympy_test.py | 46 + 9 files changed, 3188 insertions(+), 208 deletions(-) create mode 100644 Untitled.ipynb create mode 100644 qualtran/serialization/sympy.py create mode 100644 qualtran/serialization/sympy_test.py diff --git a/Untitled.ipynb b/Untitled.ipynb new file mode 100644 index 000000000..111213c38 --- /dev/null +++ b/Untitled.ipynb @@ -0,0 +1,2868 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "259ed492-c91a-441c-8cf2-399ceb7920c4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "add_diff_size_regs\n", + "add_k_large\n", + "add_k_small\n", + "add_k_symb\n", + "add_large\n", + "add_oop_large\n", + "add_oop_small\n", + "add_oop_symb\n", + "add_small\n", + "add_symb\n", + "simple_add_k_large\n", + "simple_add_k_small\n", + "bi_qubits_mixer\n", + "eq_k\n", + "greater_than\n", + "gt_k\n", + "leq\n", + "leq_symb\n", + "lt_k\n", + "lt_k_symb\n", + "sq_cmp\n", + "signed_to_twos\n", + "to_contg_index\n", + "multiply_two_reals\n", + "plus_equal_product\n", + "product\n", + "scale_int_by_real\n", + "square\n", + "square_real_number\n", + "sum_of_squares\n", + "bitonic_sort\n", + "cmp_symb\n", + "cnot\n", + "global_phase\n", + "hadamard\n", + "rx\n", + "ry\n", + "rz\n", + "x_pow\n", + "y_pow\n", + "z_pow\n", + "s_gate\n", + "hadamard\n", + "su2_rotation_gate\n", + "t_gate\n", + "cswap_large\n", + "cswap_small\n", + "cswap_symb\n", + "swap_small\n", + "t_gate\n", + "toffoli\n", + "minus_effect\n", + "minus_state\n", + "plus_effect\n", + "plus_state\n", + "int_effect\n", + "int_state\n", + "one_effect\n", + "one_state\n", + "zero_effect\n", + "zero_state\n", + "zgate\n", + "black_box_block_bloq\n", + "black_box_prepare\n", + "black_box_select\n", + "chebyshev_poly\n", + "df_block_encoding\n", + "df_one_body\n", + "indexed_data\n", + "prep_inner\n", + "prep_outer\n", + "prepare_t\n", + "prepare_uv\n", + "prep_mu_proj\n", + "prep_nu_proj\n", + "prep_power_two_proj\n", + "prep_t_proj\n", + "prep_uv_proj\n", + "prep_first_quant\n", + "sel_first_quant\n", + "sel_t_proj\n", + "sel_uv_proj\n", + "prep_first_quant\n", + "sel_first_quant\n", + "select_t\n", + "select_uv\n", + "prep_inner\n", + "prep_outer\n", + "select\n", + "sf_block_encoding\n", + "sf_one_body\n", + "prep_sparse\n", + "sel_sparse\n", + "thc_prep\n", + "thc_uni\n", + "thc_sel\n", + "nr_inv_sqrt\n", + "poly_inv_sqrt\n", + "kinetic_energy\n", + "pair_potential\n", + "potential_energy\n", + "qvr\n", + "hopping_tile\n", + "plaquette\n", + "interaction\n", + "ising_x\n", + "ising_zz\n", + "trott_unitary\n", + "qrom_multi_data\n", + "qrom_multi_dim\n", + "qrom_small\n", + "modexp\n", + "modexp_small\n", + "modexp_symb\n", + "modmul\n", + "modmul_symb\n", + "hubbard_time_evolution_by_gqsp\n", + "and_bloq\n", + "multi_and\n", + "c_multi_not\n", + "c_multi_not_symb\n", + "ccpauli\n", + "apply_z_to_odd\n", + "select_pauli_lcu\n", + "lp_resource_state_small\n", + "lp_resource_state_symbolic\n", + "lprs_interim_prep\n", + "qubitization_qpe_hubbard_model_small\n", + "textbook_qpe_from_precision_and_delta\n", + "textbook_qpe_from_standard_deviation_eps\n", + "textbook_qpe_small\n", + "textbook_qpe_using_m_bits\n", + "approximate_qft_from_epsilon\n", + "approximate_qft_small\n", + "two_bit_ffft\n", + "gqsp\n", + "gqsp_with_large_negative_power\n", + "gqsp_with_negative_power\n", + "walk_op\n", + "reflection\n", + "square_via_phase_gradient\n", + "square_via_zpow_phasing\n", + "qvr_phase_gradient\n", + "qvr_zpow\n", + "c_prep_uniform\n", + "prep_uniform\n", + "state_prep_alias\n", + "state_prep_via_rotation\n", + "approx_cswap_large\n", + "approx_cswap_small\n", + "approx_cswap_symb\n", + "multiplexed_cswap\n", + "swz\n", + "swz_small\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 packagebloq_clsnamemakedecompcountsserializetyping
83arithmeticAddadd_diff_size_regspasspassfailpasspass
87arithmeticAddadd_largepasspassfailpasspass
91arithmeticAddadd_smallpasspassfailpasspass
92arithmeticAddadd_symbpassnaunverifiedpassmissing
84arithmeticAddConstantModadd_k_largepassmissingunverifiedpassmissing
85arithmeticAddConstantModadd_k_smallpassmissingunverifiedpassmissing
86arithmeticAddConstantModadd_k_symbpassnaunverifiedpassmissing
95arithmeticBiQubitsMixerbi_qubits_mixerpasspassunverifiedpasspass
113arithmeticBitonicSortbitonic_sortpassmissingmissingpassmissing
114arithmeticComparatorcmp_symbpassmissingmissingpassmissing
96arithmeticEqualsAConstanteq_kpassmissingunverifiedpassmissing
97arithmeticGreaterThangreater_thanpassmissingunverifiedpassmissing
98arithmeticGreaterThanConstantgt_kpassmissingunverifiedpassmissing
9arithmeticHammingWeightCompute-missingmissingmissingmissingmissing
101arithmeticLessThanConstantlt_kpasspassunverifiedpasspass
102arithmeticLessThanConstantlt_k_symbpassnamissingpassmissing
99arithmeticLessThanEqualleqpasspassunverifiedpasspass
100arithmeticLessThanEqualleq_symbpassnamissingpassmissing
75arithmeticLinearDepthGreaterThan-missingmissingmissingmissingmissing
106arithmeticMultiplyTwoRealsmultiply_two_realspassmissingunverifiedpassmissing
88arithmeticOutOfPlaceAdderadd_oop_largepasspassfailpasspass
89arithmeticOutOfPlaceAdderadd_oop_smallpasspassfailpasspass
90arithmeticOutOfPlaceAdderadd_oop_symbpassnaunverifiedpassmissing
107arithmeticPlusEqualProductplus_equal_productpassmissingunverifiedpassmissing
108arithmeticProductproductpassmissingunverifiedpassmissing
109arithmeticScaleIntByRealscale_int_by_realpassmissingunverifiedpassmissing
104arithmeticSignedIntegerToTwosComplementsigned_to_twospassmissingunverifiedpassmissing
93arithmeticSimpleAddConstantsimple_add_k_largepasspassunverifiedpasspass
94arithmeticSimpleAddConstantsimple_add_k_smallpasspassunverifiedpasspass
103arithmeticSingleQubitComparesq_cmppasspassunverifiedpasspass
110arithmeticSquaresquarepassmissingunverifiedpassmissing
111arithmeticSquareRealNumbersquare_real_numberpassmissingunverifiedpassmissing
112arithmeticSumOfSquaressum_of_squarespassmissingunverifiedpassmissing
105arithmeticToContiguousIndexto_contg_indexpassmissingunverifiedpassmissing
115basic_gatesCNOTcnotpassnamissingpassmissing
128basic_gatesCSwapcswap_largepasspasspasspasspass
129basic_gatesCSwapcswap_smallpasspasspasspasspass
130basic_gatesCSwapcswap_symbpassnaunverifiedpassmissing
1basic_gatesCZPowGate-missingmissingmissingmissingmissing
116basic_gatesGlobalPhaseglobal_phasepassnamissingpassmissing
117basic_gatesHadamardhadamardpassnamissingpassmissing
138basic_gatesIntEffectint_effectpasspassfailpasspass
139basic_gatesIntStateint_statepasspassfailpasspass
134basic_gatesMinusEffectminus_effectpassmissingmissingpassmissing
135basic_gatesMinusStateminus_statepassmissingmissingpassmissing
71basic_gatesOnEach-missingmissingmissingmissingmissing
140basic_gatesOneEffectone_effectpassnamissingpassmissing
141basic_gatesOneStateone_statepassnamissingpassmissing
136basic_gatesPlusEffectplus_effectpassmissingmissingpassmissing
137basic_gatesPlusStateplus_statepassmissingmissingpassmissing
118basic_gatesRxrxpassnamissingpassmissing
119basic_gatesRyrypassnamissingpassmissing
120basic_gatesRzrzpassnamissingpassmissing
124basic_gatesSGates_gatepassmissingmissingpassmissing
125basic_gatesSU2RotationGatehadamardpasspassunverifiedpasspass
126basic_gatesSU2RotationGatesu2_rotation_gatepasspassunverifiedpasspass
127basic_gatesSU2RotationGatet_gatepasspassunverifiedpasspass
131basic_gatesSwapswap_smallpasspasspasspasspass
132basic_gatesTGatet_gatepassmissingmissingpassmissing
133basic_gatesToffolitoffolipassmissingunverifiedpassmissing
79basic_gatesTwoBitCSwap-missingmissingmissingmissingmissing
48basic_gatesTwoBitSwap-missingmissingmissingmissingmissing
66basic_gatesXGate-missingmissingmissingmissingmissing
121basic_gatesXPowGatex_powpassnamissingpassmissing
28basic_gatesYGate-missingmissingmissingmissingmissing
122basic_gatesYPowGatey_powpassnamissingpassmissing
144basic_gatesZGatezgatepassnamissingpassmissing
123basic_gatesZPowGatez_powpassnamissingpassmissing
142basic_gatesZeroEffectzero_effectpassnamissingpassmissing
143basic_gatesZeroStatezero_statepassnamissingpassmissing
39chemistryApplyControlledZs-missingmissingmissingmissingmissing
8chemistryQROAM-missingmissingmissingmissingmissing
50chemistryQROAMTwoRegs-missingmissingmissingmissingmissing
149chemistry.dfDoubleFactorizationBlockEncodingdf_block_encodingpasspassunverifiedpasspass
150chemistry.dfDoubleFactorizationOneBodydf_one_bodypasspassfailpasspass
152chemistry.dfInnerPrepareDoubleFactorizationprep_innerpassmissingunverifiedpassmissing
153chemistry.dfOuterPrepareDoubleFactorizationprep_outerpassmissingunverifiedpassmissing
151chemistry.dfOutputIndexedDataindexed_datapassmissingunverifiedpassmissing
30chemistry.dfProgRotGateArray-missingmissingmissingmissingmissing
32chemistry.pbc.first_quantizationApplyNuclearPhase-missingmissingmissingmissingmissing
26chemistry.pbc.first_quantizationFlagZeroAsFailure-missingmissingmissingmissingmissing
2chemistry.pbc.first_quantizationMultiplexedCSwap3D-missingmissingmissingmissingmissing
165chemistry.pbc.first_quantizationPrepareFirstQuantizationprep_first_quantpasspassunverifiedpassunverified
27chemistry.pbc.first_quantizationPrepareMuUnaryEncodedOneHot-missingmissingmissingmissingmissing
55chemistry.pbc.first_quantizationPrepareNuState-missingmissingmissingmissingmissing
80chemistry.pbc.first_quantizationPrepareNuSuperPositionState-missingmissingmissingmissingmissing
63chemistry.pbc.first_quantizationPreparePowerTwoState-missingmissingmissingmissingmissing
154chemistry.pbc.first_quantizationPrepareTFirstQuantizationprepare_tpasspassfailpasspass
56chemistry.pbc.first_quantizationPrepareTUVSuperpositions-missingmissingmissingmissingmissing
155chemistry.pbc.first_quantizationPrepareUVFirstQuantizationprepare_uvpasspasspasspasspass
15chemistry.pbc.first_quantizationPrepareZetaState-missingmissingmissingmissingmissing
166chemistry.pbc.first_quantizationSelectFirstQuantizationsel_first_quantpasspassunverifiedpassunverified
167chemistry.pbc.first_quantizationSelectTFirstQuantizationselect_tpassmissingunverifiedpassmissing
168chemistry.pbc.first_quantizationSelectUVFirstQuantizationselect_uvpassmissingunverifiedpassmissing
61chemistry.pbc.first_quantizationTestNuInequality-missingmissingmissingmissingmissing
11chemistry.pbc.first_quantizationTestNuLessThanMu-missingmissingmissingmissingmissing
12chemistry.pbc.first_quantizationUniformSuperpostionIJFirstQuantization-missingmissingmissingmissingmissing
34chemistry.pbc.first_quantizationUniformSuperpostionIJFirstQuantization-missingmissingmissingmissingmissing
47chemistry.pbc.first_quantization.projectileControlledMultiplexedCSwap3D-missingmissingmissingmissingmissing
161chemistry.pbc.first_quantization.projectilePrepareFirstQuantizationWithProjprep_first_quantpasspassunverifiedpassunverified
156chemistry.pbc.first_quantization.projectilePrepareMuUnaryEncodedOneHotWithProjprep_mu_projpassmissingunverifiedpassmissing
157chemistry.pbc.first_quantization.projectilePrepareNuStateWithProjprep_nu_projpasspassfailpasspass
158chemistry.pbc.first_quantization.projectilePreparePowerTwoStateWithProjprep_power_two_projpassmissingunverifiedpassmissing
159chemistry.pbc.first_quantization.projectilePrepareTFirstQuantizationWithProjprep_t_projpassmissingunverifiedpassmissing
64chemistry.pbc.first_quantization.projectilePrepareTUVSuperpositions-missingmissingmissingmissingmissing
160chemistry.pbc.first_quantization.projectilePrepareUVFirstQuantizationWithProjprep_uv_projpasspasspasspasspass
162chemistry.pbc.first_quantization.projectileSelectFirstQuantizationWithProjsel_first_quantpasspassunverifiedpassunverified
163chemistry.pbc.first_quantization.projectileSelectTFirstQuantizationWithProjsel_t_projpassmissingunverifiedpassmissing
164chemistry.pbc.first_quantization.projectileSelectUVFirstQuantizationWithProjsel_uv_projpassmissingunverifiedpassmissing
169chemistry.sfInnerPrepareSingleFactorizationprep_innerpassmissingunverifiedpassmissing
170chemistry.sfOuterPrepareSingleFactorizationprep_outerpassmissingunverifiedpassmissing
171chemistry.sfSelectSingleFactorizationselectpassmissingunverifiedpassmissing
172chemistry.sfSingleFactorizationBlockEncodingsf_block_encodingpasspassunverifiedpassunverified
173chemistry.sfSingleFactorizationOneBodysf_one_bodypasspasspasspassunverified
174chemistry.sparsePrepareSparseprep_sparsepasspassfailfailunverified
175chemistry.sparseSelectSparsesel_sparsepasspassfailpasspass
176chemistry.thcPrepareTHCthc_preppasspassfailfailunverified
178chemistry.thcSelectTHCthc_selpasspassunverifiedpassunverified
20chemistry.thcTHCRotations-missingmissingmissingmissingmissing
177chemistry.thcUniformSuperpositionTHCthc_unipasspassunverifiedpassunverified
190chemistry.trotterTrotterizedUnitarytrott_unitarypasspassunverifiedfailpass
181chemistry.trotter.grid_hamKineticEnergykinetic_energypasspassunverifiedpassunverified
179chemistry.trotter.grid_hamNewtonRaphsonApproxInverseSquareRootnr_inv_sqrtpassmissingunverifiedpassmissing
182chemistry.trotter.grid_hamPairPotentialpair_potentialpasspassunverifiedpassunverified
180chemistry.trotter.grid_hamPolynmomialEvaluationInverseSquareRootpoly_inv_sqrtpassmissingunverifiedpassmissing
183chemistry.trotter.grid_hamPotentialEnergypotential_energypasspassunverifiedpasspass
184chemistry.trotter.grid_hamQuantumVariableRotationqvrpassmissingunverifiedpassmissing
186chemistry.trotter.hubbardHoppingPlaquetteplaquettepassmissingunverifiedpassmissing
185chemistry.trotter.hubbardHoppingTilehopping_tilepassmissingunverifiedpassmissing
187chemistry.trotter.hubbardInteractioninteractionpassmissingunverifiedpassmissing
188chemistry.trotter.isingIsingXUnitaryising_xpasspassunverifiedpasspass
189chemistry.trotter.isingIsingZZUnitaryising_zzpasspassunverifiedpasspass
191data_loadingQROMqrom_multi_datapasspassfailpasspass
192data_loadingQROMqrom_multi_dimpasspassfailpasspass
193data_loadingQROMqrom_smallpasspassfailpasspass
31data_loadingSelectSwapQROM-missingmissingmissingmissingmissing
51factoringCtrlAddK-missingmissingmissingmissingmissing
76factoringCtrlModAddK-missingmissingmissingmissingmissing
197factoringCtrlModMulmodmulpasspasspassfailunverified
198factoringCtrlModMulmodmul_symbpasspasspassfailunverified
38factoringCtrlScaleModAdd-missingmissingmissingmissingmissing
194factoringModExpmodexppasspasspassfailunverified
195factoringModExpmodexp_smallpasspasspassfailunverified
196factoringModExpmodexp_symbpassnaunverifiedfailmissing
24factoringMontgomeryModAdd-missingmissingmissingmissingmissing
0factoringMontgomeryModDbl-missingmissingmissingmissingmissing
53factoringMontgomeryModNeg-missingmissingmissingmissingmissing
69factoringMontgomeryModSub-missingmissingmissingmissingmissing
42for_testingInteriorAlloc-missingmissingmissingmissingmissing
41for_testingPauliSelectOracle-missingmissingmissingmissingmissing
13for_testingRandomGate-missingmissingmissingmissingmissing
22for_testingRandomPrepareOracle-missingmissingmissingmissingmissing
77for_testingTestAtom-missingmissingmissingmissingmissing
43for_testingTestBloqWithCallGraph-missingmissingmissingmissingmissing
33for_testingTestBoundedQUInt-missingmissingmissingmissingmissing
78for_testingTestCastToFrom-missingmissingmissingmissingmissing
10for_testingTestGWRAtom-missingmissingmissingmissingmissing
74for_testingTestIndependentParallelCombo-missingmissingmissingmissingmissing
82for_testingTestMultiRegister-missingmissingmissingmissingmissing
54for_testingTestMultiTypedRegister-missingmissingmissingmissingmissing
40for_testingTestParallelCombo-missingmissingmissingmissingmissing
70for_testingTestQFxp-missingmissingmissingmissingmissing
73for_testingTestSerialCombo-missingmissingmissingmissingmissing
3for_testingTestTwoBitOp-missingmissingmissingmissingmissing
199hamiltonian_simulationHamiltonianSimulationByGQSPhubbard_time_evolution_by_gqsppasspasspassfailpass
200mcmtAndand_bloqpasspasspasspasspass
201mcmtMultiAndmulti_andpasspasspasspasspass
204mcmtMultiControlPauliccpaulipasspasspasspasspass
57mcmtMultiControlX-missingmissingmissingmissingmissing
202mcmtMultiTargetCNOTc_multi_notpasspassunverifiedpasspass
203mcmtMultiTargetCNOTc_multi_not_symbpassnamissingpassmissing
6mean_estimationArcTan-missingmissingmissingmissingmissing
58mean_estimationComplexPhaseOracle-missingmissingmissingmissingmissing
60mean_estimationMeanEstimationOperator-missingmissingmissingmissingmissing
205multiplexersApplyGateToLthQubitapply_z_to_oddpasspasspassfailpass
206multiplexersSelectPauliLCUselect_pauli_lcupasspasspassfailpass
49multiplexersSelectedMajoranaFermion-missingmissingmissingmissingmissing
18multiplexersUnaryIterationGate-missingmissingmissingmissingmissing
209phase_estimationLPRSInterimPreplprs_interim_preppasspassfailpasspass
207phase_estimationLPResourceStatelp_resource_state_smallpasspassfailpassunverified
208phase_estimationLPResourceStatelp_resource_state_symbolicpassnaerrorfailmissing
210phase_estimationQubitizationQPEqubitization_qpe_hubbard_model_smallpasspassfailpassunverified
211phase_estimationTextbookQPEtextbook_qpe_from_precision_and_deltapassnaunverifiedfailmissing
212phase_estimationTextbookQPEtextbook_qpe_from_standard_deviation_epspassnaunverifiedfailmissing
213phase_estimationTextbookQPEtextbook_qpe_smallpasspassfailpassunverified
214phase_estimationTextbookQPEtextbook_qpe_using_m_bitspassnaunverifiedfailmissing
215qftApproximateQFTapproximate_qft_from_epsilonpasspassfailpasspass
216qftApproximateQFTapproximate_qft_smallpasspassfailpasspass
19qftQFTPhaseGradient-missingmissingmissingmissingmissing
25qftQFTTextBook-missingmissingmissingmissingmissing
217qftTwoBitFFFTtwo_bit_ffftpasspassfailpasspass
218qspGeneralizedQSPgqsppasspasspasspasspass
219qspGeneralizedQSPgqsp_with_large_negative_powerpasspasspasspasspass
220qspGeneralizedQSPgqsp_with_negative_powerpasspasspasspasspass
44qualtran.bloqsAllocate-missingmissingmissingmissingmissing
45qualtran.bloqsArbitraryClifford-missingmissingmissingmissingmissing
145qualtran.bloqsBlackBoxBlockEncodingblack_box_block_bloqpasspassunverifiedpasspass
146qualtran.bloqsBlackBoxPrepareblack_box_preparepasspassunverifiedpasspass
147qualtran.bloqsBlackBoxSelectblack_box_selectpasspassunverifiedpasspass
21qualtran.bloqsCast-missingmissingmissingmissingmissing
148qualtran.bloqsChebyshevPolynomialchebyshev_polypasspasspasspasspass
62qualtran.bloqsFree-missingmissingmissingmissingmissing
23qualtran.bloqsJoin-missingmissingmissingmissingmissing
17qualtran.bloqsPartition-missingmissingmissingmissingmissing
72qualtran.bloqsPower-missingmissingmissingmissingmissing
81qualtran.bloqsPrepareHubbard-missingmissingmissingmissingmissing
65qualtran.bloqsPrepareOracle-missingmissingmissingmissingmissing
221qualtran.bloqsQubitizationWalkOperatorwalk_oppasspassunverifiedfailpass
222qualtran.bloqsReflectionreflectionpasspassfailpasspass
46qualtran.bloqsReflectionUsingPrepare-missingmissingmissingmissingmissing
68qualtran.bloqsSelectHubbard-missingmissingmissingmissingmissing
36qualtran.bloqsSelectOracle-missingmissingmissingmissingmissing
37qualtran.bloqsSplit-missingmissingmissingmissingmissing
4rotationsAddIntoPhaseGrad-missingmissingmissingmissingmissing
52rotationsAddScaledValIntoPhaseReg-missingmissingmissingmissingmissing
14rotationsHammingWeightPhasing-missingmissingmissingmissingmissing
29rotationsHammingWeightPhasingViaPhaseGradient-missingmissingmissingmissingmissing
67rotationsPhaseGradientState-missingmissingmissingmissingmissing
16rotationsPhaseGradientUnitary-missingmissingmissingmissingmissing
223rotationsPhasingViaCostFunctionsquare_via_phase_gradientpasspassunverifiedpassunverified
224rotationsPhasingViaCostFunctionsquare_via_zpow_phasingpasspassunverifiedpassunverified
35rotationsProgrammableRotationGateArray-missingmissingmissingmissingmissing
7rotationsProgrammableRotationGateArrayBase-missingmissingmissingmissingmissing
59rotationsQvrInterface-missingmissingmissingmissingmissing
225rotationsQvrPhaseGradientqvr_phase_gradientpasspasspasspasspass
226rotationsQvrZPowqvr_zpowpasspassfailpasspass
5state_preparationPRGAViaPhaseGradient-missingmissingmissingmissingmissing
227state_preparationPrepareUniformSuperpositionc_prep_uniformpasspassunverifiedpasspass
228state_preparationPrepareUniformSuperpositionprep_uniformpasspassunverifiedpasspass
229state_preparationStatePreparationAliasSamplingstate_prep_aliaspasspassunverifiedpassunverified
230state_preparationStatePreparationViaRotationsstate_prep_via_rotationpasspassunverifiedpasspass
231swap_networkCSwapApproxapprox_cswap_largepasspasspasspasspass
232swap_networkCSwapApproxapprox_cswap_smallpasspasspasspasspass
233swap_networkCSwapApproxapprox_cswap_symbpassnaunverifiedpassmissing
234swap_networkMultiplexedCSwapmultiplexed_cswappasspasspasspasspass
235swap_networkSwapWithZeroswzpasspasspasspasspass
236swap_networkSwapWithZeroswz_smallpasspasspasspasspass
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from dev_tools.qualtran_dev_tools.bloq_report_card import get_bloq_report_card, show_bloq_report_card, record_for_bloq_example, check_bloq_example_serialize, get_bloq_examples\n", + "\n", + "df = get_bloq_report_card()\n", + "show_bloq_report_card(df)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "347e5df5-b571-47f2-b3a0-90b5978b7fe3", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3094c89a-8b0f-4cfb-a86d-69f4a825880f", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/dev_tools/qualtran_dev_tools/bloq_report_card.py b/dev_tools/qualtran_dev_tools/bloq_report_card.py index 4af1d66d5..9279daa0f 100644 --- a/dev_tools/qualtran_dev_tools/bloq_report_card.py +++ b/dev_tools/qualtran_dev_tools/bloq_report_card.py @@ -84,6 +84,8 @@ def record_for_class_with_no_examples(k: Type[Bloq]) -> Dict[str, Any]: def record_for_bloq_example(be: BloqExample) -> Dict[str, Any]: + # DO NOT SUBMIT: Remove print + print(be.name) return { 'bloq_cls': be.bloq_cls.__name__, 'package': _get_package(be.bloq_cls), @@ -114,7 +116,7 @@ def get_bloq_report_card( records = [] missing_bclasses = bloq_classes_with_no_examples(bclasses, bexamples) records.extend(record_for_class_with_no_examples(k) for k in missing_bclasses) - records.extend(record_for_bloq_example(be) for be in bexamples) + records.extend(record_for_bloq_example(be) for be in bexamples if be.name !="qubitization_qpe_hubbard_model_large") df = pd.DataFrame(records) df['package'] = df['package'].str.removeprefix(package_prefix) diff --git a/qualtran/_infra/bloq.py b/qualtran/_infra/bloq.py index c51c62060..fc624ac9f 100644 --- a/qualtran/_infra/bloq.py +++ b/qualtran/_infra/bloq.py @@ -101,6 +101,8 @@ def signature(self) -> 'Signature': `Bloq`. You can optionally implement additional methods to encode more information about this bloq. """ + def namespace(self)->str: + return self.__module__ def pretty_name(self) -> str: return self.__class__.__name__ diff --git a/qualtran/bloqs/factoring/mod_mul.py b/qualtran/bloqs/factoring/mod_mul.py index 8091c2e5b..6efdb513d 100644 --- a/qualtran/bloqs/factoring/mod_mul.py +++ b/qualtran/bloqs/factoring/mod_mul.py @@ -70,6 +70,8 @@ def __attrs_post_init__(self): def signature(self) -> 'Signature': return Signature.build(ctrl=1, x=self.bitsize) + def namespace(self) ->str: + return "qualtran."+self.__module__ def _Add(self, k: Union[int, sympy.Expr]): """Helper method to forward attributes to `CtrlScaleModAdd`.""" return CtrlScaleModAdd(k=k, bitsize=self.bitsize, mod=self.mod) diff --git a/qualtran/protos/sympy.proto b/qualtran/protos/sympy.proto index d0f23b04e..d40209ad4 100644 --- a/qualtran/protos/sympy.proto +++ b/qualtran/protos/sympy.proto @@ -53,10 +53,9 @@ message Parameter { oneof parameter { int32 const_int = 1; string symbol = 2; - // string const_irrat = 3; ConstSymbol replaces the need for const_irrat - Fraction const_rat = 4; - float const_float = 5; - ConstSymbol const_symbol = 6; + Fraction const_rat = 3; + float const_float = 4; + ConstSymbol const_symbol = 5; } } diff --git a/qualtran/scratch.py b/qualtran/scratch.py index 2aa6ff63f..7337719ee 100644 --- a/qualtran/scratch.py +++ b/qualtran/scratch.py @@ -1,35 +1,53 @@ from bloqs.factoring.mod_mul import CtrlModMul from qualtran.serialization.bloq import bloqs_from_proto, bloqs_to_proto -from qualtran.serialization.bloq import arg_to_proto, arg_from_proto import sympy -# sympy.pi -# sympy.E -# sympy.EulerGamma -# sympy.core.numbers.Infinity -# sympy.core.numbers.ImaginaryUnit - - -def parameter_test(): - const_int = sympy.parse_expr("5") - symbol = sympy.symbols("x") - fraction = sympy.parse_expr("1/2") - const_symbol = sympy.pi - const_complex = sympy.parse_expr("2j") - - expr = const_int + symbol + fraction + const_symbol + const_complex - - serialized = arg_to_proto(name="test", val=expr) - expr_clone = arg_from_proto(serialized)['test'] - print("done") - -# parameter_test() +# k, N, n_x = sympy.symbols('k N n_x') +# bloq = CtrlModMul(k=k, mod=N, bitsize=n_x) +# +# serialized = bloqs_to_proto(bloq) +# reconstructed = bloqs_from_proto(serialized) +# print("Done") +# # +# Put this into dev_tools +from dev_tools.qualtran_dev_tools.bloq_report_card import get_bloq_report_card, show_bloq_report_card, record_for_bloq_example, check_bloq_example_serialize, get_bloq_examples +from qualtran.serialization.bloq import bloqs_from_proto, bloqs_to_proto -k, N, n_x = sympy.symbols('k N n_x') -bloq = CtrlModMul(k=k, mod=N, bitsize=n_x) -serialized = bloqs_to_proto(bloq) -reconstructed = bloqs_from_proto(serialized) -print("Done") -# +wanted = [ + # "add_diff_size_regs", + # "add_large", + "add_small", + "add_oop_large", + "add_oop_small", + "int_effect", + "int_state", + "df_one_body", + "prepare_t", + "prep_nu_proj", + "prep_sparse", + "sel_sparse", + "thc_prep", + "qrom_multi_data", + "qrom_multi_dim", + "qrom_small", + "lprs_interim_prep", + "lp_resource_state_small", + "qubitization_qpe_hubbard_model_small", + "textbook_qpe_small", + "approximate_qft_from_epsilon", + "approximate_qft_small", + "two_bit_ffft", + "reflection", + "qvr_zpow" +] +bexamples = get_bloq_examples() +my_examples = [example for example in bexamples if example.name in wanted] +for example in my_examples: + print(example.name, check_bloq_example_serialize(example)) + + + bloq_lib = bloqs_to_proto(example) + bloq_roundtrip = bloqs_from_proto(bloq_lib)[0] +print("Done") \ No newline at end of file diff --git a/qualtran/serialization/bloq.py b/qualtran/serialization/bloq.py index 288f4a8af..83533833e 100644 --- a/qualtran/serialization/bloq.py +++ b/qualtran/serialization/bloq.py @@ -12,11 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. - -# Test Do not submit import dataclasses import inspect -from typing import Any, Callable, Dict, List, Optional, Union +from typing import Any, Callable, Dict, List, Optional import attrs import cirq @@ -39,7 +37,7 @@ Signature, Soquet, ) -from qualtran.protos import bloq_pb2, sympy_pb2 +from qualtran.protos import bloq_pb2 from qualtran.serialization import ( annotations, args, @@ -49,172 +47,7 @@ resolver_dict, ) - -def _get_sympy_function_type(expr: sympy.Expr) -> int: - if isinstance(expr, sympy.core.mul.Mul): - return sympy_pb2.Function.Mul - elif isinstance(expr, sympy.core.add.Add): - return sympy_pb2.Function.Add - elif isinstance(expr, sympy.core.power.Pow): - return sympy_pb2.Function.Pow - elif isinstance(expr, sympy.core.Mod): - return sympy_pb2.Function.Mod - elif isinstance(expr, sympy.functions.elementary.exponential.log): - return sympy_pb2.Function.Log - elif isinstance(expr, sympy.functions.elementary.integers.floor): - return sympy_pb2.Function.Floor - elif isinstance(expr, sympy.functions.elementary.integers.ceiling): - return sympy_pb2.Function.Ceiling - elif isinstance(expr, sympy.functions.elementary.miscellaneous.Max): - return sympy_pb2.Function.Max - elif isinstance(expr, sympy.functions.elementary.miscellaneous.Min): - return sympy_pb2.Function.Min - elif isinstance(expr, sympy.functions.elementary.trigonometric.sin): - return sympy_pb2.Function.Sin - elif isinstance(expr, sympy.functions.elementary.trigonometric.cos): - return sympy_pb2.Function.Cos - elif isinstance(expr, sympy.functions.elementary.trigonometric.tan): - return sympy_pb2.Function.Tan - else: - return sympy_pb2.Function.NONE - - -def _get_sympy_from_enum(enum: int): - enum_to_sympy = { - sympy_pb2.Function.Mul: sympy.core.mul.Mul, - sympy_pb2.Function.Add: sympy.core.add.Add, - sympy_pb2.Function.Pow: sympy.core.power.Pow, - sympy_pb2.Function.Mod: sympy.core.Mod, - sympy_pb2.Function.Log: sympy.functions.elementary.exponential.log, - sympy_pb2.Function.Floor: sympy.functions.elementary.integers.floor, - sympy_pb2.Function.Ceiling: sympy.functions.elementary.integers.ceiling, - sympy_pb2.Function.Max: sympy.functions.elementary.miscellaneous.Max, - sympy_pb2.Function.Min: sympy.functions.elementary.miscellaneous.Min, - sympy_pb2.Function.Sin: sympy.functions.elementary.trigonometric.sin, - sympy_pb2.Function.Cos: sympy.functions.elementary.trigonometric.cos, - sympy_pb2.Function.Tan: sympy.functions.elementary.trigonometric.tan, - sympy_pb2.Function.NONE: None, - } - - return enum_to_sympy[enum] - -def _get_sympy_const_from_enum(enum: int): - enum_to_sympy = { - sympy_pb2.ConstSymbol.Pi: sympy.pi, - sympy_pb2.ConstSymbol.E: sympy.E, - sympy_pb2.ConstSymbol.EulerGamma: sympy.EulerGamma, - sympy_pb2.ConstSymbol.Infinity: sympy.core.numbers.Infinity(), - sympy_pb2.ConstSymbol.ImaginaryUnit: sympy.core.numbers.ImaginaryUnit() - } - return enum_to_sympy[enum] - -def _get_const_symbolic_operand(expr: sympy.Expr): - if expr == sympy.pi: - return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.Pi) - if expr == sympy.E: - return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.E) - if expr == sympy.EulerGamma: - return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.EulerGamma) - if isinstance(expr,sympy.core.numbers.Infinity): - return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.Infinity) - if isinstance(expr, sympy.core.numbers.ImaginaryUnit): - return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.ImaginaryUnit) - else: - raise NotImplementedError(f"Sympy expression {str(expr)} cannot be serialized.") - -def _get_sympy_operand(expr: Union[sympy.Expr, int, float])->sympy_pb2.Parameter: - - # Expression is a single, symbolic variable. - if isinstance(expr, sympy.core.symbol.Symbol): - return sympy_pb2.Parameter(symbol=str(expr)) - - # Expression is an integer - if issubclass(expr.__class__, sympy.core.numbers.Integer): - result = expr.numerator - if not isinstance(result, int): - raise NotImplementedError(f"Sympy expression {str(expr)} cannot be serialized.") - return sympy_pb2.Parameter(const_int=result) - - # Expression cannot be broken down further, but is a constant. - if issubclass(expr.__class__, sympy.core.numbers.Number): - if isinstance(expr, sympy.core.numbers.Float): - return sympy_pb2.Parameter(const_float=float(expr)) - if isinstance(expr, sympy.core.numbers.Rational): - numerator = _get_sympy_operand(expr.numerator) - denominator = _get_sympy_operand(expr.denominator) - fraction = sympy_pb2.Fraction(numerator=numerator, denominator=denominator) - return sympy_pb2.Parameter(const_rat=fraction) - else: - raise NotImplementedError(f"Sympy expression {str(expr)} cannot be serialized.") - if type(expr) == int: - return sympy_pb2.Parameter(const_int=expr) - if type(expr) == float: - return sympy_pb2.Parameter(const_float=expr) - else: - return _get_const_symbolic_operand(expr) - -def decompose_sympy(expr: sympy.Expr): - function = _get_sympy_function_type(expr) - operands = [] - if function == sympy_pb2.Function.NONE: - parameter = _get_sympy_operand(expr) - operands.append(sympy_pb2.Operand(parameter=parameter)) - - else: - for term in expr.args: - inner_term = decompose_sympy(term) - - operands.append(sympy_pb2.Operand(term=inner_term)) - - return sympy_pb2.Term(function=function, operands=operands) - -def _get_parameter(serialized_input: Union[sympy_pb2.Operand, sympy_pb2.Parameter]): - if isinstance(serialized_input, sympy_pb2.Operand): - serialized_parameter = serialized_input.parameter - else: - serialized_parameter = serialized_input - - parameter_type = serialized_parameter.WhichOneof("parameter") - if parameter_type == "symbol": - deserialized_parameter = sympy.symbols(serialized_parameter.symbol) - elif parameter_type == "const_int": - deserialized_parameter = serialized_parameter.const_int - elif parameter_type == "const_rat": - fraction = serialized_parameter.const_rat - numerator = _get_parameter(fraction.numerator) - denominator = _get_parameter(fraction.denominator) - deserialized_parameter = sympy.Rational(numerator, denominator) - elif parameter_type == "const_float": - deserialized_parameter = serialized_parameter.const_float - elif parameter_type == "const_symbol": - deserialized_parameter = _get_sympy_const_from_enum(serialized_parameter.const_symbol) - else: - raise TypeError(f"Type is not supported for {serialized_input}") - - return deserialized_parameter - - -def _set_function(function, parameters): - return function(parameters) - - -def compose_sympy(expr: sympy.Expr): - function = _get_sympy_from_enum(expr.function) - parameters = [] - for operand in expr.operands: - if operand.HasField("term"): - parameters.append(compose_sympy(operand.term)) - else: - parameter = _get_parameter(operand) - parameters.append(parameter) - - if function: - return function(*parameters) - elif len(parameters) == 1: - return parameters[0] - else: - raise NotImplementedError(f"{expr.function} has not been fully implimented.") - +from qualtran.serialization.sympy import sympy_expr_from_proto, sympy_expr_to_proto def arg_to_proto(*, name: str, val: Any) -> bloq_pb2.BloqArg: if isinstance(val, int): @@ -224,7 +57,7 @@ def arg_to_proto(*, name: str, val: Any) -> bloq_pb2.BloqArg: if isinstance(val, str): return bloq_pb2.BloqArg(name=name, string_val=val) if isinstance(val, sympy.Expr): - return bloq_pb2.BloqArg(name=name, sympy_expr=decompose_sympy(val)) + return bloq_pb2.BloqArg(name=name, sympy_expr=sympy_expr_to_proto(val)) if isinstance(val, Register): return bloq_pb2.BloqArg(name=name, register=registers.register_to_proto(val)) if isinstance(val, tuple) and all(isinstance(x, Register) for x in val): @@ -250,7 +83,7 @@ def arg_from_proto(arg: bloq_pb2.BloqArg) -> Dict[str, Any]: if arg.HasField("string_val"): return {arg.name: arg.string_val} if arg.HasField("sympy_expr"): - return {arg.name: compose_sympy(arg.sympy_expr)} + return {arg.name: sympy_expr_from_proto(arg.sympy_expr)} if arg.HasField("register"): return {arg.name: registers.register_from_proto(arg.register)} if arg.HasField("registers"): @@ -486,9 +319,7 @@ def _bloq_to_proto(bloq: Bloq, *, bloq_to_idx: Dict[Bloq, int]) -> bloq_pb2.Bloq except (DecomposeTypeError, DecomposeNotImplementedError, TypeError): t_complexity = None - name = bloq.__module__ + "." + bloq.__class__.__qualname__ - if not name.startswith("qualtran."): - name = "qualtran."+name + name = bloq.namespace() + "." + bloq.__class__.__qualname__ return bloq_pb2.Bloq( name=name, registers=registers.registers_to_proto(bloq.signature), diff --git a/qualtran/serialization/sympy.py b/qualtran/serialization/sympy.py new file mode 100644 index 000000000..a10bd4682 --- /dev/null +++ b/qualtran/serialization/sympy.py @@ -0,0 +1,212 @@ +# 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. + +import sympy +from qualtran.protos import sympy_pb2 +from typing import Union, Any +def _get_sympy_function_type(expr: sympy.Expr) -> int: + """ + Helper function for serializing a sympy function. + + This method converts a sympy function to its sympy_pb2.Function enum representation. + """ + if isinstance(expr, sympy.core.mul.Mul): + return sympy_pb2.Function.Mul + elif isinstance(expr, sympy.core.add.Add): + return sympy_pb2.Function.Add + elif isinstance(expr, sympy.core.power.Pow): + return sympy_pb2.Function.Pow + elif isinstance(expr, sympy.core.Mod): + return sympy_pb2.Function.Mod + elif isinstance(expr, sympy.functions.elementary.exponential.log): + return sympy_pb2.Function.Log + elif isinstance(expr, sympy.functions.elementary.integers.floor): + return sympy_pb2.Function.Floor + elif isinstance(expr, sympy.functions.elementary.integers.ceiling): + return sympy_pb2.Function.Ceiling + elif isinstance(expr, sympy.functions.elementary.miscellaneous.Max): + return sympy_pb2.Function.Max + elif isinstance(expr, sympy.functions.elementary.miscellaneous.Min): + return sympy_pb2.Function.Min + elif isinstance(expr, sympy.functions.elementary.trigonometric.sin): + return sympy_pb2.Function.Sin + elif isinstance(expr, sympy.functions.elementary.trigonometric.cos): + return sympy_pb2.Function.Cos + elif isinstance(expr, sympy.functions.elementary.trigonometric.tan): + return sympy_pb2.Function.Tan + else: + return sympy_pb2.Function.NONE + +def _get_sympy_function_from_enum(enum: int)->Any: + """ + Helper function for sympy function deserialization. + + Sympy functions are represented as a sympy_pb2.Function enum. This mehtod converts this int enum + back into the sympy function. + """ + enum_to_sympy = { + sympy_pb2.Function.Mul: sympy.core.mul.Mul, + sympy_pb2.Function.Add: sympy.core.add.Add, + sympy_pb2.Function.Pow: sympy.core.power.Pow, + sympy_pb2.Function.Mod: sympy.core.Mod, + sympy_pb2.Function.Log: sympy.functions.elementary.exponential.log, + sympy_pb2.Function.Floor: sympy.functions.elementary.integers.floor, + sympy_pb2.Function.Ceiling: sympy.functions.elementary.integers.ceiling, + sympy_pb2.Function.Max: sympy.functions.elementary.miscellaneous.Max, + sympy_pb2.Function.Min: sympy.functions.elementary.miscellaneous.Min, + sympy_pb2.Function.Sin: sympy.functions.elementary.trigonometric.sin, + sympy_pb2.Function.Cos: sympy.functions.elementary.trigonometric.cos, + sympy_pb2.Function.Tan: sympy.functions.elementary.trigonometric.tan, + sympy_pb2.Function.NONE: None, + } + + return enum_to_sympy[enum] + +def _get_sympy_const_from_enum(enum: int)->Any: + """Helper function for deserializing a sympy symbolic constant. + + Symbolic constants are serialzed as an enum of type sympy_pb2.ConstSymbol. This method converts the + enum representation back to its original sympy representation. + """ + enum_to_sympy = { + sympy_pb2.ConstSymbol.Pi: sympy.pi, + sympy_pb2.ConstSymbol.E: sympy.E, + sympy_pb2.ConstSymbol.EulerGamma: sympy.EulerGamma, + sympy_pb2.ConstSymbol.Infinity: sympy.core.numbers.Infinity(), + sympy_pb2.ConstSymbol.ImaginaryUnit: sympy.core.numbers.ImaginaryUnit() + } + return enum_to_sympy[enum] + +def _get_const_symbolic_operand(expr: sympy.Expr)->sympy_pb2.Parameter: + """ + Helper function for serializing a symbolic constant from a sympy expression. + + Currently supported symbolic constants are: pi, natural exponent, EulerGamma, sqrt(-1), and infinity. + """ + if expr == sympy.pi: + return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.Pi) + if expr == sympy.E: + return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.E) + if expr == sympy.EulerGamma: + return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.EulerGamma) + if isinstance(expr,sympy.core.numbers.Infinity): + return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.Infinity) + if isinstance(expr, sympy.core.numbers.ImaginaryUnit): + return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.ImaginaryUnit) + else: + raise NotImplementedError(f"Sympy expression {str(expr)} cannot be serialized.") + +def _get_sympy_operand(expr: Union[sympy.Expr, int, float])->sympy_pb2.Parameter: + """ + Converts the input to a serializable sympy_pb2 Parameter. + + A parameter represents a single, irreducable numeric entity such as a variable, constant, or an explicit number. + """ + + # Expression is a single, symbolic variable. + if isinstance(expr, sympy.core.symbol.Symbol): + return sympy_pb2.Parameter(symbol=str(expr)) + + # Expression is an integer + if issubclass(expr.__class__, sympy.core.numbers.Integer): + result = expr.numerator + if not isinstance(result, int): + raise NotImplementedError(f"Sympy expression {str(expr)} cannot be serialized.") + return sympy_pb2.Parameter(const_int=result) + + # Expression cannot be broken down further, but is a constant. + if issubclass(expr.__class__, sympy.core.numbers.Number): + if isinstance(expr, sympy.core.numbers.Float): + return sympy_pb2.Parameter(const_float=float(expr)) + if isinstance(expr, sympy.core.numbers.Rational): + numerator = _get_sympy_operand(expr.numerator) + denominator = _get_sympy_operand(expr.denominator) + fraction = sympy_pb2.Fraction(numerator=numerator, denominator=denominator) + return sympy_pb2.Parameter(const_rat=fraction) + else: + raise NotImplementedError(f"Sympy expression {str(expr)} cannot be serialized.") + if type(expr) == int: + return sympy_pb2.Parameter(const_int=expr) + if type(expr) == float: + return sympy_pb2.Parameter(const_float=expr) + else: + return _get_const_symbolic_operand(expr) + +def sympy_expr_to_proto(expr: sympy.Expr)-> sympy_pb2.Term: + """Serializes a sympy expression.""" + + function = _get_sympy_function_type(expr) + operands = [] + if function == sympy_pb2.Function.NONE: + parameter = _get_sympy_operand(expr) + operands.append(sympy_pb2.Operand(parameter=parameter)) + + else: + for term in expr.args: + inner_term = sympy_expr_to_proto(term) + + operands.append(sympy_pb2.Operand(term=inner_term)) + + return sympy_pb2.Term(function=function, operands=operands) + +def _get_parameter(serialized_input: Union[sympy_pb2.Operand, sympy_pb2.Parameter])->Any: + """ + Deserializes a parameter. + + Deserializes a parameter or operand into either its sympy representation or its + python primative numeric representation. + """ + if isinstance(serialized_input, sympy_pb2.Operand): + serialized_parameter = serialized_input.parameter + else: + serialized_parameter = serialized_input + + parameter_type = serialized_parameter.WhichOneof("parameter") + if parameter_type == "symbol": + deserialized_parameter = sympy.symbols(serialized_parameter.symbol) + elif parameter_type == "const_int": + deserialized_parameter = serialized_parameter.const_int + elif parameter_type == "const_rat": + fraction = serialized_parameter.const_rat + numerator = _get_parameter(fraction.numerator) + denominator = _get_parameter(fraction.denominator) + deserialized_parameter = sympy.Rational(numerator, denominator) + elif parameter_type == "const_float": + deserialized_parameter = serialized_parameter.const_float + elif parameter_type == "const_symbol": + deserialized_parameter = _get_sympy_const_from_enum(serialized_parameter.const_symbol) + else: + raise TypeError(f"Type is not supported for {serialized_input}") + + return deserialized_parameter + + +def sympy_expr_from_proto(term: sympy_pb2.Term)->Any: + """Deserialize a sympy expression.""" + + function = _get_sympy_function_from_enum(term.function) + parameters = [] + for operand in term.operands: + if operand.HasField("term"): + parameters.append(sympy_expr_from_proto(operand.term)) + else: + parameter = _get_parameter(operand) + parameters.append(parameter) + + if function: + return function(*parameters) + elif len(parameters) == 1: + return parameters[0] + else: + raise NotImplementedError(f"{term.function} has not been fully implimented.") \ No newline at end of file diff --git a/qualtran/serialization/sympy_test.py b/qualtran/serialization/sympy_test.py new file mode 100644 index 000000000..e13a73f7e --- /dev/null +++ b/qualtran/serialization/sympy_test.py @@ -0,0 +1,46 @@ +# 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. + +import sympy +import pytest +from qualtran.serialization.bloq import arg_to_proto, arg_from_proto + +@pytest.mark.parametrize( + 'expr', + [ + (sympy.parse_expr("5")+sympy.symbols("x")+sympy.parse_expr("1/2")+sympy.pi+sympy.parse_expr("2j")), + (sympy.parse_expr("(-b + sqrt(-4*a*c + b**2))/(2*a)")) + ], +) +def parameter_test(expr: sympy.Expr): + """ + Test types of expressions including fraction, complex, and constant symbol (such as pi). + """ + + serialized = arg_to_proto(name="test", val=expr) + expr_clone = arg_from_proto(serialized)['test'] + assert expr == expr_clone + +def float_fraction_test(): + """ + Test that floats and fractions can be properly combined and serialzed. + """ + float = sympy.parse_expr("1.4") + fraction = sympy.parse_expr("1/2") + expr = float*fraction + + serialized = arg_to_proto(name="test", val=expr) + expr_clone = arg_from_proto(serialized)['test'] + assert abs(expr - expr_clone) < .001 + From eb13fa858d0ec0242912a43ae62ccd745e5e5a28 Mon Sep 17 00:00:00 2001 From: local_linix Date: Mon, 15 Apr 2024 17:49:47 -0700 Subject: [PATCH 28/34] Ran formatting tools --- Untitled.ipynb | 2868 ----------------- .../qualtran_dev_tools/bloq_report_card.py | 6 +- qualtran/_infra/bloq.py | 3 +- .../chemistry/trotter/hubbard/hopping.py | 4 +- qualtran/bloqs/factoring/mod_mul.py | 5 +- qualtran/protos/sympy_pb2.py | 2 +- qualtran/protos/sympy_pb2.pyi | 3 +- qualtran/scratch.py | 53 - qualtran/serialization/bloq.py | 2 +- qualtran/serialization/sympy.py | 32 +- qualtran/serialization/sympy_test.py | 24 +- 11 files changed, 51 insertions(+), 2951 deletions(-) delete mode 100644 Untitled.ipynb delete mode 100644 qualtran/scratch.py diff --git a/Untitled.ipynb b/Untitled.ipynb deleted file mode 100644 index 111213c38..000000000 --- a/Untitled.ipynb +++ /dev/null @@ -1,2868 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "259ed492-c91a-441c-8cf2-399ceb7920c4", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "add_diff_size_regs\n", - "add_k_large\n", - "add_k_small\n", - "add_k_symb\n", - "add_large\n", - "add_oop_large\n", - "add_oop_small\n", - "add_oop_symb\n", - "add_small\n", - "add_symb\n", - "simple_add_k_large\n", - "simple_add_k_small\n", - "bi_qubits_mixer\n", - "eq_k\n", - "greater_than\n", - "gt_k\n", - "leq\n", - "leq_symb\n", - "lt_k\n", - "lt_k_symb\n", - "sq_cmp\n", - "signed_to_twos\n", - "to_contg_index\n", - "multiply_two_reals\n", - "plus_equal_product\n", - "product\n", - "scale_int_by_real\n", - "square\n", - "square_real_number\n", - "sum_of_squares\n", - "bitonic_sort\n", - "cmp_symb\n", - "cnot\n", - "global_phase\n", - "hadamard\n", - "rx\n", - "ry\n", - "rz\n", - "x_pow\n", - "y_pow\n", - "z_pow\n", - "s_gate\n", - "hadamard\n", - "su2_rotation_gate\n", - "t_gate\n", - "cswap_large\n", - "cswap_small\n", - "cswap_symb\n", - "swap_small\n", - "t_gate\n", - "toffoli\n", - "minus_effect\n", - "minus_state\n", - "plus_effect\n", - "plus_state\n", - "int_effect\n", - "int_state\n", - "one_effect\n", - "one_state\n", - "zero_effect\n", - "zero_state\n", - "zgate\n", - "black_box_block_bloq\n", - "black_box_prepare\n", - "black_box_select\n", - "chebyshev_poly\n", - "df_block_encoding\n", - "df_one_body\n", - "indexed_data\n", - "prep_inner\n", - "prep_outer\n", - "prepare_t\n", - "prepare_uv\n", - "prep_mu_proj\n", - "prep_nu_proj\n", - "prep_power_two_proj\n", - "prep_t_proj\n", - "prep_uv_proj\n", - "prep_first_quant\n", - "sel_first_quant\n", - "sel_t_proj\n", - "sel_uv_proj\n", - "prep_first_quant\n", - "sel_first_quant\n", - "select_t\n", - "select_uv\n", - "prep_inner\n", - "prep_outer\n", - "select\n", - "sf_block_encoding\n", - "sf_one_body\n", - "prep_sparse\n", - "sel_sparse\n", - "thc_prep\n", - "thc_uni\n", - "thc_sel\n", - "nr_inv_sqrt\n", - "poly_inv_sqrt\n", - "kinetic_energy\n", - "pair_potential\n", - "potential_energy\n", - "qvr\n", - "hopping_tile\n", - "plaquette\n", - "interaction\n", - "ising_x\n", - "ising_zz\n", - "trott_unitary\n", - "qrom_multi_data\n", - "qrom_multi_dim\n", - "qrom_small\n", - "modexp\n", - "modexp_small\n", - "modexp_symb\n", - "modmul\n", - "modmul_symb\n", - "hubbard_time_evolution_by_gqsp\n", - "and_bloq\n", - "multi_and\n", - "c_multi_not\n", - "c_multi_not_symb\n", - "ccpauli\n", - "apply_z_to_odd\n", - "select_pauli_lcu\n", - "lp_resource_state_small\n", - "lp_resource_state_symbolic\n", - "lprs_interim_prep\n", - "qubitization_qpe_hubbard_model_small\n", - "textbook_qpe_from_precision_and_delta\n", - "textbook_qpe_from_standard_deviation_eps\n", - "textbook_qpe_small\n", - "textbook_qpe_using_m_bits\n", - "approximate_qft_from_epsilon\n", - "approximate_qft_small\n", - "two_bit_ffft\n", - "gqsp\n", - "gqsp_with_large_negative_power\n", - "gqsp_with_negative_power\n", - "walk_op\n", - "reflection\n", - "square_via_phase_gradient\n", - "square_via_zpow_phasing\n", - "qvr_phase_gradient\n", - "qvr_zpow\n", - "c_prep_uniform\n", - "prep_uniform\n", - "state_prep_alias\n", - "state_prep_via_rotation\n", - "approx_cswap_large\n", - "approx_cswap_small\n", - "approx_cswap_symb\n", - "multiplexed_cswap\n", - "swz\n", - "swz_small\n" - ] - }, - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 packagebloq_clsnamemakedecompcountsserializetyping
83arithmeticAddadd_diff_size_regspasspassfailpasspass
87arithmeticAddadd_largepasspassfailpasspass
91arithmeticAddadd_smallpasspassfailpasspass
92arithmeticAddadd_symbpassnaunverifiedpassmissing
84arithmeticAddConstantModadd_k_largepassmissingunverifiedpassmissing
85arithmeticAddConstantModadd_k_smallpassmissingunverifiedpassmissing
86arithmeticAddConstantModadd_k_symbpassnaunverifiedpassmissing
95arithmeticBiQubitsMixerbi_qubits_mixerpasspassunverifiedpasspass
113arithmeticBitonicSortbitonic_sortpassmissingmissingpassmissing
114arithmeticComparatorcmp_symbpassmissingmissingpassmissing
96arithmeticEqualsAConstanteq_kpassmissingunverifiedpassmissing
97arithmeticGreaterThangreater_thanpassmissingunverifiedpassmissing
98arithmeticGreaterThanConstantgt_kpassmissingunverifiedpassmissing
9arithmeticHammingWeightCompute-missingmissingmissingmissingmissing
101arithmeticLessThanConstantlt_kpasspassunverifiedpasspass
102arithmeticLessThanConstantlt_k_symbpassnamissingpassmissing
99arithmeticLessThanEqualleqpasspassunverifiedpasspass
100arithmeticLessThanEqualleq_symbpassnamissingpassmissing
75arithmeticLinearDepthGreaterThan-missingmissingmissingmissingmissing
106arithmeticMultiplyTwoRealsmultiply_two_realspassmissingunverifiedpassmissing
88arithmeticOutOfPlaceAdderadd_oop_largepasspassfailpasspass
89arithmeticOutOfPlaceAdderadd_oop_smallpasspassfailpasspass
90arithmeticOutOfPlaceAdderadd_oop_symbpassnaunverifiedpassmissing
107arithmeticPlusEqualProductplus_equal_productpassmissingunverifiedpassmissing
108arithmeticProductproductpassmissingunverifiedpassmissing
109arithmeticScaleIntByRealscale_int_by_realpassmissingunverifiedpassmissing
104arithmeticSignedIntegerToTwosComplementsigned_to_twospassmissingunverifiedpassmissing
93arithmeticSimpleAddConstantsimple_add_k_largepasspassunverifiedpasspass
94arithmeticSimpleAddConstantsimple_add_k_smallpasspassunverifiedpasspass
103arithmeticSingleQubitComparesq_cmppasspassunverifiedpasspass
110arithmeticSquaresquarepassmissingunverifiedpassmissing
111arithmeticSquareRealNumbersquare_real_numberpassmissingunverifiedpassmissing
112arithmeticSumOfSquaressum_of_squarespassmissingunverifiedpassmissing
105arithmeticToContiguousIndexto_contg_indexpassmissingunverifiedpassmissing
115basic_gatesCNOTcnotpassnamissingpassmissing
128basic_gatesCSwapcswap_largepasspasspasspasspass
129basic_gatesCSwapcswap_smallpasspasspasspasspass
130basic_gatesCSwapcswap_symbpassnaunverifiedpassmissing
1basic_gatesCZPowGate-missingmissingmissingmissingmissing
116basic_gatesGlobalPhaseglobal_phasepassnamissingpassmissing
117basic_gatesHadamardhadamardpassnamissingpassmissing
138basic_gatesIntEffectint_effectpasspassfailpasspass
139basic_gatesIntStateint_statepasspassfailpasspass
134basic_gatesMinusEffectminus_effectpassmissingmissingpassmissing
135basic_gatesMinusStateminus_statepassmissingmissingpassmissing
71basic_gatesOnEach-missingmissingmissingmissingmissing
140basic_gatesOneEffectone_effectpassnamissingpassmissing
141basic_gatesOneStateone_statepassnamissingpassmissing
136basic_gatesPlusEffectplus_effectpassmissingmissingpassmissing
137basic_gatesPlusStateplus_statepassmissingmissingpassmissing
118basic_gatesRxrxpassnamissingpassmissing
119basic_gatesRyrypassnamissingpassmissing
120basic_gatesRzrzpassnamissingpassmissing
124basic_gatesSGates_gatepassmissingmissingpassmissing
125basic_gatesSU2RotationGatehadamardpasspassunverifiedpasspass
126basic_gatesSU2RotationGatesu2_rotation_gatepasspassunverifiedpasspass
127basic_gatesSU2RotationGatet_gatepasspassunverifiedpasspass
131basic_gatesSwapswap_smallpasspasspasspasspass
132basic_gatesTGatet_gatepassmissingmissingpassmissing
133basic_gatesToffolitoffolipassmissingunverifiedpassmissing
79basic_gatesTwoBitCSwap-missingmissingmissingmissingmissing
48basic_gatesTwoBitSwap-missingmissingmissingmissingmissing
66basic_gatesXGate-missingmissingmissingmissingmissing
121basic_gatesXPowGatex_powpassnamissingpassmissing
28basic_gatesYGate-missingmissingmissingmissingmissing
122basic_gatesYPowGatey_powpassnamissingpassmissing
144basic_gatesZGatezgatepassnamissingpassmissing
123basic_gatesZPowGatez_powpassnamissingpassmissing
142basic_gatesZeroEffectzero_effectpassnamissingpassmissing
143basic_gatesZeroStatezero_statepassnamissingpassmissing
39chemistryApplyControlledZs-missingmissingmissingmissingmissing
8chemistryQROAM-missingmissingmissingmissingmissing
50chemistryQROAMTwoRegs-missingmissingmissingmissingmissing
149chemistry.dfDoubleFactorizationBlockEncodingdf_block_encodingpasspassunverifiedpasspass
150chemistry.dfDoubleFactorizationOneBodydf_one_bodypasspassfailpasspass
152chemistry.dfInnerPrepareDoubleFactorizationprep_innerpassmissingunverifiedpassmissing
153chemistry.dfOuterPrepareDoubleFactorizationprep_outerpassmissingunverifiedpassmissing
151chemistry.dfOutputIndexedDataindexed_datapassmissingunverifiedpassmissing
30chemistry.dfProgRotGateArray-missingmissingmissingmissingmissing
32chemistry.pbc.first_quantizationApplyNuclearPhase-missingmissingmissingmissingmissing
26chemistry.pbc.first_quantizationFlagZeroAsFailure-missingmissingmissingmissingmissing
2chemistry.pbc.first_quantizationMultiplexedCSwap3D-missingmissingmissingmissingmissing
165chemistry.pbc.first_quantizationPrepareFirstQuantizationprep_first_quantpasspassunverifiedpassunverified
27chemistry.pbc.first_quantizationPrepareMuUnaryEncodedOneHot-missingmissingmissingmissingmissing
55chemistry.pbc.first_quantizationPrepareNuState-missingmissingmissingmissingmissing
80chemistry.pbc.first_quantizationPrepareNuSuperPositionState-missingmissingmissingmissingmissing
63chemistry.pbc.first_quantizationPreparePowerTwoState-missingmissingmissingmissingmissing
154chemistry.pbc.first_quantizationPrepareTFirstQuantizationprepare_tpasspassfailpasspass
56chemistry.pbc.first_quantizationPrepareTUVSuperpositions-missingmissingmissingmissingmissing
155chemistry.pbc.first_quantizationPrepareUVFirstQuantizationprepare_uvpasspasspasspasspass
15chemistry.pbc.first_quantizationPrepareZetaState-missingmissingmissingmissingmissing
166chemistry.pbc.first_quantizationSelectFirstQuantizationsel_first_quantpasspassunverifiedpassunverified
167chemistry.pbc.first_quantizationSelectTFirstQuantizationselect_tpassmissingunverifiedpassmissing
168chemistry.pbc.first_quantizationSelectUVFirstQuantizationselect_uvpassmissingunverifiedpassmissing
61chemistry.pbc.first_quantizationTestNuInequality-missingmissingmissingmissingmissing
11chemistry.pbc.first_quantizationTestNuLessThanMu-missingmissingmissingmissingmissing
12chemistry.pbc.first_quantizationUniformSuperpostionIJFirstQuantization-missingmissingmissingmissingmissing
34chemistry.pbc.first_quantizationUniformSuperpostionIJFirstQuantization-missingmissingmissingmissingmissing
47chemistry.pbc.first_quantization.projectileControlledMultiplexedCSwap3D-missingmissingmissingmissingmissing
161chemistry.pbc.first_quantization.projectilePrepareFirstQuantizationWithProjprep_first_quantpasspassunverifiedpassunverified
156chemistry.pbc.first_quantization.projectilePrepareMuUnaryEncodedOneHotWithProjprep_mu_projpassmissingunverifiedpassmissing
157chemistry.pbc.first_quantization.projectilePrepareNuStateWithProjprep_nu_projpasspassfailpasspass
158chemistry.pbc.first_quantization.projectilePreparePowerTwoStateWithProjprep_power_two_projpassmissingunverifiedpassmissing
159chemistry.pbc.first_quantization.projectilePrepareTFirstQuantizationWithProjprep_t_projpassmissingunverifiedpassmissing
64chemistry.pbc.first_quantization.projectilePrepareTUVSuperpositions-missingmissingmissingmissingmissing
160chemistry.pbc.first_quantization.projectilePrepareUVFirstQuantizationWithProjprep_uv_projpasspasspasspasspass
162chemistry.pbc.first_quantization.projectileSelectFirstQuantizationWithProjsel_first_quantpasspassunverifiedpassunverified
163chemistry.pbc.first_quantization.projectileSelectTFirstQuantizationWithProjsel_t_projpassmissingunverifiedpassmissing
164chemistry.pbc.first_quantization.projectileSelectUVFirstQuantizationWithProjsel_uv_projpassmissingunverifiedpassmissing
169chemistry.sfInnerPrepareSingleFactorizationprep_innerpassmissingunverifiedpassmissing
170chemistry.sfOuterPrepareSingleFactorizationprep_outerpassmissingunverifiedpassmissing
171chemistry.sfSelectSingleFactorizationselectpassmissingunverifiedpassmissing
172chemistry.sfSingleFactorizationBlockEncodingsf_block_encodingpasspassunverifiedpassunverified
173chemistry.sfSingleFactorizationOneBodysf_one_bodypasspasspasspassunverified
174chemistry.sparsePrepareSparseprep_sparsepasspassfailfailunverified
175chemistry.sparseSelectSparsesel_sparsepasspassfailpasspass
176chemistry.thcPrepareTHCthc_preppasspassfailfailunverified
178chemistry.thcSelectTHCthc_selpasspassunverifiedpassunverified
20chemistry.thcTHCRotations-missingmissingmissingmissingmissing
177chemistry.thcUniformSuperpositionTHCthc_unipasspassunverifiedpassunverified
190chemistry.trotterTrotterizedUnitarytrott_unitarypasspassunverifiedfailpass
181chemistry.trotter.grid_hamKineticEnergykinetic_energypasspassunverifiedpassunverified
179chemistry.trotter.grid_hamNewtonRaphsonApproxInverseSquareRootnr_inv_sqrtpassmissingunverifiedpassmissing
182chemistry.trotter.grid_hamPairPotentialpair_potentialpasspassunverifiedpassunverified
180chemistry.trotter.grid_hamPolynmomialEvaluationInverseSquareRootpoly_inv_sqrtpassmissingunverifiedpassmissing
183chemistry.trotter.grid_hamPotentialEnergypotential_energypasspassunverifiedpasspass
184chemistry.trotter.grid_hamQuantumVariableRotationqvrpassmissingunverifiedpassmissing
186chemistry.trotter.hubbardHoppingPlaquetteplaquettepassmissingunverifiedpassmissing
185chemistry.trotter.hubbardHoppingTilehopping_tilepassmissingunverifiedpassmissing
187chemistry.trotter.hubbardInteractioninteractionpassmissingunverifiedpassmissing
188chemistry.trotter.isingIsingXUnitaryising_xpasspassunverifiedpasspass
189chemistry.trotter.isingIsingZZUnitaryising_zzpasspassunverifiedpasspass
191data_loadingQROMqrom_multi_datapasspassfailpasspass
192data_loadingQROMqrom_multi_dimpasspassfailpasspass
193data_loadingQROMqrom_smallpasspassfailpasspass
31data_loadingSelectSwapQROM-missingmissingmissingmissingmissing
51factoringCtrlAddK-missingmissingmissingmissingmissing
76factoringCtrlModAddK-missingmissingmissingmissingmissing
197factoringCtrlModMulmodmulpasspasspassfailunverified
198factoringCtrlModMulmodmul_symbpasspasspassfailunverified
38factoringCtrlScaleModAdd-missingmissingmissingmissingmissing
194factoringModExpmodexppasspasspassfailunverified
195factoringModExpmodexp_smallpasspasspassfailunverified
196factoringModExpmodexp_symbpassnaunverifiedfailmissing
24factoringMontgomeryModAdd-missingmissingmissingmissingmissing
0factoringMontgomeryModDbl-missingmissingmissingmissingmissing
53factoringMontgomeryModNeg-missingmissingmissingmissingmissing
69factoringMontgomeryModSub-missingmissingmissingmissingmissing
42for_testingInteriorAlloc-missingmissingmissingmissingmissing
41for_testingPauliSelectOracle-missingmissingmissingmissingmissing
13for_testingRandomGate-missingmissingmissingmissingmissing
22for_testingRandomPrepareOracle-missingmissingmissingmissingmissing
77for_testingTestAtom-missingmissingmissingmissingmissing
43for_testingTestBloqWithCallGraph-missingmissingmissingmissingmissing
33for_testingTestBoundedQUInt-missingmissingmissingmissingmissing
78for_testingTestCastToFrom-missingmissingmissingmissingmissing
10for_testingTestGWRAtom-missingmissingmissingmissingmissing
74for_testingTestIndependentParallelCombo-missingmissingmissingmissingmissing
82for_testingTestMultiRegister-missingmissingmissingmissingmissing
54for_testingTestMultiTypedRegister-missingmissingmissingmissingmissing
40for_testingTestParallelCombo-missingmissingmissingmissingmissing
70for_testingTestQFxp-missingmissingmissingmissingmissing
73for_testingTestSerialCombo-missingmissingmissingmissingmissing
3for_testingTestTwoBitOp-missingmissingmissingmissingmissing
199hamiltonian_simulationHamiltonianSimulationByGQSPhubbard_time_evolution_by_gqsppasspasspassfailpass
200mcmtAndand_bloqpasspasspasspasspass
201mcmtMultiAndmulti_andpasspasspasspasspass
204mcmtMultiControlPauliccpaulipasspasspasspasspass
57mcmtMultiControlX-missingmissingmissingmissingmissing
202mcmtMultiTargetCNOTc_multi_notpasspassunverifiedpasspass
203mcmtMultiTargetCNOTc_multi_not_symbpassnamissingpassmissing
6mean_estimationArcTan-missingmissingmissingmissingmissing
58mean_estimationComplexPhaseOracle-missingmissingmissingmissingmissing
60mean_estimationMeanEstimationOperator-missingmissingmissingmissingmissing
205multiplexersApplyGateToLthQubitapply_z_to_oddpasspasspassfailpass
206multiplexersSelectPauliLCUselect_pauli_lcupasspasspassfailpass
49multiplexersSelectedMajoranaFermion-missingmissingmissingmissingmissing
18multiplexersUnaryIterationGate-missingmissingmissingmissingmissing
209phase_estimationLPRSInterimPreplprs_interim_preppasspassfailpasspass
207phase_estimationLPResourceStatelp_resource_state_smallpasspassfailpassunverified
208phase_estimationLPResourceStatelp_resource_state_symbolicpassnaerrorfailmissing
210phase_estimationQubitizationQPEqubitization_qpe_hubbard_model_smallpasspassfailpassunverified
211phase_estimationTextbookQPEtextbook_qpe_from_precision_and_deltapassnaunverifiedfailmissing
212phase_estimationTextbookQPEtextbook_qpe_from_standard_deviation_epspassnaunverifiedfailmissing
213phase_estimationTextbookQPEtextbook_qpe_smallpasspassfailpassunverified
214phase_estimationTextbookQPEtextbook_qpe_using_m_bitspassnaunverifiedfailmissing
215qftApproximateQFTapproximate_qft_from_epsilonpasspassfailpasspass
216qftApproximateQFTapproximate_qft_smallpasspassfailpasspass
19qftQFTPhaseGradient-missingmissingmissingmissingmissing
25qftQFTTextBook-missingmissingmissingmissingmissing
217qftTwoBitFFFTtwo_bit_ffftpasspassfailpasspass
218qspGeneralizedQSPgqsppasspasspasspasspass
219qspGeneralizedQSPgqsp_with_large_negative_powerpasspasspasspasspass
220qspGeneralizedQSPgqsp_with_negative_powerpasspasspasspasspass
44qualtran.bloqsAllocate-missingmissingmissingmissingmissing
45qualtran.bloqsArbitraryClifford-missingmissingmissingmissingmissing
145qualtran.bloqsBlackBoxBlockEncodingblack_box_block_bloqpasspassunverifiedpasspass
146qualtran.bloqsBlackBoxPrepareblack_box_preparepasspassunverifiedpasspass
147qualtran.bloqsBlackBoxSelectblack_box_selectpasspassunverifiedpasspass
21qualtran.bloqsCast-missingmissingmissingmissingmissing
148qualtran.bloqsChebyshevPolynomialchebyshev_polypasspasspasspasspass
62qualtran.bloqsFree-missingmissingmissingmissingmissing
23qualtran.bloqsJoin-missingmissingmissingmissingmissing
17qualtran.bloqsPartition-missingmissingmissingmissingmissing
72qualtran.bloqsPower-missingmissingmissingmissingmissing
81qualtran.bloqsPrepareHubbard-missingmissingmissingmissingmissing
65qualtran.bloqsPrepareOracle-missingmissingmissingmissingmissing
221qualtran.bloqsQubitizationWalkOperatorwalk_oppasspassunverifiedfailpass
222qualtran.bloqsReflectionreflectionpasspassfailpasspass
46qualtran.bloqsReflectionUsingPrepare-missingmissingmissingmissingmissing
68qualtran.bloqsSelectHubbard-missingmissingmissingmissingmissing
36qualtran.bloqsSelectOracle-missingmissingmissingmissingmissing
37qualtran.bloqsSplit-missingmissingmissingmissingmissing
4rotationsAddIntoPhaseGrad-missingmissingmissingmissingmissing
52rotationsAddScaledValIntoPhaseReg-missingmissingmissingmissingmissing
14rotationsHammingWeightPhasing-missingmissingmissingmissingmissing
29rotationsHammingWeightPhasingViaPhaseGradient-missingmissingmissingmissingmissing
67rotationsPhaseGradientState-missingmissingmissingmissingmissing
16rotationsPhaseGradientUnitary-missingmissingmissingmissingmissing
223rotationsPhasingViaCostFunctionsquare_via_phase_gradientpasspassunverifiedpassunverified
224rotationsPhasingViaCostFunctionsquare_via_zpow_phasingpasspassunverifiedpassunverified
35rotationsProgrammableRotationGateArray-missingmissingmissingmissingmissing
7rotationsProgrammableRotationGateArrayBase-missingmissingmissingmissingmissing
59rotationsQvrInterface-missingmissingmissingmissingmissing
225rotationsQvrPhaseGradientqvr_phase_gradientpasspasspasspasspass
226rotationsQvrZPowqvr_zpowpasspassfailpasspass
5state_preparationPRGAViaPhaseGradient-missingmissingmissingmissingmissing
227state_preparationPrepareUniformSuperpositionc_prep_uniformpasspassunverifiedpasspass
228state_preparationPrepareUniformSuperpositionprep_uniformpasspassunverifiedpasspass
229state_preparationStatePreparationAliasSamplingstate_prep_aliaspasspassunverifiedpassunverified
230state_preparationStatePreparationViaRotationsstate_prep_via_rotationpasspassunverifiedpasspass
231swap_networkCSwapApproxapprox_cswap_largepasspasspasspasspass
232swap_networkCSwapApproxapprox_cswap_smallpasspasspasspasspass
233swap_networkCSwapApproxapprox_cswap_symbpassnaunverifiedpassmissing
234swap_networkMultiplexedCSwapmultiplexed_cswappasspasspasspasspass
235swap_networkSwapWithZeroswzpasspasspasspasspass
236swap_networkSwapWithZeroswz_smallpasspasspasspasspass
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from dev_tools.qualtran_dev_tools.bloq_report_card import get_bloq_report_card, show_bloq_report_card, record_for_bloq_example, check_bloq_example_serialize, get_bloq_examples\n", - "\n", - "df = get_bloq_report_card()\n", - "show_bloq_report_card(df)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "347e5df5-b571-47f2-b3a0-90b5978b7fe3", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3094c89a-8b0f-4cfb-a86d-69f4a825880f", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/dev_tools/qualtran_dev_tools/bloq_report_card.py b/dev_tools/qualtran_dev_tools/bloq_report_card.py index 9279daa0f..47fb93551 100644 --- a/dev_tools/qualtran_dev_tools/bloq_report_card.py +++ b/dev_tools/qualtran_dev_tools/bloq_report_card.py @@ -116,7 +116,11 @@ def get_bloq_report_card( records = [] missing_bclasses = bloq_classes_with_no_examples(bclasses, bexamples) records.extend(record_for_class_with_no_examples(k) for k in missing_bclasses) - records.extend(record_for_bloq_example(be) for be in bexamples if be.name !="qubitization_qpe_hubbard_model_large") + records.extend( + record_for_bloq_example(be) + for be in bexamples + if be.name != "qubitization_qpe_hubbard_model_large" + ) df = pd.DataFrame(records) df['package'] = df['package'].str.removeprefix(package_prefix) diff --git a/qualtran/_infra/bloq.py b/qualtran/_infra/bloq.py index fc624ac9f..351eeb32a 100644 --- a/qualtran/_infra/bloq.py +++ b/qualtran/_infra/bloq.py @@ -101,7 +101,8 @@ def signature(self) -> 'Signature': `Bloq`. You can optionally implement additional methods to encode more information about this bloq. """ - def namespace(self)->str: + + def namespace(self) -> str: return self.__module__ def pretty_name(self) -> str: diff --git a/qualtran/bloqs/chemistry/trotter/hubbard/hopping.py b/qualtran/bloqs/chemistry/trotter/hubbard/hopping.py index bf7778c52..98ed7975f 100644 --- a/qualtran/bloqs/chemistry/trotter/hubbard/hopping.py +++ b/qualtran/bloqs/chemistry/trotter/hubbard/hopping.py @@ -129,9 +129,7 @@ def signature(self) -> Signature: def build_call_graph(self, ssa: 'SympySymbolAllocator') -> Set['BloqCountT']: # Page 5, text after Eq. 22. There are L^2 / 4 plaquettes of a given colour and x2 for spin. - return { - (HoppingPlaquette(kappa=self.tau * self.angle, eps=self.eps), self.length**2 // 2) - } + return {(HoppingPlaquette(kappa=self.tau * self.angle, eps=self.eps), self.length**2 // 2)} @bloq_example diff --git a/qualtran/bloqs/factoring/mod_mul.py b/qualtran/bloqs/factoring/mod_mul.py index 6efdb513d..b40feda89 100644 --- a/qualtran/bloqs/factoring/mod_mul.py +++ b/qualtran/bloqs/factoring/mod_mul.py @@ -70,8 +70,9 @@ def __attrs_post_init__(self): def signature(self) -> 'Signature': return Signature.build(ctrl=1, x=self.bitsize) - def namespace(self) ->str: - return "qualtran."+self.__module__ + def namespace(self) -> str: + return "qualtran." + self.__module__ + def _Add(self, k: Union[int, sympy.Expr]): """Helper method to forward attributes to `CtrlScaleModAdd`.""" return CtrlScaleModAdd(k=k, bitsize=self.bitsize, mod=self.mod) diff --git a/qualtran/protos/sympy_pb2.py b/qualtran/protos/sympy_pb2.py index 11e4216a5..9abbd2801 100644 --- a/qualtran/protos/sympy_pb2.py +++ b/qualtran/protos/sympy_pb2.py @@ -14,7 +14,7 @@ -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1bqualtran/protos/sympy.proto\x12\x08qualtran\"\\\n\x08\x46raction\x12&\n\tnumerator\x18\x01 \x01(\x0b\x32\x13.qualtran.Parameter\x12(\n\x0b\x64\x65nominator\x18\x02 \x01(\x0b\x32\x13.qualtran.Parameter\"\xae\x01\n\tParameter\x12\x13\n\tconst_int\x18\x01 \x01(\x05H\x00\x12\x10\n\x06symbol\x18\x02 \x01(\tH\x00\x12\'\n\tconst_rat\x18\x04 \x01(\x0b\x32\x12.qualtran.FractionH\x00\x12\x15\n\x0b\x63onst_float\x18\x05 \x01(\x02H\x00\x12-\n\x0c\x63onst_symbol\x18\x06 \x01(\x0e\x32\x15.qualtran.ConstSymbolH\x00\x42\x0b\n\tparameter\"^\n\x07Operand\x12\x1e\n\x04term\x18\x01 \x01(\x0b\x32\x0e.qualtran.TermH\x00\x12(\n\tparameter\x18\x02 \x01(\x0b\x32\x13.qualtran.ParameterH\x00\x42\t\n\x07operand\"Q\n\x04Term\x12$\n\x08\x66unction\x18\x01 \x01(\x0e\x32\x12.qualtran.Function\x12#\n\x08operands\x18\x02 \x03(\x0b\x32\x11.qualtran.Operand*\x86\x01\n\x08\x46unction\x12\x08\n\x04NONE\x10\x00\x12\x07\n\x03\x41\x64\x64\x10\x01\x12\x07\n\x03Mul\x10\x02\x12\x07\n\x03Pow\x10\x03\x12\x07\n\x03Mod\x10\x04\x12\x07\n\x03Log\x10\x05\x12\t\n\x05\x46loor\x10\x06\x12\x0b\n\x07\x43\x65iling\x10\x07\x12\x07\n\x03Max\x10\x08\x12\x07\n\x03Min\x10\t\x12\x07\n\x03Sin\x10\n\x12\x07\n\x03\x43os\x10\x0b\x12\x07\n\x03Tan\x10\x0c*M\n\x0b\x43onstSymbol\x12\x06\n\x02Pi\x10\x00\x12\x05\n\x01\x45\x10\x01\x12\x0e\n\nEulerGamma\x10\x02\x12\x0c\n\x08Infinity\x10\x03\x12\x11\n\rImaginaryUnit\x10\x04\x62\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1bqualtran/protos/sympy.proto\x12\x08qualtran\"\\\n\x08\x46raction\x12&\n\tnumerator\x18\x01 \x01(\x0b\x32\x13.qualtran.Parameter\x12(\n\x0b\x64\x65nominator\x18\x02 \x01(\x0b\x32\x13.qualtran.Parameter\"\xae\x01\n\tParameter\x12\x13\n\tconst_int\x18\x01 \x01(\x05H\x00\x12\x10\n\x06symbol\x18\x02 \x01(\tH\x00\x12\'\n\tconst_rat\x18\x03 \x01(\x0b\x32\x12.qualtran.FractionH\x00\x12\x15\n\x0b\x63onst_float\x18\x04 \x01(\x02H\x00\x12-\n\x0c\x63onst_symbol\x18\x05 \x01(\x0e\x32\x15.qualtran.ConstSymbolH\x00\x42\x0b\n\tparameter\"^\n\x07Operand\x12\x1e\n\x04term\x18\x01 \x01(\x0b\x32\x0e.qualtran.TermH\x00\x12(\n\tparameter\x18\x02 \x01(\x0b\x32\x13.qualtran.ParameterH\x00\x42\t\n\x07operand\"Q\n\x04Term\x12$\n\x08\x66unction\x18\x01 \x01(\x0e\x32\x12.qualtran.Function\x12#\n\x08operands\x18\x02 \x03(\x0b\x32\x11.qualtran.Operand*\x86\x01\n\x08\x46unction\x12\x08\n\x04NONE\x10\x00\x12\x07\n\x03\x41\x64\x64\x10\x01\x12\x07\n\x03Mul\x10\x02\x12\x07\n\x03Pow\x10\x03\x12\x07\n\x03Mod\x10\x04\x12\x07\n\x03Log\x10\x05\x12\t\n\x05\x46loor\x10\x06\x12\x0b\n\x07\x43\x65iling\x10\x07\x12\x07\n\x03Max\x10\x08\x12\x07\n\x03Min\x10\t\x12\x07\n\x03Sin\x10\n\x12\x07\n\x03\x43os\x10\x0b\x12\x07\n\x03Tan\x10\x0c*M\n\x0b\x43onstSymbol\x12\x06\n\x02Pi\x10\x00\x12\x05\n\x01\x45\x10\x01\x12\x0e\n\nEulerGamma\x10\x02\x12\x0c\n\x08Infinity\x10\x03\x12\x11\n\rImaginaryUnit\x10\x04\x62\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) diff --git a/qualtran/protos/sympy_pb2.pyi b/qualtran/protos/sympy_pb2.pyi index eb907a614..aab4e4fc3 100644 --- a/qualtran/protos/sympy_pb2.pyi +++ b/qualtran/protos/sympy_pb2.pyi @@ -128,8 +128,7 @@ class Parameter(google.protobuf.message.Message): const_int: builtins.int symbol: builtins.str @property - def const_rat(self) -> global___Fraction: - """string const_irrat = 3; ConstSymbol replaces the need for const_irrat""" + def const_rat(self) -> global___Fraction: ... const_float: builtins.float const_symbol: global___ConstSymbol.ValueType def __init__( diff --git a/qualtran/scratch.py b/qualtran/scratch.py deleted file mode 100644 index 7337719ee..000000000 --- a/qualtran/scratch.py +++ /dev/null @@ -1,53 +0,0 @@ -from bloqs.factoring.mod_mul import CtrlModMul -from qualtran.serialization.bloq import bloqs_from_proto, bloqs_to_proto -import sympy - -# k, N, n_x = sympy.symbols('k N n_x') -# bloq = CtrlModMul(k=k, mod=N, bitsize=n_x) -# -# serialized = bloqs_to_proto(bloq) -# reconstructed = bloqs_from_proto(serialized) -# print("Done") -# # - -# Put this into dev_tools -from dev_tools.qualtran_dev_tools.bloq_report_card import get_bloq_report_card, show_bloq_report_card, record_for_bloq_example, check_bloq_example_serialize, get_bloq_examples -from qualtran.serialization.bloq import bloqs_from_proto, bloqs_to_proto - - -wanted = [ - # "add_diff_size_regs", - # "add_large", - "add_small", - "add_oop_large", - "add_oop_small", - "int_effect", - "int_state", - "df_one_body", - "prepare_t", - "prep_nu_proj", - "prep_sparse", - "sel_sparse", - "thc_prep", - "qrom_multi_data", - "qrom_multi_dim", - "qrom_small", - "lprs_interim_prep", - "lp_resource_state_small", - "qubitization_qpe_hubbard_model_small", - "textbook_qpe_small", - "approximate_qft_from_epsilon", - "approximate_qft_small", - "two_bit_ffft", - "reflection", - "qvr_zpow" -] -bexamples = get_bloq_examples() -my_examples = [example for example in bexamples if example.name in wanted] -for example in my_examples: - print(example.name, check_bloq_example_serialize(example)) - - - bloq_lib = bloqs_to_proto(example) - bloq_roundtrip = bloqs_from_proto(bloq_lib)[0] -print("Done") \ No newline at end of file diff --git a/qualtran/serialization/bloq.py b/qualtran/serialization/bloq.py index 83533833e..62d2c8171 100644 --- a/qualtran/serialization/bloq.py +++ b/qualtran/serialization/bloq.py @@ -46,9 +46,9 @@ registers, resolver_dict, ) - from qualtran.serialization.sympy import sympy_expr_from_proto, sympy_expr_to_proto + def arg_to_proto(*, name: str, val: Any) -> bloq_pb2.BloqArg: if isinstance(val, int): return bloq_pb2.BloqArg(name=name, int_val=val) diff --git a/qualtran/serialization/sympy.py b/qualtran/serialization/sympy.py index a10bd4682..01387209a 100644 --- a/qualtran/serialization/sympy.py +++ b/qualtran/serialization/sympy.py @@ -12,9 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +from typing import Any, Union + import sympy + from qualtran.protos import sympy_pb2 -from typing import Union, Any + + def _get_sympy_function_type(expr: sympy.Expr) -> int: """ Helper function for serializing a sympy function. @@ -48,7 +52,8 @@ def _get_sympy_function_type(expr: sympy.Expr) -> int: else: return sympy_pb2.Function.NONE -def _get_sympy_function_from_enum(enum: int)->Any: + +def _get_sympy_function_from_enum(enum: int) -> Any: """ Helper function for sympy function deserialization. @@ -73,7 +78,8 @@ def _get_sympy_function_from_enum(enum: int)->Any: return enum_to_sympy[enum] -def _get_sympy_const_from_enum(enum: int)->Any: + +def _get_sympy_const_from_enum(enum: int) -> Any: """Helper function for deserializing a sympy symbolic constant. Symbolic constants are serialzed as an enum of type sympy_pb2.ConstSymbol. This method converts the @@ -84,11 +90,12 @@ def _get_sympy_const_from_enum(enum: int)->Any: sympy_pb2.ConstSymbol.E: sympy.E, sympy_pb2.ConstSymbol.EulerGamma: sympy.EulerGamma, sympy_pb2.ConstSymbol.Infinity: sympy.core.numbers.Infinity(), - sympy_pb2.ConstSymbol.ImaginaryUnit: sympy.core.numbers.ImaginaryUnit() + sympy_pb2.ConstSymbol.ImaginaryUnit: sympy.core.numbers.ImaginaryUnit(), } return enum_to_sympy[enum] -def _get_const_symbolic_operand(expr: sympy.Expr)->sympy_pb2.Parameter: + +def _get_const_symbolic_operand(expr: sympy.Expr) -> sympy_pb2.Parameter: """ Helper function for serializing a symbolic constant from a sympy expression. @@ -100,14 +107,15 @@ def _get_const_symbolic_operand(expr: sympy.Expr)->sympy_pb2.Parameter: return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.E) if expr == sympy.EulerGamma: return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.EulerGamma) - if isinstance(expr,sympy.core.numbers.Infinity): + if isinstance(expr, sympy.core.numbers.Infinity): return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.Infinity) if isinstance(expr, sympy.core.numbers.ImaginaryUnit): return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.ImaginaryUnit) else: raise NotImplementedError(f"Sympy expression {str(expr)} cannot be serialized.") -def _get_sympy_operand(expr: Union[sympy.Expr, int, float])->sympy_pb2.Parameter: + +def _get_sympy_operand(expr: Union[sympy.Expr, int, float]) -> sympy_pb2.Parameter: """ Converts the input to a serializable sympy_pb2 Parameter. @@ -143,7 +151,8 @@ def _get_sympy_operand(expr: Union[sympy.Expr, int, float])->sympy_pb2.Parameter else: return _get_const_symbolic_operand(expr) -def sympy_expr_to_proto(expr: sympy.Expr)-> sympy_pb2.Term: + +def sympy_expr_to_proto(expr: sympy.Expr) -> sympy_pb2.Term: """Serializes a sympy expression.""" function = _get_sympy_function_type(expr) @@ -160,7 +169,8 @@ def sympy_expr_to_proto(expr: sympy.Expr)-> sympy_pb2.Term: return sympy_pb2.Term(function=function, operands=operands) -def _get_parameter(serialized_input: Union[sympy_pb2.Operand, sympy_pb2.Parameter])->Any: + +def _get_parameter(serialized_input: Union[sympy_pb2.Operand, sympy_pb2.Parameter]) -> Any: """ Deserializes a parameter. @@ -192,7 +202,7 @@ def _get_parameter(serialized_input: Union[sympy_pb2.Operand, sympy_pb2.Paramete return deserialized_parameter -def sympy_expr_from_proto(term: sympy_pb2.Term)->Any: +def sympy_expr_from_proto(term: sympy_pb2.Term) -> Any: """Deserialize a sympy expression.""" function = _get_sympy_function_from_enum(term.function) @@ -209,4 +219,4 @@ def sympy_expr_from_proto(term: sympy_pb2.Term)->Any: elif len(parameters) == 1: return parameters[0] else: - raise NotImplementedError(f"{term.function} has not been fully implimented.") \ No newline at end of file + raise NotImplementedError(f"{term.function} has not been fully implimented.") diff --git a/qualtran/serialization/sympy_test.py b/qualtran/serialization/sympy_test.py index e13a73f7e..30db6c0c2 100644 --- a/qualtran/serialization/sympy_test.py +++ b/qualtran/serialization/sympy_test.py @@ -12,15 +12,23 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sympy import pytest -from qualtran.serialization.bloq import arg_to_proto, arg_from_proto +import sympy + +from qualtran.serialization.bloq import arg_from_proto, arg_to_proto + @pytest.mark.parametrize( 'expr', [ - (sympy.parse_expr("5")+sympy.symbols("x")+sympy.parse_expr("1/2")+sympy.pi+sympy.parse_expr("2j")), - (sympy.parse_expr("(-b + sqrt(-4*a*c + b**2))/(2*a)")) + ( + sympy.parse_expr("5") + + sympy.symbols("x") + + sympy.parse_expr("1/2") + + sympy.pi + + sympy.parse_expr("2j") + ), + (sympy.parse_expr("(-b + sqrt(-4*a*c + b**2))/(2*a)")), ], ) def parameter_test(expr: sympy.Expr): @@ -32,15 +40,15 @@ def parameter_test(expr: sympy.Expr): expr_clone = arg_from_proto(serialized)['test'] assert expr == expr_clone + def float_fraction_test(): """ Test that floats and fractions can be properly combined and serialzed. """ - float = sympy.parse_expr("1.4") + float_const = sympy.parse_expr("1.4") fraction = sympy.parse_expr("1/2") - expr = float*fraction + expr = float_const * fraction serialized = arg_to_proto(name="test", val=expr) expr_clone = arg_from_proto(serialized)['test'] - assert abs(expr - expr_clone) < .001 - + assert abs(expr - expr_clone) < 0.001 From 98784d1d4e1e0fe330588c1533cd7133cfb6f2d0 Mon Sep 17 00:00:00 2001 From: local_linix Date: Mon, 15 Apr 2024 17:58:30 -0700 Subject: [PATCH 29/34] Cleanup forgotten test code. --- dev_tools/qualtran_dev_tools/bloq_report_card.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/dev_tools/qualtran_dev_tools/bloq_report_card.py b/dev_tools/qualtran_dev_tools/bloq_report_card.py index 47fb93551..4af1d66d5 100644 --- a/dev_tools/qualtran_dev_tools/bloq_report_card.py +++ b/dev_tools/qualtran_dev_tools/bloq_report_card.py @@ -84,8 +84,6 @@ def record_for_class_with_no_examples(k: Type[Bloq]) -> Dict[str, Any]: def record_for_bloq_example(be: BloqExample) -> Dict[str, Any]: - # DO NOT SUBMIT: Remove print - print(be.name) return { 'bloq_cls': be.bloq_cls.__name__, 'package': _get_package(be.bloq_cls), @@ -116,11 +114,7 @@ def get_bloq_report_card( records = [] missing_bclasses = bloq_classes_with_no_examples(bclasses, bexamples) records.extend(record_for_class_with_no_examples(k) for k in missing_bclasses) - records.extend( - record_for_bloq_example(be) - for be in bexamples - if be.name != "qubitization_qpe_hubbard_model_large" - ) + records.extend(record_for_bloq_example(be) for be in bexamples) df = pd.DataFrame(records) df['package'] = df['package'].str.removeprefix(package_prefix) From af1d32c6937c1ce85482ca9bd65e0e58dedc43cb Mon Sep 17 00:00:00 2001 From: local_linix Date: Tue, 16 Apr 2024 01:46:49 -0700 Subject: [PATCH 30/34] Add tests, fix naming conventions, and add proper return types. --- qualtran/_infra/bloq.py | 3 -- qualtran/bloqs/factoring/mod_mul.py | 3 -- qualtran/protos/sympy.proto | 6 ++- qualtran/protos/sympy_pb2.py | 6 +-- qualtran/protos/sympy_pb2.pyi | 14 +++++-- qualtran/serialization/bloq.py | 2 +- qualtran/serialization/sympy.py | 62 +++++++++++++++++----------- qualtran/serialization/sympy_test.py | 50 ++++++++++++++++------ 8 files changed, 92 insertions(+), 54 deletions(-) diff --git a/qualtran/_infra/bloq.py b/qualtran/_infra/bloq.py index 351eeb32a..c51c62060 100644 --- a/qualtran/_infra/bloq.py +++ b/qualtran/_infra/bloq.py @@ -102,9 +102,6 @@ def signature(self) -> 'Signature': about this bloq. """ - def namespace(self) -> str: - return self.__module__ - def pretty_name(self) -> str: return self.__class__.__name__ diff --git a/qualtran/bloqs/factoring/mod_mul.py b/qualtran/bloqs/factoring/mod_mul.py index b40feda89..8091c2e5b 100644 --- a/qualtran/bloqs/factoring/mod_mul.py +++ b/qualtran/bloqs/factoring/mod_mul.py @@ -70,9 +70,6 @@ def __attrs_post_init__(self): def signature(self) -> 'Signature': return Signature.build(ctrl=1, x=self.bitsize) - def namespace(self) -> str: - return "qualtran." + self.__module__ - def _Add(self, k: Union[int, sympy.Expr]): """Helper method to forward attributes to `CtrlScaleModAdd`.""" return CtrlScaleModAdd(k=k, bitsize=self.bitsize, mod=self.mod) diff --git a/qualtran/protos/sympy.proto b/qualtran/protos/sympy.proto index d40209ad4..108de5fc2 100644 --- a/qualtran/protos/sympy.proto +++ b/qualtran/protos/sympy.proto @@ -19,6 +19,8 @@ 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; Add = 1; Mul = 2; @@ -35,7 +37,7 @@ enum Function { } // Represents a constant, rational number. -message Fraction { +message Rational { Parameter numerator = 1; Parameter denominator = 2; } @@ -53,7 +55,7 @@ message Parameter { oneof parameter { int32 const_int = 1; string symbol = 2; - Fraction const_rat = 3; + Rational const_rat = 3; float const_float = 4; ConstSymbol const_symbol = 5; diff --git a/qualtran/protos/sympy_pb2.py b/qualtran/protos/sympy_pb2.py index 9abbd2801..d090f4f74 100644 --- a/qualtran/protos/sympy_pb2.py +++ b/qualtran/protos/sympy_pb2.py @@ -14,7 +14,7 @@ -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1bqualtran/protos/sympy.proto\x12\x08qualtran\"\\\n\x08\x46raction\x12&\n\tnumerator\x18\x01 \x01(\x0b\x32\x13.qualtran.Parameter\x12(\n\x0b\x64\x65nominator\x18\x02 \x01(\x0b\x32\x13.qualtran.Parameter\"\xae\x01\n\tParameter\x12\x13\n\tconst_int\x18\x01 \x01(\x05H\x00\x12\x10\n\x06symbol\x18\x02 \x01(\tH\x00\x12\'\n\tconst_rat\x18\x03 \x01(\x0b\x32\x12.qualtran.FractionH\x00\x12\x15\n\x0b\x63onst_float\x18\x04 \x01(\x02H\x00\x12-\n\x0c\x63onst_symbol\x18\x05 \x01(\x0e\x32\x15.qualtran.ConstSymbolH\x00\x42\x0b\n\tparameter\"^\n\x07Operand\x12\x1e\n\x04term\x18\x01 \x01(\x0b\x32\x0e.qualtran.TermH\x00\x12(\n\tparameter\x18\x02 \x01(\x0b\x32\x13.qualtran.ParameterH\x00\x42\t\n\x07operand\"Q\n\x04Term\x12$\n\x08\x66unction\x18\x01 \x01(\x0e\x32\x12.qualtran.Function\x12#\n\x08operands\x18\x02 \x03(\x0b\x32\x11.qualtran.Operand*\x86\x01\n\x08\x46unction\x12\x08\n\x04NONE\x10\x00\x12\x07\n\x03\x41\x64\x64\x10\x01\x12\x07\n\x03Mul\x10\x02\x12\x07\n\x03Pow\x10\x03\x12\x07\n\x03Mod\x10\x04\x12\x07\n\x03Log\x10\x05\x12\t\n\x05\x46loor\x10\x06\x12\x0b\n\x07\x43\x65iling\x10\x07\x12\x07\n\x03Max\x10\x08\x12\x07\n\x03Min\x10\t\x12\x07\n\x03Sin\x10\n\x12\x07\n\x03\x43os\x10\x0b\x12\x07\n\x03Tan\x10\x0c*M\n\x0b\x43onstSymbol\x12\x06\n\x02Pi\x10\x00\x12\x05\n\x01\x45\x10\x01\x12\x0e\n\nEulerGamma\x10\x02\x12\x0c\n\x08Infinity\x10\x03\x12\x11\n\rImaginaryUnit\x10\x04\x62\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1bqualtran/protos/sympy.proto\x12\x08qualtran\"\\\n\x08Rational\x12&\n\tnumerator\x18\x01 \x01(\x0b\x32\x13.qualtran.Parameter\x12(\n\x0b\x64\x65nominator\x18\x02 \x01(\x0b\x32\x13.qualtran.Parameter\"\xae\x01\n\tParameter\x12\x13\n\tconst_int\x18\x01 \x01(\x05H\x00\x12\x10\n\x06symbol\x18\x02 \x01(\tH\x00\x12\'\n\tconst_rat\x18\x03 \x01(\x0b\x32\x12.qualtran.RationalH\x00\x12\x15\n\x0b\x63onst_float\x18\x04 \x01(\x02H\x00\x12-\n\x0c\x63onst_symbol\x18\x05 \x01(\x0e\x32\x15.qualtran.ConstSymbolH\x00\x42\x0b\n\tparameter\"^\n\x07Operand\x12\x1e\n\x04term\x18\x01 \x01(\x0b\x32\x0e.qualtran.TermH\x00\x12(\n\tparameter\x18\x02 \x01(\x0b\x32\x13.qualtran.ParameterH\x00\x42\t\n\x07operand\"Q\n\x04Term\x12$\n\x08\x66unction\x18\x01 \x01(\x0e\x32\x12.qualtran.Function\x12#\n\x08operands\x18\x02 \x03(\x0b\x32\x11.qualtran.Operand*\x86\x01\n\x08\x46unction\x12\x08\n\x04NONE\x10\x00\x12\x07\n\x03\x41\x64\x64\x10\x01\x12\x07\n\x03Mul\x10\x02\x12\x07\n\x03Pow\x10\x03\x12\x07\n\x03Mod\x10\x04\x12\x07\n\x03Log\x10\x05\x12\t\n\x05\x46loor\x10\x06\x12\x0b\n\x07\x43\x65iling\x10\x07\x12\x07\n\x03Max\x10\x08\x12\x07\n\x03Min\x10\t\x12\x07\n\x03Sin\x10\n\x12\x07\n\x03\x43os\x10\x0b\x12\x07\n\x03Tan\x10\x0c*M\n\x0b\x43onstSymbol\x12\x06\n\x02Pi\x10\x00\x12\x05\n\x01\x45\x10\x01\x12\x0e\n\nEulerGamma\x10\x02\x12\x0c\n\x08Infinity\x10\x03\x12\x11\n\rImaginaryUnit\x10\x04\x62\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) @@ -25,8 +25,8 @@ _globals['_FUNCTION']._serialized_end=626 _globals['_CONSTSYMBOL']._serialized_start=628 _globals['_CONSTSYMBOL']._serialized_end=705 - _globals['_FRACTION']._serialized_start=41 - _globals['_FRACTION']._serialized_end=133 + _globals['_RATIONAL']._serialized_start=41 + _globals['_RATIONAL']._serialized_end=133 _globals['_PARAMETER']._serialized_start=136 _globals['_PARAMETER']._serialized_end=310 _globals['_OPERAND']._serialized_start=312 diff --git a/qualtran/protos/sympy_pb2.pyi b/qualtran/protos/sympy_pb2.pyi index aab4e4fc3..79aea4d17 100644 --- a/qualtran/protos/sympy_pb2.pyi +++ b/qualtran/protos/sympy_pb2.pyi @@ -39,6 +39,9 @@ class _Function: class _FunctionEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[_Function.ValueType], builtins.type): DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor NONE: _Function.ValueType # 0 + """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. + """ Add: _Function.ValueType # 1 Mul: _Function.ValueType # 2 Pow: _Function.ValueType # 3 @@ -56,6 +59,9 @@ class Function(_Function, metaclass=_FunctionEnumTypeWrapper): """A function sympy expression.""" NONE: Function.ValueType # 0 +"""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. +""" Add: Function.ValueType # 1 Mul: Function.ValueType # 2 Pow: Function.ValueType # 3 @@ -92,7 +98,7 @@ ImaginaryUnit: ConstSymbol.ValueType # 4 global___ConstSymbol = ConstSymbol @typing_extensions.final -class Fraction(google.protobuf.message.Message): +class Rational(google.protobuf.message.Message): """Represents a constant, rational number.""" DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -112,7 +118,7 @@ class Fraction(google.protobuf.message.Message): def HasField(self, field_name: typing_extensions.Literal["denominator", b"denominator", "numerator", b"numerator"]) -> builtins.bool: ... def ClearField(self, field_name: typing_extensions.Literal["denominator", b"denominator", "numerator", b"numerator"]) -> None: ... -global___Fraction = Fraction +global___Rational = Rational @typing_extensions.final class Parameter(google.protobuf.message.Message): @@ -128,7 +134,7 @@ class Parameter(google.protobuf.message.Message): const_int: builtins.int symbol: builtins.str @property - def const_rat(self) -> global___Fraction: ... + def const_rat(self) -> global___Rational: ... const_float: builtins.float const_symbol: global___ConstSymbol.ValueType def __init__( @@ -136,7 +142,7 @@ class Parameter(google.protobuf.message.Message): *, const_int: builtins.int = ..., symbol: builtins.str = ..., - const_rat: global___Fraction | None = ..., + const_rat: global___Rational | None = ..., const_float: builtins.float = ..., const_symbol: global___ConstSymbol.ValueType = ..., ) -> None: ... diff --git a/qualtran/serialization/bloq.py b/qualtran/serialization/bloq.py index 62d2c8171..c2d4dd3da 100644 --- a/qualtran/serialization/bloq.py +++ b/qualtran/serialization/bloq.py @@ -319,7 +319,7 @@ def _bloq_to_proto(bloq: Bloq, *, bloq_to_idx: Dict[Bloq, int]) -> bloq_pb2.Bloq except (DecomposeTypeError, DecomposeNotImplementedError, TypeError): t_complexity = None - name = bloq.namespace() + "." + bloq.__class__.__qualname__ + name = bloq.__module__ + "." + bloq.__class__.__qualname__ return bloq_pb2.Bloq( name=name, registers=registers.registers_to_proto(bloq.signature), diff --git a/qualtran/serialization/sympy.py b/qualtran/serialization/sympy.py index 01387209a..303974f68 100644 --- a/qualtran/serialization/sympy.py +++ b/qualtran/serialization/sympy.py @@ -57,8 +57,8 @@ def _get_sympy_function_from_enum(enum: int) -> Any: """ Helper function for sympy function deserialization. - Sympy functions are represented as a sympy_pb2.Function enum. This mehtod converts this int enum - back into the sympy function. + Sympy functions are represented as a sympy_pb2.Function enum. This method converts + this int enum. """ enum_to_sympy = { sympy_pb2.Function.Mul: sympy.core.mul.Mul, @@ -111,8 +111,7 @@ def _get_const_symbolic_operand(expr: sympy.Expr) -> sympy_pb2.Parameter: return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.Infinity) if isinstance(expr, sympy.core.numbers.ImaginaryUnit): return sympy_pb2.Parameter(const_symbol=sympy_pb2.ConstSymbol.ImaginaryUnit) - else: - raise NotImplementedError(f"Sympy expression {str(expr)} cannot be serialized.") + raise NotImplementedError(f"Sympy expression {str(expr)} cannot be serialized.") def _get_sympy_operand(expr: Union[sympy.Expr, int, float]) -> sympy_pb2.Parameter: @@ -140,13 +139,13 @@ def _get_sympy_operand(expr: Union[sympy.Expr, int, float]) -> sympy_pb2.Paramet if isinstance(expr, sympy.core.numbers.Rational): numerator = _get_sympy_operand(expr.numerator) denominator = _get_sympy_operand(expr.denominator) - fraction = sympy_pb2.Fraction(numerator=numerator, denominator=denominator) + fraction = sympy_pb2.Rational(numerator=numerator, denominator=denominator) return sympy_pb2.Parameter(const_rat=fraction) else: raise NotImplementedError(f"Sympy expression {str(expr)} cannot be serialized.") - if type(expr) == int: + if type(expr) is int: return sympy_pb2.Parameter(const_int=expr) - if type(expr) == float: + if type(expr) is float: return sympy_pb2.Parameter(const_float=expr) else: return _get_const_symbolic_operand(expr) @@ -170,7 +169,9 @@ def sympy_expr_to_proto(expr: sympy.Expr) -> sympy_pb2.Term: return sympy_pb2.Term(function=function, operands=operands) -def _get_parameter(serialized_input: Union[sympy_pb2.Operand, sympy_pb2.Parameter]) -> Any: +def _get_parameter( + serialized_input: Union[sympy_pb2.Operand, sympy_pb2.Parameter] +) -> Union[sympy.core.AtomicExpr, int, float]: """ Deserializes a parameter. @@ -184,27 +185,36 @@ def _get_parameter(serialized_input: Union[sympy_pb2.Operand, sympy_pb2.Paramete parameter_type = serialized_parameter.WhichOneof("parameter") if parameter_type == "symbol": - deserialized_parameter = sympy.symbols(serialized_parameter.symbol) - elif parameter_type == "const_int": - deserialized_parameter = serialized_parameter.const_int - elif parameter_type == "const_rat": + return sympy.symbols(serialized_parameter.symbol) + if parameter_type == "const_int": + return serialized_parameter.const_int + if parameter_type == "const_rat": fraction = serialized_parameter.const_rat numerator = _get_parameter(fraction.numerator) denominator = _get_parameter(fraction.denominator) - deserialized_parameter = sympy.Rational(numerator, denominator) - elif parameter_type == "const_float": - deserialized_parameter = serialized_parameter.const_float - elif parameter_type == "const_symbol": - deserialized_parameter = _get_sympy_const_from_enum(serialized_parameter.const_symbol) - else: - raise TypeError(f"Type is not supported for {serialized_input}") + return sympy.Rational(numerator, denominator) + if parameter_type == "const_float": + return serialized_parameter.const_float + if parameter_type == "const_symbol": + return _get_sympy_const_from_enum(serialized_parameter.const_symbol) - return deserialized_parameter + raise TypeError(f"Type is not supported for {serialized_input}") -def sympy_expr_from_proto(term: sympy_pb2.Term) -> Any: - """Deserialize a sympy expression.""" +def sympy_expr_from_proto( + term: sympy_pb2.Term, +) -> Union[sympy.core.AtomicExpr, sympy_pb2.Term, int, float]: + """Deserialize a sympy expression. + This will take a sympy_pb2.Term which will contain a function and + one or more operands. These operands can also be Terms which will cause + this method to be called recursively. + + An error will be raised if a Term contains a function that is not listed in + the sympy_pb2.Function enum in sympy.proto. Additionally, an error will be + raised if an operand cannot be converted into one of the following: a + sympy symbol, a sympy constant, a nested Term, or a native python numeric type. + """ function = _get_sympy_function_from_enum(term.function) parameters = [] for operand in term.operands: @@ -216,7 +226,9 @@ def sympy_expr_from_proto(term: sympy_pb2.Term) -> Any: if function: return function(*parameters) - elif len(parameters) == 1: + + # If a term has no function, then it must be a single parameter. + if len(parameters) == 1: return parameters[0] - else: - raise NotImplementedError(f"{term.function} has not been fully implimented.") + + raise NotImplementedError(f"{term.function} has not been fully implimented.") diff --git a/qualtran/serialization/sympy_test.py b/qualtran/serialization/sympy_test.py index 30db6c0c2..a1fce03a4 100644 --- a/qualtran/serialization/sympy_test.py +++ b/qualtran/serialization/sympy_test.py @@ -17,20 +17,44 @@ from qualtran.serialization.bloq import arg_from_proto, arg_to_proto +x = sympy.Symbol('x', positive=True) +a, b, c = sympy.symbols("a b c") -@pytest.mark.parametrize( - 'expr', - [ - ( - sympy.parse_expr("5") - + sympy.symbols("x") - + sympy.parse_expr("1/2") - + sympy.pi - + sympy.parse_expr("2j") - ), - (sympy.parse_expr("(-b + sqrt(-4*a*c + b**2))/(2*a)")), - ], -) +# These should return a `sympy_pb2.Parameter` proto object? +sympy_parameters_to_test = [ + # Only symbols + sympy.Symbol('x'), + sympy.Symbol('N'), + sympy.Symbol('E'), + # Sympy constants + sympy.pi, + sympy.oo, # infinity + sympy.E, + sympy.I, + sympy.EulerGamma, + # Integers, Floats, Rationals + sympy.Integer(5), + sympy.Float(0.1), + sympy.Rational("1/2"), + sympy.Rational('1/10'), +] +sympy_exprs_to_test = [ + 5 * x + sympy.sqrt(a), + # Complex Fractions + sympy.Rational("1/10") * sympy.I + 5, + # Basic operations + a / b + c - 5, + # Trig operations + sympy.sin(a) + sympy.cos(b) + sympy.tan(c), + # Integer operations + sympy.floor(5.43) + sympy.ceiling(a), + sympy.Max(a, b), + # Nested Operations + a ** (b * c**2), +] + + +@pytest.mark.parametrize('expr', sympy_parameters_to_test + sympy_exprs_to_test) def parameter_test(expr: sympy.Expr): """ Test types of expressions including fraction, complex, and constant symbol (such as pi). From deb30165f4a2b4a15242a3be2f19e63dfb57d409 Mon Sep 17 00:00:00 2001 From: Epsilon1024 <50683403+Epsilon1024@users.noreply.github.com> Date: Wed, 17 Apr 2024 16:06:51 -0700 Subject: [PATCH 31/34] Update sympy_test.py Call sympy serialization directly rather than calling it through bloq. --- qualtran/serialization/sympy_test.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/qualtran/serialization/sympy_test.py b/qualtran/serialization/sympy_test.py index a1fce03a4..b41dc5c6e 100644 --- a/qualtran/serialization/sympy_test.py +++ b/qualtran/serialization/sympy_test.py @@ -15,7 +15,7 @@ import pytest import sympy -from qualtran.serialization.bloq import arg_from_proto, arg_to_proto +from qualtran.serialization.sympy import sympy_expr_to_proto, sympy_expr_from_proto x = sympy.Symbol('x', positive=True) a, b, c = sympy.symbols("a b c") @@ -60,8 +60,8 @@ def parameter_test(expr: sympy.Expr): Test types of expressions including fraction, complex, and constant symbol (such as pi). """ - serialized = arg_to_proto(name="test", val=expr) - expr_clone = arg_from_proto(serialized)['test'] + serialized = sympy_expr_to_proto(name="test", val=expr) + expr_clone = sympy_expr_from_proto(serialized)['test'] assert expr == expr_clone @@ -73,6 +73,6 @@ def float_fraction_test(): fraction = sympy.parse_expr("1/2") expr = float_const * fraction - serialized = arg_to_proto(name="test", val=expr) - expr_clone = arg_from_proto(serialized)['test'] + serialized = sympy_expr_to_proto(name="test", val=expr) + expr_clone = sympy_expr_from_proto(serialized)['test'] assert abs(expr - expr_clone) < 0.001 From c426f301ce90abeecf3265caf8b68011a099798e Mon Sep 17 00:00:00 2001 From: Epsilon1024 <50683403+Epsilon1024@users.noreply.github.com> Date: Wed, 17 Apr 2024 16:08:31 -0700 Subject: [PATCH 32/34] Apply suggestions from code review Addressed nit comments. Co-authored-by: Tanuj Khattar --- qualtran/serialization/sympy.py | 10 ++++------ qualtran/serialization/sympy_test.py | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/qualtran/serialization/sympy.py b/qualtran/serialization/sympy.py index 303974f68..40ac5072e 100644 --- a/qualtran/serialization/sympy.py +++ b/qualtran/serialization/sympy.py @@ -1,4 +1,4 @@ -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -147,8 +147,7 @@ def _get_sympy_operand(expr: Union[sympy.Expr, int, float]) -> sympy_pb2.Paramet return sympy_pb2.Parameter(const_int=expr) if type(expr) is float: return sympy_pb2.Parameter(const_float=expr) - else: - return _get_const_symbolic_operand(expr) + return _get_const_symbolic_operand(expr) def sympy_expr_to_proto(expr: sympy.Expr) -> sympy_pb2.Term: @@ -221,8 +220,7 @@ def sympy_expr_from_proto( if operand.HasField("term"): parameters.append(sympy_expr_from_proto(operand.term)) else: - parameter = _get_parameter(operand) - parameters.append(parameter) + parameters.append(_get_parameter(operand)) if function: return function(*parameters) @@ -231,4 +229,4 @@ def sympy_expr_from_proto( if len(parameters) == 1: return parameters[0] - raise NotImplementedError(f"{term.function} has not been fully implimented.") + raise NotImplementedError(f"{term.function} has not been fully implemented.") diff --git a/qualtran/serialization/sympy_test.py b/qualtran/serialization/sympy_test.py index b41dc5c6e..24da7f7fa 100644 --- a/qualtran/serialization/sympy_test.py +++ b/qualtran/serialization/sympy_test.py @@ -1,4 +1,4 @@ -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ x = sympy.Symbol('x', positive=True) a, b, c = sympy.symbols("a b c") -# These should return a `sympy_pb2.Parameter` proto object? +# These should return a `sympy_pb2.Parameter` proto object sympy_parameters_to_test = [ # Only symbols sympy.Symbol('x'), From 95ffb938fd9c9aac25f11edb9ad8bbc39f8b57a7 Mon Sep 17 00:00:00 2001 From: local_linix Date: Wed, 17 Apr 2024 16:29:44 -0700 Subject: [PATCH 33/34] Fix sympy_test --- qualtran/serialization/sympy_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qualtran/serialization/sympy_test.py b/qualtran/serialization/sympy_test.py index 24da7f7fa..a7e63f774 100644 --- a/qualtran/serialization/sympy_test.py +++ b/qualtran/serialization/sympy_test.py @@ -15,7 +15,7 @@ import pytest import sympy -from qualtran.serialization.sympy import sympy_expr_to_proto, sympy_expr_from_proto +from qualtran.serialization.sympy import sympy_expr_from_proto, sympy_expr_to_proto x = sympy.Symbol('x', positive=True) a, b, c = sympy.symbols("a b c") @@ -60,7 +60,7 @@ def parameter_test(expr: sympy.Expr): Test types of expressions including fraction, complex, and constant symbol (such as pi). """ - serialized = sympy_expr_to_proto(name="test", val=expr) + serialized = sympy_expr_to_proto(expr) expr_clone = sympy_expr_from_proto(serialized)['test'] assert expr == expr_clone @@ -73,6 +73,6 @@ def float_fraction_test(): fraction = sympy.parse_expr("1/2") expr = float_const * fraction - serialized = sympy_expr_to_proto(name="test", val=expr) + serialized = sympy_expr_to_proto(expr) expr_clone = sympy_expr_from_proto(serialized)['test'] assert abs(expr - expr_clone) < 0.001 From 8524f33c60a25b62c3e5ddf1be3836a7a7e430fc Mon Sep 17 00:00:00 2001 From: Tanuj Khattar Date: Thu, 18 Apr 2024 17:22:53 -0700 Subject: [PATCH 34/34] Fix return type of sympy_expr_from_proto --- qualtran/serialization/sympy.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/qualtran/serialization/sympy.py b/qualtran/serialization/sympy.py index 40ac5072e..d5e5b8f59 100644 --- a/qualtran/serialization/sympy.py +++ b/qualtran/serialization/sympy.py @@ -200,9 +200,7 @@ def _get_parameter( raise TypeError(f"Type is not supported for {serialized_input}") -def sympy_expr_from_proto( - term: sympy_pb2.Term, -) -> Union[sympy.core.AtomicExpr, sympy_pb2.Term, int, float]: +def sympy_expr_from_proto(term: sympy_pb2.Term) -> Union[sympy.core.AtomicExpr, int, float]: """Deserialize a sympy expression. This will take a sympy_pb2.Term which will contain a function and