Skip to content

Commit

Permalink
Merge pull request #109 from alonkukl/master
Browse files Browse the repository at this point in the history
Enabling Pickle of QFactor object.
  • Loading branch information
edyounis authored Dec 14, 2022
2 parents 8ae1e9a + 46809c4 commit 682c332
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion bqskit/ir/opt/instantiaters/qfactor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""This module implements the QFactor class."""
from __future__ import annotations

import copy
import logging
from typing import Any
from typing import TYPE_CHECKING
Expand All @@ -27,7 +28,12 @@ class QFactor(QFactorInstantiatorNative, Instantiater):
def __new__(cls, **kwargs: dict[str, Any]) -> Any:
if 'cost_fn_gen' in kwargs:
del kwargs['cost_fn_gen']
return super().__new__(cls, **kwargs)

new_obj = super().__new__(cls, **kwargs)

new_obj.__orig_kwargs = copy.deepcopy(kwargs)

return new_obj

def instantiate(
self,
Expand Down Expand Up @@ -78,3 +84,6 @@ def get_violation_report(circuit: Circuit) -> str:
def get_method_name() -> str:
"""Return the name of this method."""
return 'qfactor'

def __getnewargs_ex__(self) -> tuple[Any, Any]:
return (tuple(), self.__orig_kwargs)

0 comments on commit 682c332

Please sign in to comment.