Skip to content

Commit

Permalink
minor qelectron fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kessler-frost committed Sep 27, 2023
1 parent efe1db8 commit f6554e2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
4 changes: 3 additions & 1 deletion covalent/quantum/qcluster/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class AsyncBaseQCluster(AsyncBaseQExecutor):
executors: Sequence[BaseQExecutor]
selector: Union[str, Callable]

_selector_serialized: bool = False
# Flag used to indicate whether `self.selector` is currently serialized.
# This needs to be without the "_" prefix so that it gets propagated to the server.
selector_serialized: bool = False

@abstractmethod
def serialize_selector(self) -> None:
Expand Down
13 changes: 7 additions & 6 deletions covalent/quantum/qcluster/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ class QCluster(AsyncBaseQCluster):
selector: Union[str, Callable] = "cyclic"

# Flag used to indicate whether `self.selector` is currently serialized.
_selector_serialized: bool = False
# This needs to be without the "_" prefix so that it gets propagated to the server.
selector_serialized: bool = False

def batch_submit(self, qscripts_list):
if self._selector_serialized:
if self.selector_serialized:
self.selector = self.deserialize_selector()

selector = self.get_selector()
Expand All @@ -58,24 +59,24 @@ def batch_submit(self, qscripts_list):
return selected_executor.batch_submit(qscripts_list)

def serialize_selector(self) -> None:
if self._selector_serialized:
if self.selector_serialized:
return

# serialize to bytes with cloudpickle
self.selector = cloudpickle_serialize(self.selector)

# convert to string to make JSON-able
self.selector = base64.b64encode(self.selector).decode("utf-8")
self._selector_serialized = True
self.selector_serialized = True

def deserialize_selector(self) -> Union[str, Callable]:
if not self._selector_serialized:
if not self.selector_serialized:
return self.selector

# Deserialize the selector function (or string).
selector = cloudpickle_deserialize(base64.b64decode(self.selector.encode("utf-8")))

self._selector_serialized = False
self.selector_serialized = False
return selector

def dict(self, *args, **kwargs) -> dict:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"""
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
Expand All @@ -43,7 +44,11 @@ def upgrade() -> None:
batch_op.create_foreign_key("electron_link", "electrons", ["parent_electron_id"], ["id"])

with op.batch_alter_table("electrons", schema=None) as batch_op:
batch_op.add_column(sa.Column("qelectron_data_exists", sa.Boolean(), nullable=False))
batch_op.add_column(
sa.Column(
"qelectron_data_exists", sa.Boolean(), nullable=False, server_default=sa.false()
)
)

# ### end Alembic commands ###

Expand Down

0 comments on commit f6554e2

Please sign in to comment.