def test_fails_with_neither_ansatz_specs_nor_number_of_parameters(self, ): seed = RNDSEED filename = "params.json" try: with pytest.raises(AssertionError): generate_random_ansatz_params(seed=seed, ) finally: remove_file_if_exists(filename)
def test_generate_random_ansatz_params_using_number_of_parameters( self, number_of_parameters, ): # Given seed = RNDSEED filename = "params.json" remove_file_if_exists(filename) # When generate_random_ansatz_params( number_of_parameters=number_of_parameters, seed=seed) # Then try: parameters = load_circuit_template_params(filename) assert len(parameters) == number_of_parameters finally: remove_file_if_exists(filename)
def test_fails_with_both_ansatz_specs_and_number_of_parameters(self, ): number_of_parameters = 2 ansatz_specs = { "module_name": "zquantum.core.interfaces.mock_objects", "function_name": "MockAnsatz", "number_of_layers": 2, "problem_size": 1, } seed = RNDSEED filename = "params.json" try: with pytest.raises(AssertionError): generate_random_ansatz_params( ansatz_specs=ansatz_specs, number_of_parameters=number_of_parameters, seed=seed, ) finally: remove_file_if_exists(filename)
def test_using_mock_ansatz_specs(self, number_of_layers): # Given ansatz_specs = { "module_name": "zquantum.core.interfaces.mock_objects", "function_name": "MockAnsatz", "number_of_layers": number_of_layers, "problem_size": 2, } seed = RNDSEED filename = "params.json" remove_file_if_exists(filename) # When generate_random_ansatz_params(ansatz_specs=ansatz_specs, seed=seed) # Then try: parameters = load_array(filename) assert len(parameters) == number_of_layers finally: remove_file_if_exists(filename)
def test_generate_random_ansatz_params_ansatz_specs_as_string(self): # Given number_of_layers = 5 ansatz_specs = { "module_name": "zquantum.core.interfaces.mock_objects", "function_name": "MockAnsatz", "number_of_layers": number_of_layers, "problem_size": 2, } seed = RNDSEED filename = "params.json" remove_file_if_exists(filename) # When generate_random_ansatz_params(ansatz_specs=json.dumps(ansatz_specs), seed=seed) # Then try: parameters = load_circuit_template_params(filename) assert len(parameters) == number_of_layers finally: remove_file_if_exists(filename)