Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cg.workflow] Update str(ProcessorRecord) #5012

Merged
merged 3 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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