Skip to content

Commit

Permalink
Added README.md file to qml_lfe 6/7. (#245)
Browse files Browse the repository at this point in the history
* Add shadows I + P datataking module. 5/n

* remove p39 feature.

* Doug feedback.

* Doug feedback p2.

* Added qml_lfe Readme.md 6/7.

* reverted import practices.

* missed moves.
  • Loading branch information
MichaelBroughton authored Dec 10, 2021
1 parent fee620b commit 6cf7bc2
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 50 deletions.
21 changes: 21 additions & 0 deletions recirq/qml_lfe/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Simulation and data analysis code for "Quantum advantage in learning from experiments"

Code to generate main text data for [Quantum advantage in learning from experiments](https://arxiv.org/abs/2112.00778)

Running `python3 -m recirq.qml_lfe.learn_***_* --help` will give a list of all available command line
flags for each experiment file as well as a short description of what each experiment
module does.

To generate bitstring data for an 8-qubit depth-5 experiment on learning 1D physical dynamics:

`python3 -m recirq.qml_lfe.learn_dynamics_c --n=8 --depth=5`

`python3 -m recirq.qml_lfe.learn_dynamics_q.py --n=8 --depth=5`

To generate bitstring data for an 8-qubit experiment on learning physical states:

`python3 -m recirq.qml_lfe.learn_states_c.py --n=8`

`python3 -m recirq.qml_lfe.learn_states_q.py --n=8`


2 changes: 1 addition & 1 deletion recirq/qml_lfe/circuit_blocks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import pytest
from . import circuit_blocks
from recirq.qml_lfe import circuit_blocks
import cirq
import cirq_google
import numpy as np
Expand Down
4 changes: 3 additions & 1 deletion recirq/qml_lfe/dynamics_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
)

flags.DEFINE_string(
"save_dir", "./data", "Path to save experiment data (must already exist)."
"save_dir",
"./recirq/qml_lfe/data",
"Path to save experiment data (must already exist).",
)

flags.DEFINE_bool("use_engine", False, "Whether or not to use quantum engine.")
24 changes: 13 additions & 11 deletions recirq/qml_lfe/learn_dynamics_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
import os
import cirq
import numpy as np
from . import circuit_blocks
from . import run_config

from absl import app
from absl import logging

from recirq.qml_lfe import circuit_blocks
from recirq.qml_lfe import run_config


def _build_circuit(
qubit_pairs: List[List[cirq.Qid]], use_tsym: bool, depth: int
Expand Down Expand Up @@ -132,18 +134,18 @@ def run_and_save(


def main(_):
from . import dynamics_flags

run_and_save(
dynamics_flags.n,
dynamics_flags.depth,
dynamics_flags.n_data,
dynamics_flags.batch_size,
dynamics_flags.n_shots,
dynamics_flags.save_dir,
dynamics_flags.use_engine,
dynamics_flags.FLAGS.n,
dynamics_flags.FLAGS.depth,
dynamics_flags.FLAGS.n_data,
dynamics_flags.FLAGS.batch_size,
dynamics_flags.FLAGS.n_shots,
dynamics_flags.FLAGS.save_dir,
dynamics_flags.FLAGS.use_engine,
)


if __name__ == "__main__":
from recirq.qml_lfe import dynamics_flags

app.run(main)
2 changes: 1 addition & 1 deletion recirq/qml_lfe/learn_dynamics_c_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import os
import pytest
import numpy as np
from . import learn_dynamics_c
from recirq.qml_lfe import learn_dynamics_c


def test_shadows_dont_seperate(tmpdir):
Expand Down
24 changes: 13 additions & 11 deletions recirq/qml_lfe/learn_dynamics_q.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
import os
import cirq
import numpy as np
from . import circuit_blocks
from . import run_config

from absl import app
from absl import logging

from recirq.qml_lfe import circuit_blocks
from recirq.qml_lfe import run_config


def _build_circuit(
qubit_pairs: List[List[cirq.Qid]], use_tsym: bool, depth: int
Expand Down Expand Up @@ -148,18 +150,18 @@ def run_and_save(


def main(_):
from . import dynamics_flags

run_and_save(
dynamics_flags.n,
dynamics_flags.depth,
dynamics_flags.n_data,
dynamics_flags.batch_size,
dynamics_flags.n_shots,
dynamics_flags.save_dir,
dynamics_flags.use_engine,
dynamics_flags.FLAGS.n,
dynamics_flags.FLAGS.depth,
dynamics_flags.FLAGS.n_data,
dynamics_flags.FLAGS.batch_size,
dynamics_flags.FLAGS.n_shots,
dynamics_flags.FLAGS.save_dir,
dynamics_flags.FLAGS.use_engine,
)


if __name__ == "__main__":
from recirq.qml_lfe import dynamics_flags

app.run(main)
2 changes: 1 addition & 1 deletion recirq/qml_lfe/learn_dynamics_q_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import os
import pytest
import numpy as np
from . import learn_dynamics_q
from recirq.qml_lfe import learn_dynamics_q


def test_twocopy_seperates(tmpdir):
Expand Down
21 changes: 11 additions & 10 deletions recirq/qml_lfe/learn_states_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
import cirq
import numpy as np
import sympy
from . import circuit_blocks
from . import run_config

from absl import app
from absl import logging

from recirq.qml_lfe import circuit_blocks
from recirq.qml_lfe import run_config


def _create_basis_sweeps(
H_params: List[sympy.Symbol],
Expand Down Expand Up @@ -203,17 +204,17 @@ def run_and_save(


def main(_):
from . import state_flags

run_and_save(
state_flags.n,
state_flags.n_paulis,
state_flags.n_sweeps,
state_flags.n_shots,
state_flags.save_dir,
state_flags.use_engine,
state_flags.FLAGS.n,
state_flags.FLAGS.n_paulis,
state_flags.FLAGS.n_sweeps,
state_flags.FLAGS.n_shots,
state_flags.FLAGS.save_dir,
state_flags.FLAGS.use_engine,
)


if __name__ == "__main__":
from recirq.qml_lfe import state_flags

app.run(main)
2 changes: 1 addition & 1 deletion recirq/qml_lfe/learn_states_c_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest
import tempfile
import numpy as np
from . import learn_states_c
from recirq.qml_lfe import learn_states_c


def _predict_exp(data, paulistring, two_copy):
Expand Down
21 changes: 11 additions & 10 deletions recirq/qml_lfe/learn_states_q.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
import cirq
import numpy as np
import sympy
from . import circuit_blocks
from . import run_config

from absl import app
from absl import logging

from recirq.qml_lfe import circuit_blocks
from recirq.qml_lfe import run_config


def build_circuit(
qubit_pairs: List[List[cirq.Qid]],
Expand Down Expand Up @@ -152,17 +153,17 @@ def run_and_save(


def main(_):
from . import state_flags

run_and_save(
state_flags.n,
state_flags.n_paulis,
state_flags.n_sweeps,
state_flags.n_shots,
state_flags.save_dir,
state_flags.use_engine,
state_flags.FLAGS.n,
state_flags.FLAGS.n_paulis,
state_flags.FLAGS.n_sweeps,
state_flags.FLAGS.n_shots,
state_flags.FLAGS.save_dir,
state_flags.FLAGS.use_engine,
)


if __name__ == "__main__":
from recirq.qml_lfe import state_flags

app.run(main)
2 changes: 1 addition & 1 deletion recirq/qml_lfe/learn_states_q_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import pytest
import os
import numpy as np
from . import learn_states_q
from recirq.qml_lfe import learn_states_q


def _predict_exp(data, paulistring, two_copy):
Expand Down
2 changes: 1 addition & 1 deletion recirq/qml_lfe/run_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
import pytest
import cirq
from . import run_config
from recirq.qml_lfe import run_config
import numpy as np


Expand Down
4 changes: 3 additions & 1 deletion recirq/qml_lfe/state_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
)

flags.DEFINE_string(
"save_dir", "./data", "Path to save experiment data (must already exist)."
"save_dir",
"./recirq/qml_lfe/data",
"Path to save experiment data (must already exist).",
)

flags.DEFINE_bool("use_engine", False, "Whether or not to use quantum engine.")

0 comments on commit 6cf7bc2

Please sign in to comment.