text
stringclasses
220 values
"""
Read an array from an NPY file.
Parameters
----------
fp : file_like object
If this is not a real file object, then this may take extra memory
and time.
allow_pickle : bool, optional
Whether to allow writing pickled data. Default: False
.. versionchanged:: 1.16.3
Made default False in response to CVE-2019-6446.
pickle_kwargs : dict
Additional keyword arguments to pass to pickle.load. These are only
useful when loading object arrays saved on Python 2 when using
Python 3.
max_header_size : int, optional
Maximum allowed size of the header. Large headers may not be safe
to load securely and thus require explicitly passing a larger value.
See :py:func:`ast.literal_eval()` for details.
This option is ignored when `allow_pickle` is passed. In that case
the file is by definition trusted and the limit is unnecessary.
Returns
-------
array : ndarray
The array from the data on disk.
Raises
------
ValueError
If the data is invalid, or allow_pickle=False and the file contains
an object array.
"""
if allow_pickle:
# Effectively ignore max_header_size, since `allow_pickle` indicates
# that the input is fully trusted.
max_header_size = 2**64
version = read_magic(fp)
_check_version(version)
shape, fortran_order, dtype = _read_array_header(
fp, version, max_header_size=max_header_size)
if len(shape) == 0:
count = 1
else:
count = numpy.multiply.reduce(shape, dtype=numpy.int64)
# Now read the actual data.
if dtype.hasobject:
# The array contained Python objects. We need to unpickle the data.
if not allow_pickle:
> raise ValueError("Object arrays cannot be loaded when "
"allow_pickle=False")
E ValueError: Object arrays cannot be loaded when allow_pickle=False
/usr/local/lib/python3.12/site-packages/numpy/lib/format.py:822: ValueError
_________________ test_equation_probes_independently_recompute _________________
def test_equation_probes_independently_recompute() -> None:
result = load_result()
config = result["config"]
expected_pairs = [
(float(coupling), np.asarray(state, dtype=np.float64))
for coupling in config["couplings"]
for state in config["probe_states"]
]
assert len(result["probe_results"]) == len(expected_pairs)
for actual, (coupling, state) in zip(result["probe_results"], expected_pairs):
assert math.isclose(actual["coupling"], coupling)
assert np.allclose(actual["state"], state, atol=0.0, rtol=0.0)
drift_no = independent_drift(
state,
coupling,
float(config["sigma2"]),
int(config["n_oscillators"]),
False,
)
drift_with = independent_drift(
state,
coupling,
float(config["sigma2"]),
int(config["n_oscillators"]),
True,
)
covariance = independent_covariance(
state,
float(config["sigma2"]),
int(config["n_oscillators"]),
)
> assert np.allclose(actual["drift_no_finite_size"], drift_no, atol=2e-13, rtol=2e-12)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E KeyError: 'drift_no_finite_size'
/verifier/test_outputs.py:361: KeyError
_______________________ test_public_finite_time_outcomes _______________________