Skip to content

Commit

Permalink
[cg.workflow] Update str(ProcessorRecord) (#5012)
Browse files Browse the repository at this point in the history
These should be good for e.g. plot legends
  • Loading branch information
mpharrigan authored Feb 24, 2022
1 parent 43527c8 commit 6f9e277
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion cirq-google/cirq_google/workflow/processor_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def get_processor(self) -> 'cg.EngineProcessor':
def __repr__(self):
return dataclass_repr(self, namespace='cirq_google')

def __str__(self) -> str:
return self.processor_id

@classmethod
def _json_namespace_(cls) -> str:
return 'cirq.google'
Expand Down Expand Up @@ -143,7 +146,7 @@ def __str__(self) -> str:
elif self.noise_strength == float('inf'):
suffix = 'zeros'
else:
suffix = f'p={self.noise_strength:.3e}'
suffix = f'depol({self.noise_strength:.3e})'
return f'{self.processor_id}-{suffix}'

def __repr__(self) -> str:
Expand Down
3 changes: 2 additions & 1 deletion cirq-google/cirq_google/workflow/processor_record_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def test_engine_backend(get_processor, _):
assert isinstance(proc_rec.get_sampler(), cirq.Sampler)
assert isinstance(proc_rec.get_device(), cirq.Device)
cirq.testing.assert_equivalent_repr(proc_rec, global_vals={'cirq_google': cg})
assert str(proc_rec) == 'rainbow'


@mock.patch('cirq_google.engine.client.quantum.QuantumEngineServiceClient')
Expand Down Expand Up @@ -124,7 +125,7 @@ def test_simulated_backend_descriptive_name():
assert isinstance(p.get_sampler(), cirq.Simulator)

p = cg.SimulatedProcessorWithLocalDeviceRecord('rainbow', noise_strength=1e-3)
assert str(p) == 'rainbow-p=1.000e-03'
assert str(p) == 'rainbow-depol(1.000e-03)'
assert isinstance(p.get_sampler(), cirq.DensityMatrixSimulator)

p = cg.SimulatedProcessorWithLocalDeviceRecord('rainbow', noise_strength=float('inf'))
Expand Down

0 comments on commit 6f9e277

Please sign in to comment.