From fe7fe4e1d29e6b5fcc1643c0c73c26f8b37adae1 Mon Sep 17 00:00:00 2001 From: Jon Donovan Date: Mon, 28 Mar 2022 16:44:59 -0700 Subject: [PATCH] Support specific IonQ targets (qpu.generation) (#5141) * Support specific IonQ targets Allows for more specific backend targets. * fmt --- cirq-ionq/cirq_ionq/job.py | 2 +- cirq-ionq/cirq_ionq/job_test.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cirq-ionq/cirq_ionq/job.py b/cirq-ionq/cirq_ionq/job.py index b93924d5b07..04f273f6014 100644 --- a/cirq-ionq/cirq_ionq/job.py +++ b/cirq-ionq/cirq_ionq/job.py @@ -206,7 +206,7 @@ def results( f'Job was not completed successfully. Instead had status: {self.status()}' ) # IonQ returns results in little endian, Cirq prefers to use big endian, so we convert. - if self.target() == 'qpu': + if self.target().startswith('qpu'): repetitions = self.repetitions() counts = { _little_endian_to_big(int(k), self.num_qubits()): int(repetitions * float(v)) diff --git a/cirq-ionq/cirq_ionq/job_test.py b/cirq-ionq/cirq_ionq/job_test.py index ac83a2bab3e..f8bbf36dc35 100644 --- a/cirq-ionq/cirq_ionq/job_test.py +++ b/cirq-ionq/cirq_ionq/job_test.py @@ -101,6 +101,20 @@ def test_job_results_qpu_endianness(): assert results == ionq.QPUResult({0: 600, 2: 400}, 2, measurement_dict={}) +def test_job_results_qpu_target_endianness(): + job_dict = { + 'id': 'my_id', + 'status': 'completed', + 'qubits': '2', + 'target': 'qpu.target', + 'metadata': {'shots': 1000}, + 'data': {'histogram': {'0': '0.6', '1': '0.4'}}, + } + job = ionq.Job(None, job_dict) + results = job.results() + assert results == ionq.QPUResult({0: 600, 2: 400}, 2, measurement_dict={}) + + @mock.patch('time.sleep', return_value=None) def test_job_results_poll(mock_sleep): ready_job = {