Skip to content

Commit

Permalink
Address comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
fdmalone committed Jul 2, 2024
1 parent 094df6b commit 467a458
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def fixture_4_qubit_ham_trial_wf_and_blueprint(
seed=1,
)

bp = blueprint.build_blueprint(
bp = blueprint.BlueprintData.build_blueprint_from_dependencies(
blueprint_params, dependencies={trial_wf_params: trial_wf_data}
)

Expand Down
55 changes: 25 additions & 30 deletions recirq/qcqmc/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
from recirq.qcqmc import blueprint, config, data, for_refactor


def _to_tuple(x: Optional[Iterable[float]]) -> Optional[Sequence[float]]:
if x is None:
return x
return tuple(x)


@attrs.frozen(repr=False)
class SimulatedExperimentParams(data.Params):
"""Class for storing the parameters that specify an ExperimentData object.
Expand All @@ -52,7 +46,7 @@ class SimulatedExperimentParams(data.Params):
n_samples_per_clifford: int
noise_model_name: str
noise_model_params: Optional[Tuple[float, ...]] = attrs.field(
converter=_to_tuple, default=None
converter=lambda x: tuple(x) if x is not None else None, default=None
)
seed: int = 0
path_prefix: str = ""
Expand Down Expand Up @@ -91,34 +85,35 @@ def _json_dict_(self):
return simple_dict


def build_experiment(
params: SimulatedExperimentParams, *, dependencies: Dict[data.Params, data.Data]
) -> ExperimentData:
"""Builds an ExperimentData from ExperimentParams
@classmethod
def build_experiment_from_dependencies(
cls, params: SimulatedExperimentParams, *, dependencies: Dict[data.Params, data.Data]
) -> 'ExperimentData':
"""Builds an ExperimentData from ExperimentParams and any dependencies.
Args:
params: The experimental parameters.
dependencies: The dependencies leading up to this point (in particular the blueprint.)
"""
bp = dependencies[params.blueprint_params]
assert isinstance(bp, blueprint.BlueprintData)
assert params.blueprint_params == bp.params
Args:
params: The experimental parameters.
dependencies: The dependencies leading up to this point (in particular the blueprint.)
"""
bp = dependencies[params.blueprint_params]
assert isinstance(bp, blueprint.BlueprintData)
assert params.blueprint_params == bp.params

noise_model = for_refactor.get_noise_model(
params.noise_model_name, params.noise_model_params
)
noise_model = for_refactor.get_noise_model(
params.noise_model_name, params.noise_model_params
)

raw_samples = get_samples_from_simulation(
bp.compiled_circuit,
bp.resolvers,
noise_model,
params.n_samples_per_clifford,
params.seed,
)
raw_samples = get_samples_from_simulation(
bp.compiled_circuit,
bp.resolvers,
noise_model,
params.n_samples_per_clifford,
params.seed,
)

metadata = get_experimental_metadata()
metadata = get_experimental_metadata()

return ExperimentData(params=params, raw_samples=raw_samples, metadata=metadata)
return ExperimentData(params=params, raw_samples=raw_samples, metadata=metadata)


def get_samples_from_simulation(
Expand Down
9 changes: 7 additions & 2 deletions recirq/qcqmc/experiment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import cirq

from recirq.qcqmc.blueprint import BlueprintData
from recirq.qcqmc.experiment import SimulatedExperimentParams, build_experiment
from recirq.qcqmc.experiment import SimulatedExperimentParams, get_experimental_metadata, ExperimentData
from recirq.qcqmc.hamiltonian import HamiltonianData
from recirq.qcqmc.trial_wf import TrialWavefunctionData

Expand All @@ -38,7 +38,7 @@ def test_small_experiment_raw_samples_shape(
seed=1,
)

experiment = build_experiment(
experiment = ExperimentData.build_experiment_from_dependencies(
params=simulated_experiment_params,
dependencies={blueprint_data.params: blueprint_data},
)
Expand All @@ -49,3 +49,8 @@ def test_small_experiment_raw_samples_shape(

exp2 = cirq.read_json(json_text=cirq.to_json(experiment))
assert exp2 == experiment

def test_get_experimental_metadata():
md = get_experimental_metadata()
assert md.get('PST_formatted_date_time') is not None
assert md.get('iso_formatted_date_time') is not None

0 comments on commit 467a458

Please sign in to comment.