def _build_service_results( mock_qpu_implementer: Any, circuit: cirq.Circuit, sweepable: cirq.Sweepable, *, executor: executors.CircuitSweepExecutor = _default_executor, transformer: transformers.CircuitTransformer = transformers.default, ) -> Tuple[Sequence[cirq.Result], QuantumComputer, List["np.ndarray[Any, np.dtype[np.float_]]"], List[cirq.ParamResolver], ]: repetitions = 2 param_resolvers = [r for r in cirq.to_resolvers(sweepable)] param_resolver_index = min(1, len(param_resolvers) - 1) param_resolver = param_resolvers[param_resolver_index] expected_results = [ np.ones( (repetitions, )) * (param_resolver["t"] if "t" in param_resolver else param_resolver_index) ] quantum_computer = mock_qpu_implementer.implement_passive_quantum_computer_with_results( expected_results) service = RigettiQCSService(quantum_computer=quantum_computer, executor=executor, transformer=transformer) result = service.run(circuit=circuit, param_resolver=param_resolver, repetitions=repetitions) return [result], quantum_computer, expected_results, [param_resolver]
def test_parametric_circuit_through_service( parametric_circuit_with_params: Tuple[cirq.Circuit, cirq.Linspace]) -> None: """test that RigettiQCSService can run a basic parametric circuit on the QVM and return an accurate `cirq.study.Result`. """ circuit, sweepable = parametric_circuit_with_params qc = get_qc('9q-square', as_qvm=True) service = RigettiQCSService(quantum_computer=qc, ) # set the seed so we get a deterministic set of results. qvm = cast(QVM, qc.qam) qvm.random_seed = 0 repetitions = 10 param_resolvers = [r for r in cirq.study.to_resolvers(sweepable)] result = service.run( circuit=circuit, repetitions=repetitions, param_resolver=param_resolvers[1], ) assert isinstance(result, cirq.study.Result) assert sweepable[1] == result.params assert 'm' in result.measurements assert (repetitions, 1) == result.measurements['m'].shape counter = result.histogram(key='m') assert 4 == counter[0] assert 6 == counter[1]
def test_bell_circuit_through_service(bell_circuit: cirq.Circuit) -> None: """test that RigettiQCSService can run a basic bell circuit on the QVM and return an accurate ``cirq.study.Result``. """ qc = get_qc('9q-square', as_qvm=True) service = RigettiQCSService(quantum_computer=qc, ) # set the seed so we get a deterministic set of results. qvm = cast(QVM, qc.qam) qvm.random_seed = 0 repetitions = 10 result = service.run(circuit=bell_circuit, repetitions=repetitions) assert isinstance(result, cirq.study.Result) assert 0 == len(result.params.param_dict) assert 'm' in result.measurements assert (repetitions, 2) == result.measurements['m'].shape counter = result.histogram(key='m') assert 6 == counter.get(0) assert counter.get(1) is None assert counter.get(2) is None assert 4 == counter.get(3)