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

Consistent final_state_vector #5267

Merged
merged 15 commits into from
May 9, 2022
Merged

Conversation

95-martin-orion
Copy link
Collaborator

Fixes #3693.

This pushes Circuit.final_state_vector and mux.final_state_vector towards a shared API of:

def final_state_vector(
    program: 'cirq.CIRCUIT_LIKE',
    *,
    initial_state: 'cirq.STATE_VECTOR_LIKE' = 0,
    param_resolver: 'cirq.ParamResolverOrSimilarType' = None,
    qubit_order: 'cirq.QubitOrderOrList' = ops.QubitOrder.DEFAULT,
    ignore_terminal_measurements: bool = False,
    dtype: Type[np.number] = np.complex64,
    seed: 'cirq.RANDOM_STATE_OR_SEED_LIKE' = None,
) -> 'np.ndarray':

Additionally, calls to Circuit.final_state_vector will now pass through the simulator instead of using apply_unitary.

Notable changes in Circuit:

  • qubits_that_should_be_present is deprecated
  • Use of positional args is deprecated
  • The default of ignore_terminal_measurements will change to False in v0.16
  • The default of dtype has directly changed to np.complex64

Notable changes in mux:

  • Addition of ignore_terminal_measurements parameter

Other changes:

  • Added drop_terminal_measurements transformer

@95-martin-orion 95-martin-orion requested review from a team, vtomole and cduck as code owners April 18, 2022 17:10
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@CirqBot CirqBot added the size: L 250< lines changed <1000 label Apr 18, 2022
@95-martin-orion
Copy link
Collaborator Author

Shout-out to @tanujkhattar for the Transformers API - it massively simplified the process of migrating drop-terminal-measurements behavior from in-simulation to pre-simulation. Thanks Tanuj!

Copy link
Collaborator

@tanujkhattar tanujkhattar left a comment

Choose a reason for hiding this comment

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

Some initial comments on the newly added transformer.

Also, glad to see more uses of the transformer api infra :)

Copy link
Collaborator

@tanujkhattar tanujkhattar left a comment

Choose a reason for hiding this comment

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

LGTM % one final concern around a breaking change

cirq-core/cirq/circuits/circuit.py Outdated Show resolved Hide resolved
cirq-core/cirq/sim/mux.py Show resolved Hide resolved
cirq-core/cirq/circuits/circuit.py Outdated Show resolved Hide resolved
@95-martin-orion 95-martin-orion added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label May 9, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label May 9, 2022
@CirqBot CirqBot merged commit af4ce3d into quantumlib:master May 9, 2022
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels May 9, 2022
@95-martin-orion 95-martin-orion deleted the monofsv branch May 9, 2022 20:01
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Fixes quantumlib#3693.

This pushes `Circuit.final_state_vector` and `mux.final_state_vector` towards a shared API of:
```python
def final_state_vector(
    program: 'cirq.CIRCUIT_LIKE',
    *,
    initial_state: 'cirq.STATE_VECTOR_LIKE' = 0,
    param_resolver: 'cirq.ParamResolverOrSimilarType' = None,
    qubit_order: 'cirq.QubitOrderOrList' = ops.QubitOrder.DEFAULT,
    ignore_terminal_measurements: bool = False,
    dtype: Type[np.number] = np.complex64,
    seed: 'cirq.RANDOM_STATE_OR_SEED_LIKE' = None,
) -> 'np.ndarray':
```
Additionally, calls to `Circuit.final_state_vector` will now pass through the simulator instead of using `apply_unitary`.

Notable changes in `Circuit`:
- `qubits_that_should_be_present` is deprecated
- Use of positional args is deprecated
- The default of `ignore_terminal_measurements` will change to `False` in v0.16
- The default of `dtype` has directly changed to `np.complex64`

Notable changes in `mux`:
- Addition of `ignore_terminal_measurements` parameter

Other changes:
- Added `drop_terminal_measurements` transformer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: L 250< lines changed <1000
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make cirq.final_state_vector and cirq.AbstractCircuit.final_state_vector consistent
3 participants