Cirq icon indicating copy to clipboard operation
Cirq copied to clipboard

Update ClassicalSimulator to use simulation infrastructure

Open NoureldinYosri opened this issue 2 years ago • 5 comments

Update Classical Simulator to use https://github.com/quantumlib/Cirq/pull/5417


What is the urgency from your perspective for this issue? Is it blocking important work? P2 - we should do it in the next couple of quarters

NoureldinYosri avatar Nov 10 '23 19:11 NoureldinYosri

Hi @NoureldinYosri, I'm interested in working on this issue and have been looking through the related information.

shef4 avatar Nov 21 '23 02:11 shef4

Started work on class based on the ComputationalBasisState and ComputationalBasisSimState classes shown in custom_state_simulator_test.py from #5417.

shef4 avatar Nov 28 '23 15:11 shef4

@shef4 The classical simulator is already implemented https://github.com/quantumlib/Cirq/blob/master/cirq-core/cirq/sim/classical_simulator.py

The goal of this issue is align the implementation with that of other simulators using the infrastructure introduced in the linked PR.

NoureldinYosri avatar Nov 28 '23 19:11 NoureldinYosri

@NoureldinYosri Thanks for clarification. The code I sent is on based on example of infrastructure in custom_state_simulator_test.py. (ComputationalBasisSimState)

I changed the _act_on_fallback_ to include the behaviour and gates described in classical_simulator and comments mentioned in #6124 .

Honestly not sure if using _act_on_fallback_ was the correct thing to do and based it off of ComputationalBasisSimState.

shef4 avatar Nov 28 '23 21:11 shef4

Hi @NoureldinYosri, I see why the test is failing now. They are based on the abstract method in the SimulatesSamples class, _run(program, repetitions, param_resolver).

There's a formatting mismatch between:

  1. ClassicalStateSimulator.run(circuit, param_resolver=None, repetitions=1).records = {'key': array([[[1, 0]]], dtype=uint8)}
  2. CustomStateSimulator(ClassicalStateSimulator).simulate(circuit).measurements = {'key': array([1, 0], dtype=uint8)}

Thanks for the help!

q0, q1 = cirq.LineQubit.range(2)
circuit = cirq.Circuit()
circuit.append(cirq.X(q0))
circuit.append(cirq.X(q1))
circuit.append(cirq.X(q1))
circuit.append(cirq.measure((q0, q1), key='key'))

shef4 avatar Dec 20 '23 20:12 shef4

completed in https://github.com/quantumlib/Cirq/pull/6432

NoureldinYosri avatar Mar 19 '24 19:03 NoureldinYosri