diff --git a/unitary/alpha/quantum_world.py b/unitary/alpha/quantum_world.py index 23aeb9b0..340d7c7f 100644 --- a/unitary/alpha/quantum_world.py +++ b/unitary/alpha/quantum_world.py @@ -486,7 +486,7 @@ def get_histogram( histogram[idx][cast(int, result[idx])] += 1 return histogram - def get_histogram_with_all_objects_as_key( + def get_correlated_histogram( self, objects: Optional[Sequence[QuantumObject]] = None, count: int = 100 ) -> Dict[Tuple[int], int]: """Creates histogram of the whole quantum world (or `objects` if specified) @@ -576,8 +576,7 @@ def get_binary_probabilities_from_state_vector( if objects is None: objects = self.public_objects - simulator = cirq.Simulator() - result = simulator.simulate(self.circuit, initial_state=0) + result = cirq.Simulator().simulate(self.circuit, initial_state=0) state_vector = result.state_vector() # qubit_map gives the mapping from object to its index in (the dirac notation of) # the state vector. @@ -633,7 +632,7 @@ def get_binary_probabilities_from_state_vector( # Renormalize. final_world_distribution[key] = abs(coefficients[index]) ** 2 / prob_sum - # TODO(pengfeichen): make the above calculation a seperate function, which calculates + # TODO(pengfeichen): make the above calculation a separate function, which calculates # the distribution of the whole world (or specified objects) by state vector. # Calculate the distribution of all objects. diff --git a/unitary/alpha/quantum_world_test.py b/unitary/alpha/quantum_world_test.py index 0d230c7b..0d21719a 100644 --- a/unitary/alpha/quantum_world_test.py +++ b/unitary/alpha/quantum_world_test.py @@ -656,7 +656,7 @@ def test_get_histogram_and_get_probabilities_one_binary_qobject( ) histogram = world.get_histogram() assert histogram == [{0: 0, 1: 100}] - histogram = world.get_histogram_with_all_objects_as_key() + histogram = world.get_correlated_histogram() assert histogram == {(1,): 100} probs = world.get_probabilities() assert probs == [{0: 0.0, 1: 1.0}] @@ -667,7 +667,7 @@ def test_get_histogram_and_get_probabilities_one_binary_qobject( alpha.Flip()(l1) histogram = world.get_histogram() assert histogram == [{0: 100, 1: 0}] - histogram = world.get_histogram_with_all_objects_as_key() + histogram = world.get_correlated_histogram() assert histogram == {(0,): 100} probs = world.get_probabilities() assert probs == [{0: 1.0, 1: 0.0}] @@ -681,7 +681,7 @@ def test_get_histogram_and_get_probabilities_one_binary_qobject( assert len(histogram[0]) == 2 assert histogram[0][0] > 10 assert histogram[0][1] > 10 - histogram = world.get_histogram_with_all_objects_as_key() + histogram = world.get_correlated_histogram() assert len(histogram) == 2 assert histogram[(0,)] > 10 assert histogram[(1,)] > 10 @@ -714,7 +714,7 @@ def test_get_histogram_and_get_probabilities_one_trinary_qobject( ) histogram = world.get_histogram() assert histogram == [{0: 0, 1: 100, 2: 0}] - histogram = world.get_histogram_with_all_objects_as_key() + histogram = world.get_correlated_histogram() assert histogram == {(1,): 100} probs = world.get_probabilities() assert probs == [{0: 0.0, 1: 1.0, 2: 0.0}] @@ -746,7 +746,7 @@ def test_get_histogram_and_get_probabilities_two_qobjects(simulator, compile_to_ ) histogram = world.get_histogram() assert histogram == [{0: 0, 1: 100}, {0: 0, 1: 100, 2: 0}] - histogram = world.get_histogram_with_all_objects_as_key() + histogram = world.get_correlated_histogram() assert histogram == {(1, 1): 100} probs = world.get_probabilities() assert probs == [{0: 0.0, 1: 1.0}, {0: 0.0, 1: 1.0, 2: 0.0}] @@ -754,7 +754,7 @@ def test_get_histogram_and_get_probabilities_two_qobjects(simulator, compile_to_ assert bin_probs == [1.0, 1.0] histogram = world.get_histogram(objects=[l2], count=1000) assert histogram == [{0: 0, 1: 1000, 2: 0}] - histogram = world.get_histogram_with_all_objects_as_key(objects=[l2], count=1000) + histogram = world.get_correlated_histogram(objects=[l2], count=1000) assert histogram == {(1,): 1000} probs = world.get_probabilities(objects=[l2], count=1000) assert probs == [{0: 0.0, 1: 1.0, 2: 0.0}]