def test_run_simulator_sweeps(): simulator = cirq.SimulatesSamples() expected_measurements = {'a': np.array([[1]])} simulator._run.return_value = expected_measurements circuit = mock.Mock(cirq.Circuit) circuit.__iter__ = mock.Mock(return_value=iter([])) param_resolvers = [ mock.Mock(cirq.ParamResolver), mock.Mock(cirq.ParamResolver) ] for resolver in param_resolvers: resolver.param_dict = {} expected_results = [ cirq.Result.from_single_parameter_set( measurements=expected_measurements, params=param_resolvers[0]), cirq.Result.from_single_parameter_set( measurements=expected_measurements, params=param_resolvers[1]), ] assert expected_results == simulator.run_sweep(program=circuit, repetitions=10, params=param_resolvers) simulator._run.assert_called_with(circuit=circuit, repetitions=10, param_resolver=mock.ANY) assert simulator._run.call_count == 2
def test_run_simulator_run(): simulator = cirq.SimulatesSamples() expected_measurements = {'a': np.array([[1]])} simulator._run.return_value = expected_measurements circuit = mock.Mock(cirq.Circuit) param_resolver = mock.Mock(cirq.ParamResolver) expected_result = cirq.TrialResult.from_single_parameter_set( measurements=expected_measurements, params=param_resolver) assert expected_result == simulator.run(program=circuit, repetitions=10, param_resolver=param_resolver) simulator._run.assert_called_once_with(circuit=circuit, repetitions=10, param_resolver=param_resolver)
def test_run_simulator_run(): simulator = cirq.SimulatesSamples() expected_measurements = {'a': [[1]]} simulator._run.return_value = expected_measurements circuit = mock.Mock(cirq.Circuit) param_resolver = mock.Mock(cirq.ParamResolver) expected_result = cirq.TrialResult(repetitions=10, measurements=expected_measurements, params=param_resolver) assert expected_result == simulator.run(circuit=circuit, repetitions=10, param_resolver=param_resolver) simulator._run.assert_called_once_with(circuit=circuit, repetitions=10, param_resolver=param_resolver)
def test_run_simulator_run(): simulator = cirq.SimulatesSamples() expected_measurements = {'a': np.array([[1]])} simulator._run.return_value = expected_measurements circuit = mock.Mock(cirq.Circuit) circuit.__iter__ = mock.Mock(return_value=iter([])) param_resolver = mock.Mock(cirq.ParamResolver) param_resolver.param_dict = {} expected_result = cirq.Result(measurements=expected_measurements, params=param_resolver) assert expected_result == simulator.run(program=circuit, repetitions=10, param_resolver=param_resolver) simulator._run.assert_called_once_with(circuit=circuit, repetitions=10, param_resolver=param_resolver)
def test_run_simulator_sweeps(): simulator = cirq.SimulatesSamples() expected_measurements = {'a': np.array([[1]])} simulator._run.return_value = expected_measurements circuit = mock.Mock(cirq.Circuit) param_resolvers = [mock.Mock(cirq.ParamResolver), mock.Mock(cirq.ParamResolver)] expected_results = [cirq.TrialResult(repetitions=10, measurements=expected_measurements, params=param_resolvers[0]), cirq.TrialResult(repetitions=10, measurements=expected_measurements, params=param_resolvers[1])] assert expected_results == simulator.run_sweep(program=circuit, repetitions=10, params=param_resolvers) simulator._run.assert_called_with(circuit=circuit, repetitions=10, param_resolver=mock.ANY) assert simulator._run.call_count == 2