Skip to content

Commit

Permalink
Add to_dict() to KeyValueExecutableSpec (#5072)
Browse files Browse the repository at this point in the history
Goal would be to fix #4734
  • Loading branch information
tonybruguier authored Mar 17, 2022
1 parent c153664 commit b2d8dd9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cirq-google/cirq_google/workflow/quantum_executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class KeyValueExecutableSpec(ExecutableSpec):
executable_family: str
key_value_pairs: Tuple[Tuple[str, Any], ...] = ()

def to_dict(self) -> Dict[str, Any]:
return dict(self.key_value_pairs)

@classmethod
def _json_namespace_(cls) -> str:
return 'cirq.google'
Expand Down
12 changes: 12 additions & 0 deletions cirq-google/cirq_google/workflow/quantum_executable_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ def test_kv_executable_spec():
hash(KeyValueExecutableSpec(executable_family='', key_value_pairs=[('name', 'test')]))


def test_dict_round_trip():
input_dict = dict(name='test', idx=5)

kv = KeyValueExecutableSpec.from_dict(
input_dict, executable_family='cirq_google.algo_benchmarks.example'
)

actual_dict = kv.to_dict()

assert input_dict == actual_dict


def test_kv_repr():
kv = _get_example_spec()
cirq.testing.assert_equivalent_repr(kv, global_vals={'cirq_google': cirq_google})
Expand Down

0 comments on commit b2d8dd9

Please sign in to comment.