Skip to content

Commit

Permalink
added scale with space
Browse files Browse the repository at this point in the history
Signed-off-by: Melvin Strobl <[email protected]>
  • Loading branch information
Melvin Strobl committed Nov 14, 2024
1 parent 2c8136f commit 487853c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion qml_essentials/expressibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def state_fidelities(
n_input_samples: int,
input_domain: List[float],
model: Model,
scale_with_space: bool = True,
**kwargs: Any,
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
"""
Expand All @@ -94,6 +95,8 @@ def state_fidelities(
n_input_samples (int): Number of input samples.
input_domain (List[float]): Input domain.
model (Callable): Function that models the quantum circuit.
scale_with_space (bool): Whether to scale the number of
samples (exp) and bins (lin) with the number of qubits.
kwargs (Any): Additional keyword arguments for the model function.
Returns:
Expand All @@ -103,6 +106,10 @@ def state_fidelities(

x = np.linspace(*input_domain, n_input_samples, requires_grad=False)

if scale_with_space:
n_samples = np.power(2, model.n_qubits) * n_samples
n_bins = model.n_qubits * n_bins

fidelities = Expressibility._sample_state_fidelities(
x_samples=x,
n_samples=n_samples,
Expand Down Expand Up @@ -168,6 +175,7 @@ def haar_integral(
n_qubits: int,
n_bins: int,
cache: bool = True,
scale_with_space: bool = True,
) -> Tuple[np.ndarray, np.ndarray]:
"""
Calculates theoretical probability density function for random Haar states
Expand All @@ -185,10 +193,13 @@ def haar_integral(
- y component (probabilities): the haar probability density
funtion for random Haar states
"""
if scale_with_space:
n_bins = n_qubits * n_bins

x = np.linspace(0, 1, n_bins)

if cache:
name = f"haar_{n_qubits}q_{n_bins}s.npy"
name = f"haar_{n_qubits}q_{n_bins}s_{'scaled' if scale_with_space else 'unscaled'}.npy"

cache_folder = ".cache"
if not os.path.exists(cache_folder):
Expand Down

0 comments on commit 487853c

Please sign in to comment.