Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add classical simulator #6124

Merged
merged 125 commits into from Nov 13, 2023

Conversation

naerabati
Copy link
Collaborator

No description provided.

@naerabati naerabati requested review from a team, vtomole and cduck as code owners June 7, 2023 14:51
@naerabati naerabati requested a review from dabacon June 7, 2023 14:51
@google-cla
Copy link

google-cla bot commented Jun 7, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@CirqBot CirqBot added the size: M 50< lines changed <250 label Jun 7, 2023
Copy link
Collaborator

@dstrain115 dstrain115 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to see the pull request appear! Now time to get the tests to pass.

You will also need to get the CLA (contributor license agreement) signed.

.vs/ProjectSettings.json Outdated Show resolved Hide resolved
cirq-core/cirq/sim/classical_simulator.py Outdated Show resolved Hide resolved
cirq-core/cirq/sim/__init__.py Outdated Show resolved Hide resolved
cirq-core/cirq/__init__.py Outdated Show resolved Hide resolved
cirq-core/cirq/sim/classical_simulator.py Outdated Show resolved Hide resolved
cirq-core/cirq/sim/classical_simulator.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for helping with this project. Please address only the remaining comments and we will be able to merge your PR :)

cirq-core/cirq/sim/classical_simulator.py Show resolved Hide resolved
@@ -64,7 +64,7 @@ def _unitary_(self) -> np.ndarray:
return m1

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to make any changes to this file or to the .gitignore file. please do

git checkout master cirq-core/cirq/protocols/unitary_protocol_test.py
git checkout master .gitignore
git add cirq-core/cirq/protocols/unitary_protocol_test.py .gitignore
git commit -m "restore unrelated files to their original state"

cirq-core/cirq/sim/classical_simulator.py Outdated Show resolved Hide resolved
match="Can not simulate gates other than "
+ "cirq.XGate, cirq.CNOT, cirq.SWAP, and cirq.CCNOT",
):
sim.run(circuit, param_resolver=resolver, repetitions=1).records
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add _ = before sim.run inorder to pass the pylint tests

cirq-core/cirq/sim/classical_simulator.py Outdated Show resolved Hide resolved


class ClassicalStateSimulator(SimulatesSamples):
"""basic simulator that only accepts cirq.X, cirq.ISwap, and cirq.CNOT gates
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please replace the docstring with

    """A simulator that only accepts only gates with classical counterparts.

    This simulator evolves a single state, using only gates that output a single state for each
    input state. The simulator runs in linear time, at the cost of not supporting superposition.
    It can be used to estimate costs and simulate circuits for simple non-quantum algorithms using
    many more qubits than fully capable quantum simulators.

    The supported gates are:
        - cirq.X
        - cirq.CNOT
        - cirq.SWAP
        - cirq.TOFFOLI
        - cirq.measure

    Args:
        circuit: The circuit to simulate.
        param_resolver: Parameters to run with the program.
        repetitions: Number of times to repeat the run. It is expected that
            this is validated greater than zero before calling this method.

    Returns:
        A dictionary mapping measurement keys to measurement results.

    Raises:
        ValueError: If one of the gates is not an X, CNOT, SWAP, TOFFOLI or a measurement.
    """

@NoureldinYosri NoureldinYosri enabled auto-merge (squash) November 13, 2023 19:27
@NoureldinYosri
Copy link
Collaborator

@naerabati thanks for your help with this project. I fixed the failing style CI and removed unrelated files.

@NoureldinYosri NoureldinYosri merged commit 2f702c8 into quantumlib:master Nov 13, 2023
35 checks passed
@naerabati
Copy link
Collaborator Author

@naerabati thanks for your help with this project. I fixed the failing style CI and removed unrelated files.

thanks so much! I'm glad to see this merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants