From 6d12636300829a6fc2a5588585c6f910006f8e99 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Thu, 21 Sep 2023 13:12:03 -0700 Subject: [PATCH 01/39] allow representing simulation results as 1D array --- qsimcirq/qsim_simulator.py | 60 ++++++++++++++++++++++++++++++++- qsimcirq_tests/qsimcirq_test.py | 12 +++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/qsimcirq/qsim_simulator.py b/qsimcirq/qsim_simulator.py index 37d497ed..f94b28eb 100644 --- a/qsimcirq/qsim_simulator.py +++ b/qsimcirq/qsim_simulator.py @@ -435,12 +435,67 @@ def compute_amplitudes_sweep_iter( options["s"] = self.get_seed() yield simulator_fn(options) + def simulate( + self, + program: cirq.AbstractCircuit, + param_resolver: cirq.ParamResolverOrSimilarType = None, + qubit_order: cirq.QubitOrderOrList = cirq.ops.QubitOrder.DEFAULT, + initial_state: Any = None, + as_1d_state_vector: bool = False, + ) -> cirq.sim.simulator.TSimulationTrialResult: + """Simulates the supplied Circuit. + + This method returns a result which allows access to the entire + simulator's final state. + + Args: + program: The circuit to simulate. + param_resolver: Parameters to run with the program. + qubit_order: Determines the canonical ordering of the qubits. This + is often used in specifying the initial state, i.e. the + ordering of the computational basis states. + initial_state: The initial state for the simulation. The form of + this state depends on the simulation implementation. See + documentation of the implementing class for details. + as_1d_state_vector: Whether the returned state vector is 1D or + has number of dimensions equal number of qubits. + Operations on 1D representation are significantly slower than + the other representation and might not even work. + The 1D representation should only be used when the number of qubits + is larger than the dimension limit on numpy arrays (numpy/numpy#5744). + + Returns: + SimulationTrialResults for the simulation. Includes the final state. + """ + return self.simulate_sweep( + program, + cirq.study.ParamResolver(param_resolver), + qubit_order, + initial_state, + as_1d_state_vector, + )[0] + + def simulate_sweep( + self, + program: cirq.AbstractCircuit, + params: cirq.Sweepable, + qubit_order: cirq.QubitOrderOrList = cirq.ops.QubitOrder.DEFAULT, + initial_state: Any = None, + as_1d_state_vector: bool = False, + ) -> List[cirq.sim.simulator.TSimulationTrialResult]: + return list( + self.simulate_sweep_iter( + program, params, qubit_order, initial_state, as_1d_state_vector + ) + ) + def simulate_sweep_iter( self, program: cirq.Circuit, params: cirq.Sweepable, qubit_order: cirq.QubitOrderOrList = cirq.QubitOrder.DEFAULT, initial_state: Optional[Union[int, np.ndarray]] = None, + as_1d_state_vector: bool = False, ) -> Iterator[cirq.StateVectorTrialResult]: """Simulates the supplied Circuit. @@ -463,6 +518,8 @@ def simulate_sweep_iter( be an integer representing a pure state (e.g. 11010) or a numpy array containing the full state vector. If none is provided, this is assumed to be the all-zeros state. + as_1d_state_vector: Whether the returned state vector is 1D or + has number of dimensions equal number of qubits. Returns: List of SimulationTrialResults for this run, one for each @@ -527,7 +584,8 @@ def simulate_sweep_iter( assert qsim_state.ndim == 1 final_state = cirq.StateVectorSimulationState( - initial_state=qsim_state.view(np.complex64), qubits=cirq_order + initial_state=qsim_state.view(np.complex64), + qubits=cirq_order if not as_1d_state_vector else None, ) # create result for this parameter # TODO: We need to support measurements. diff --git a/qsimcirq_tests/qsimcirq_test.py b/qsimcirq_tests/qsimcirq_test.py index 82ddb1f0..a9a56489 100644 --- a/qsimcirq_tests/qsimcirq_test.py +++ b/qsimcirq_tests/qsimcirq_test.py @@ -2058,3 +2058,15 @@ def test_cirq_global_phase_gate(): assert cirq.approx_eq( qsim_result.state_vector(), cirq_result.state_vector(), atol=1e-6 ) + + +def test_1d_representation(): + qsim_sim = qsimcirq.QSimSimulator() + qs = cirq.LineQubit.range(2) + c = cirq.Circuit(cirq.H.on_each(qs), cirq.X(qs[0]), cirq.Y(qs[1])) + + want = np.array([0.0 - 0.5j, 0.0 + 0.5j, 0.0 - 0.5j, 0.0 + 0.5j]) + res = qsim_sim.simulate(c, as_1d_state_vector=True) + np.testing.assert_allclose( + res.final_state_vector, np.array(want, dtype=np.complex64) + ) From 6705a06afdb386f7e8057e21306cda8d1aae99db Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Fri, 22 Sep 2023 11:45:02 -0700 Subject: [PATCH 02/39] add debug line --- pybind_interface/Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index b826d197..9497bcaa 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -1,6 +1,9 @@ # Base OS FROM qsim +RUN ln -sf /dev/stdout /var/log/nginx/access.log \ + && ln -sf /dev/stderr /var/log/nginx/error.log + # Install additional requirements RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip From 736d45bfbf23e83155518ebd42dddd1f91cdd3de Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Fri, 22 Sep 2023 11:49:14 -0700 Subject: [PATCH 03/39] Debug line --- pybind_interface/Dockerfile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index 9497bcaa..06e0ce77 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -1,15 +1,12 @@ # Base OS FROM qsim -RUN ln -sf /dev/stdout /var/log/nginx/access.log \ - && ln -sf /dev/stderr /var/log/nginx/error.log - # Install additional requirements RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip -# The --force flag is used mainly so that the old numpy installation from pybind +# The --force-reinstall flag is used mainly so that the old numpy installation from pybind # gets replaced with the one cirq requires -RUN pip3 install --prefer-binary cirq-core --force +RUN pip3 install --prefer-binary cirq-core --force-reinstall # Copy relevant files COPY ./pybind_interface/ /qsim/pybind_interface/ From 8c84f398fc949d1e9f2f779cebbbafa5b65e13fc Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Fri, 22 Sep 2023 11:52:43 -0700 Subject: [PATCH 04/39] Debug line --- pybind_interface/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index 06e0ce77..c6095129 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -4,9 +4,9 @@ FROM qsim # Install additional requirements RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip -# The --force-reinstall flag is used mainly so that the old numpy installation from pybind +# The --force flag is used mainly so that the old numpy installation from pybind # gets replaced with the one cirq requires -RUN pip3 install --prefer-binary cirq-core --force-reinstall +RUN pip3 install --prefer-binary cirq-core --force --verbose # Copy relevant files COPY ./pybind_interface/ /qsim/pybind_interface/ From 6337d592266346ef78c78fef07b39b46d1c9b7f4 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Fri, 22 Sep 2023 11:56:40 -0700 Subject: [PATCH 05/39] Debug line --- pybind_interface/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index c6095129..cfd2bcd0 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -6,7 +6,7 @@ RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip # The --force flag is used mainly so that the old numpy installation from pybind # gets replaced with the one cirq requires -RUN pip3 install --prefer-binary cirq-core --force --verbose +RUN pip3 install -vvv --prefer-binary cirq-core --force # Copy relevant files COPY ./pybind_interface/ /qsim/pybind_interface/ From 9b9e426f755b0383006516f169d0a0f17caad555 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Fri, 22 Sep 2023 12:01:59 -0700 Subject: [PATCH 06/39] Docker Debug line --- pybind_interface/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index cfd2bcd0..078bde35 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -6,7 +6,8 @@ RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip # The --force flag is used mainly so that the old numpy installation from pybind # gets replaced with the one cirq requires -RUN pip3 install -vvv --prefer-binary cirq-core --force +RUN pip3 install --upgrade numpy +RUN pip3 install -vvv --prefer-binary cirq-core --force-reinstall # Copy relevant files COPY ./pybind_interface/ /qsim/pybind_interface/ From 2c7c06baad2a6d4af46afcfe1f3df3790af22ddc Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Fri, 22 Sep 2023 12:05:46 -0700 Subject: [PATCH 07/39] Docker Debug line --- pybind_interface/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index 078bde35..6fa609b3 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -6,7 +6,7 @@ RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip # The --force flag is used mainly so that the old numpy installation from pybind # gets replaced with the one cirq requires -RUN pip3 install --upgrade numpy +RUN pip3 uninstall --force numpy RUN pip3 install -vvv --prefer-binary cirq-core --force-reinstall # Copy relevant files From 585a99683f4b4633bfe4522b1b4f48a20f0af01d Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Fri, 22 Sep 2023 12:09:01 -0700 Subject: [PATCH 08/39] Docker Debug line --- pybind_interface/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index 6fa609b3..9882a547 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -6,7 +6,7 @@ RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip # The --force flag is used mainly so that the old numpy installation from pybind # gets replaced with the one cirq requires -RUN pip3 uninstall --force numpy +RUN pip3 uninstall numpy RUN pip3 install -vvv --prefer-binary cirq-core --force-reinstall # Copy relevant files From 16b5ab66a2c6e15a0b8399a7a4d51c3007b12cbb Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Fri, 22 Sep 2023 12:12:26 -0700 Subject: [PATCH 09/39] Docker Debug line --- pybind_interface/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index 9882a547..1300b4fe 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -6,8 +6,7 @@ RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip # The --force flag is used mainly so that the old numpy installation from pybind # gets replaced with the one cirq requires -RUN pip3 uninstall numpy -RUN pip3 install -vvv --prefer-binary cirq-core --force-reinstall +RUN pip3 install -vvv --break-system-packages --prefer-binary cirq-core --force-reinstall # Copy relevant files COPY ./pybind_interface/ /qsim/pybind_interface/ From 575ba8dd73b416aabac802dea699280528c507f7 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Fri, 22 Sep 2023 12:27:10 -0700 Subject: [PATCH 10/39] Docker Debug line --- pybind_interface/Dockerfile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index 1300b4fe..40a33cfb 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -4,9 +4,11 @@ FROM qsim # Install additional requirements RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip -# The --force flag is used mainly so that the old numpy installation from pybind -# gets replaced with the one cirq requires -RUN pip3 install -vvv --break-system-packages --prefer-binary cirq-core --force-reinstall +# Install cirq-core +RUN pip3 install --prefer-binary cirq-core + +# Install pybind11 +RUN apt-get install -y python3-pybind11 # Copy relevant files COPY ./pybind_interface/ /qsim/pybind_interface/ From 7cdda0c7d4dcb852819d377fe77135e5d3bb1e36 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Fri, 22 Sep 2023 12:31:50 -0700 Subject: [PATCH 11/39] Docker Debug line --- pybind_interface/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index 40a33cfb..3fa175e2 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -6,6 +6,7 @@ RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip # Install cirq-core RUN pip3 install --prefer-binary cirq-core +RUN pip3 uinstall numpy --purge # Install pybind11 RUN apt-get install -y python3-pybind11 From 5794472d347d8fec9ef89c3c29a01168cc6336c1 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Fri, 22 Sep 2023 12:35:05 -0700 Subject: [PATCH 12/39] Docker Debug line --- pybind_interface/Dockerfile | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index 3fa175e2..c51563de 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -4,12 +4,9 @@ FROM qsim # Install additional requirements RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip -# Install cirq-core -RUN pip3 install --prefer-binary cirq-core -RUN pip3 uinstall numpy --purge - -# Install pybind11 -RUN apt-get install -y python3-pybind11 +# The --force-reinstall flag is used mainly so that the old numpy installation from pybind +# gets replaced with the one cirq requires +RUN pip3 install --break-system-packages --prefer-binary cirq-core --force-reinstall # Copy relevant files COPY ./pybind_interface/ /qsim/pybind_interface/ From d16dfa09269f441ed4c5b7074d7e50f1e0a53a7d Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Fri, 22 Sep 2023 14:21:38 -0700 Subject: [PATCH 13/39] Docker Debug line --- pybind_interface/Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index c51563de..331ed789 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -4,9 +4,9 @@ FROM qsim # Install additional requirements RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip -# The --force-reinstall flag is used mainly so that the old numpy installation from pybind -# gets replaced with the one cirq requires -RUN pip3 install --break-system-packages --prefer-binary cirq-core --force-reinstall +# The --force and --break-system-packages flags are used mainly so that the old numpy +# installation from pybind gets replaced with the one cirq requires +RUN pip3 install --break-system-packages --prefer-binary cirq-core --force # Copy relevant files COPY ./pybind_interface/ /qsim/pybind_interface/ From a1e5a22ce8f2f119d2f0a4a1d257b0a733a5614e Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Fri, 22 Sep 2023 14:42:05 -0700 Subject: [PATCH 14/39] revert changes to docker file --- pybind_interface/Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index 331ed789..b826d197 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -4,9 +4,9 @@ FROM qsim # Install additional requirements RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip -# The --force and --break-system-packages flags are used mainly so that the old numpy -# installation from pybind gets replaced with the one cirq requires -RUN pip3 install --break-system-packages --prefer-binary cirq-core --force +# The --force flag is used mainly so that the old numpy installation from pybind +# gets replaced with the one cirq requires +RUN pip3 install --prefer-binary cirq-core --force # Copy relevant files COPY ./pybind_interface/ /qsim/pybind_interface/ From 0009bc4f47d954c3eadd883aa458d78af7fa040e Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Fri, 22 Sep 2023 15:29:24 -0700 Subject: [PATCH 15/39] change into adding a new functionality --- qsimcirq/qsim_simulator.py | 149 +++++++++++++------------------- qsimcirq_tests/qsimcirq_test.py | 6 +- 2 files changed, 61 insertions(+), 94 deletions(-) diff --git a/qsimcirq/qsim_simulator.py b/qsimcirq/qsim_simulator.py index f94b28eb..405b9158 100644 --- a/qsimcirq/qsim_simulator.py +++ b/qsimcirq/qsim_simulator.py @@ -435,99 +435,13 @@ def compute_amplitudes_sweep_iter( options["s"] = self.get_seed() yield simulator_fn(options) - def simulate( - self, - program: cirq.AbstractCircuit, - param_resolver: cirq.ParamResolverOrSimilarType = None, - qubit_order: cirq.QubitOrderOrList = cirq.ops.QubitOrder.DEFAULT, - initial_state: Any = None, - as_1d_state_vector: bool = False, - ) -> cirq.sim.simulator.TSimulationTrialResult: - """Simulates the supplied Circuit. - - This method returns a result which allows access to the entire - simulator's final state. - - Args: - program: The circuit to simulate. - param_resolver: Parameters to run with the program. - qubit_order: Determines the canonical ordering of the qubits. This - is often used in specifying the initial state, i.e. the - ordering of the computational basis states. - initial_state: The initial state for the simulation. The form of - this state depends on the simulation implementation. See - documentation of the implementing class for details. - as_1d_state_vector: Whether the returned state vector is 1D or - has number of dimensions equal number of qubits. - Operations on 1D representation are significantly slower than - the other representation and might not even work. - The 1D representation should only be used when the number of qubits - is larger than the dimension limit on numpy arrays (numpy/numpy#5744). - - Returns: - SimulationTrialResults for the simulation. Includes the final state. - """ - return self.simulate_sweep( - program, - cirq.study.ParamResolver(param_resolver), - qubit_order, - initial_state, - as_1d_state_vector, - )[0] - - def simulate_sweep( - self, - program: cirq.AbstractCircuit, - params: cirq.Sweepable, - qubit_order: cirq.QubitOrderOrList = cirq.ops.QubitOrder.DEFAULT, - initial_state: Any = None, - as_1d_state_vector: bool = False, - ) -> List[cirq.sim.simulator.TSimulationTrialResult]: - return list( - self.simulate_sweep_iter( - program, params, qubit_order, initial_state, as_1d_state_vector - ) - ) - - def simulate_sweep_iter( + def _simulate_impl( self, program: cirq.Circuit, params: cirq.Sweepable, qubit_order: cirq.QubitOrderOrList = cirq.QubitOrder.DEFAULT, initial_state: Optional[Union[int, np.ndarray]] = None, - as_1d_state_vector: bool = False, - ) -> Iterator[cirq.StateVectorTrialResult]: - """Simulates the supplied Circuit. - - This method returns a result which allows access to the entire - wave function. In contrast to simulate, this allows for sweeping - over different parameter values. - - Avoid using this method with `use_gpu=True` in the simulator options; - when used with GPU this method must copy state from device to host memory - multiple times, which can be very slow. This issue is not present in - `simulate_expectation_values_sweep`. - - Args: - program: The circuit to simulate. - params: Parameters to run with the program. - qubit_order: Determines the canonical ordering of the qubits. This is - often used in specifying the initial state, i.e. the ordering of the - computational basis states. - initial_state: The initial state for the simulation. This can either - be an integer representing a pure state (e.g. 11010) or a numpy - array containing the full state vector. If none is provided, this - is assumed to be the all-zeros state. - as_1d_state_vector: Whether the returned state vector is 1D or - has number of dimensions equal number of qubits. - - Returns: - List of SimulationTrialResults for this run, one for each - possible parameter resolver. - - Raises: - TypeError: if an invalid initial_state is provided. - """ + ) -> Iterator[Tuple[cirq.ParamResolver, np.ndarray, Sequence[int]]]: if initial_state is None: initial_state = 0 if not isinstance(initial_state, (int, np.ndarray)): @@ -583,9 +497,64 @@ def simulate_sweep_iter( assert qsim_state.dtype == np.float32 assert qsim_state.ndim == 1 + yield prs, qsim_state.view(np.complex64), cirq_order + + def simulate_into_1d_array( + self, + program: cirq.AbstractCircuit, + param_resolver: cirq.ParamResolverOrSimilarType = None, + qubit_order: cirq.QubitOrderOrList = cirq.ops.QubitOrder.DEFAULT, + initial_state: Any = None, + ) -> np.ndarray: + """Same as simulate() but returns the state vector as 1D np.ndarray.""" + params = cirq.study.ParamResolver(param_resolver) + _, state_vector, _ = next( + self._simulate_impl(program, params, qubit_order, initial_state) + ) + return state_vector + + def simulate_sweep_iter( + self, + program: cirq.Circuit, + params: cirq.Sweepable, + qubit_order: cirq.QubitOrderOrList = cirq.QubitOrder.DEFAULT, + initial_state: Optional[Union[int, np.ndarray]] = None, + ) -> Iterator[cirq.StateVectorTrialResult]: + """Simulates the supplied Circuit. + + This method returns a result which allows access to the entire + wave function. In contrast to simulate, this allows for sweeping + over different parameter values. + + Avoid using this method with `use_gpu=True` in the simulator options; + when used with GPU this method must copy state from device to host memory + multiple times, which can be very slow. This issue is not present in + `simulate_expectation_values_sweep`. + + Args: + program: The circuit to simulate. + params: Parameters to run with the program. + qubit_order: Determines the canonical ordering of the qubits. This is + often used in specifying the initial state, i.e. the ordering of the + computational basis states. + initial_state: The initial state for the simulation. This can either + be an integer representing a pure state (e.g. 11010) or a numpy + array containing the full state vector. If none is provided, this + is assumed to be the all-zeros state. + + Returns: + List of SimulationTrialResults for this run, one for each + possible parameter resolver. + + Raises: + TypeError: if an invalid initial_state is provided. + """ + + for prs, state_vector, cirq_order in self._simulate_impl( + program, params, qubit_order, initial_state + ): final_state = cirq.StateVectorSimulationState( - initial_state=qsim_state.view(np.complex64), - qubits=cirq_order if not as_1d_state_vector else None, + initial_state=state_vector, qubits=cirq_order ) # create result for this parameter # TODO: We need to support measurements. diff --git a/qsimcirq_tests/qsimcirq_test.py b/qsimcirq_tests/qsimcirq_test.py index a9a56489..f9dc517f 100644 --- a/qsimcirq_tests/qsimcirq_test.py +++ b/qsimcirq_tests/qsimcirq_test.py @@ -2066,7 +2066,5 @@ def test_1d_representation(): c = cirq.Circuit(cirq.H.on_each(qs), cirq.X(qs[0]), cirq.Y(qs[1])) want = np.array([0.0 - 0.5j, 0.0 + 0.5j, 0.0 - 0.5j, 0.0 + 0.5j]) - res = qsim_sim.simulate(c, as_1d_state_vector=True) - np.testing.assert_allclose( - res.final_state_vector, np.array(want, dtype=np.complex64) - ) + res = qsim_sim.simulate_into_1d_array(c) + np.testing.assert_allclose(res, np.array(want, dtype=np.complex64)) From 12775097e455bb8a5008cde6e8dd2a6b5b0917d1 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Mon, 25 Sep 2023 12:01:32 -0700 Subject: [PATCH 16/39] update return type --- qsimcirq/qsim_simulator.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/qsimcirq/qsim_simulator.py b/qsimcirq/qsim_simulator.py index 405b9158..60044927 100644 --- a/qsimcirq/qsim_simulator.py +++ b/qsimcirq/qsim_simulator.py @@ -505,13 +505,19 @@ def simulate_into_1d_array( param_resolver: cirq.ParamResolverOrSimilarType = None, qubit_order: cirq.QubitOrderOrList = cirq.ops.QubitOrder.DEFAULT, initial_state: Any = None, - ) -> np.ndarray: - """Same as simulate() but returns the state vector as 1D np.ndarray.""" + ) -> Tuple[cirq.ParamResolver, np.ndarray, Sequence[int]]: + """Same as simulate() but returns raw simulation result without wrapping it. + + The returned result is not wrapped in a StateVectorTrialResult but can be used + to create a StateVectorTrialResult. + + Retruns: + A parameter resolver. + Final simulation state vector as a 1D array. + Qubit order. + """ params = cirq.study.ParamResolver(param_resolver) - _, state_vector, _ = next( - self._simulate_impl(program, params, qubit_order, initial_state) - ) - return state_vector + return next(self._simulate_impl(program, params, qubit_order, initial_state)) def simulate_sweep_iter( self, From 86279517072e9a2aa502ac7b4ded42ed86b4e085 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Mon, 25 Sep 2023 12:12:48 -0700 Subject: [PATCH 17/39] updae --- qsimcirq_tests/qsimcirq_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qsimcirq_tests/qsimcirq_test.py b/qsimcirq_tests/qsimcirq_test.py index f9dc517f..e0d19fae 100644 --- a/qsimcirq_tests/qsimcirq_test.py +++ b/qsimcirq_tests/qsimcirq_test.py @@ -2066,5 +2066,5 @@ def test_1d_representation(): c = cirq.Circuit(cirq.H.on_each(qs), cirq.X(qs[0]), cirq.Y(qs[1])) want = np.array([0.0 - 0.5j, 0.0 + 0.5j, 0.0 - 0.5j, 0.0 + 0.5j]) - res = qsim_sim.simulate_into_1d_array(c) + _, res, _ = qsim_sim.simulate_into_1d_array(c) np.testing.assert_allclose(res, np.array(want, dtype=np.complex64)) From 6c17d8d632a271dc21446dd19709588355c870f9 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Mon, 25 Sep 2023 13:48:16 -0700 Subject: [PATCH 18/39] docs --- qsimcirq/qsim_simulator.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/qsimcirq/qsim_simulator.py b/qsimcirq/qsim_simulator.py index 60044927..1bf0a4d0 100644 --- a/qsimcirq/qsim_simulator.py +++ b/qsimcirq/qsim_simulator.py @@ -511,10 +511,8 @@ def simulate_into_1d_array( The returned result is not wrapped in a StateVectorTrialResult but can be used to create a StateVectorTrialResult. - Retruns: - A parameter resolver. - Final simulation state vector as a 1D array. - Qubit order. + Returns: + Tuple of (param resolver, final state, qubit order) """ params = cirq.study.ParamResolver(param_resolver) return next(self._simulate_impl(program, params, qubit_order, initial_state)) @@ -549,7 +547,7 @@ def simulate_sweep_iter( is assumed to be the all-zeros state. Returns: - List of SimulationTrialResults for this run, one for each + Iterator over SimulationTrialResults for this run, one for each possible parameter resolver. Raises: From 7de58035799c497587a74ac0eb08a261a9f43131 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Mon, 2 Oct 2023 13:08:19 -0700 Subject: [PATCH 19/39] try to fix CI --- .bazelrc | 2 +- pybind_interface/Dockerfile | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.bazelrc b/.bazelrc index 16c8a51d..573fdb8f 100644 --- a/.bazelrc +++ b/.bazelrc @@ -16,7 +16,7 @@ build:asan --copt -fsanitize=address build:asan --linkopt -fsanitize=address # Memory sanitizer -build:msan --config=sanitizer +# build:msan --config=sanitizer build:msan --copt -fsanitize=leak build:msan --linkopt -fsanitize=leak diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index b826d197..eba2b8b6 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -4,6 +4,8 @@ FROM qsim # Install additional requirements RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip +RUN apt-get remove python-numpy + # The --force flag is used mainly so that the old numpy installation from pybind # gets replaced with the one cirq requires RUN pip3 install --prefer-binary cirq-core --force From 7bad066b728ea20b87cc5c3f41660543219cb0cf Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Mon, 2 Oct 2023 13:20:56 -0700 Subject: [PATCH 20/39] try to fix CI --- .bazelrc | 2 +- .github/workflows/bazeltest.yml | 5 +++++ pybind_interface/Dockerfile | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.bazelrc b/.bazelrc index 573fdb8f..16c8a51d 100644 --- a/.bazelrc +++ b/.bazelrc @@ -16,7 +16,7 @@ build:asan --copt -fsanitize=address build:asan --linkopt -fsanitize=address # Memory sanitizer -# build:msan --config=sanitizer +build:msan --config=sanitizer build:msan --copt -fsanitize=leak build:msan --linkopt -fsanitize=leak diff --git a/.github/workflows/bazeltest.yml b/.github/workflows/bazeltest.yml index 6eb6a261..d3fd30f2 100644 --- a/.github/workflows/bazeltest.yml +++ b/.github/workflows/bazeltest.yml @@ -60,6 +60,11 @@ jobs: - name: Install requirements run: | python3 -m pip install -r requirements.txt + # An LLVM update broke this test, fix per is https://bugs.llvm.org/show_bug.cgi?id=27310. + - name: Upgrade glibc to pypass + run: | + wget http://launchpadlibrarian.net/656214525/libc-bin_2.37-0ubuntu2_amd64.deb + sudo dpkg -i libc-bin_2.37-0ubuntu2_amd64.deb - name: Run C++ tests run: | bazel test --config=avx --config=openmp \ diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index eba2b8b6..dbbe8d03 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -4,7 +4,7 @@ FROM qsim # Install additional requirements RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip -RUN apt-get remove python-numpy +RUN apt-get remove python3-numpy --purge # The --force flag is used mainly so that the old numpy installation from pybind # gets replaced with the one cirq requires From fab46a28487dd53090869a48ab2e41e5f9ede3ff Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Mon, 2 Oct 2023 13:28:05 -0700 Subject: [PATCH 21/39] try to fix CI --- .github/workflows/bazeltest.yml | 7 +++---- pybind_interface/Dockerfile | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/bazeltest.yml b/.github/workflows/bazeltest.yml index d3fd30f2..e76f6780 100644 --- a/.github/workflows/bazeltest.yml +++ b/.github/workflows/bazeltest.yml @@ -54,17 +54,16 @@ jobs: - name: Checkout submodules run: git submodule update --init --recursive - name: Install Bazel on CI - run: | + run: | wget https://github.com/bazelbuild/bazel/releases/download/5.3.0/bazel_5.3.0-linux-x86_64.deb sudo dpkg -i bazel_5.3.0-linux-x86_64.deb - name: Install requirements run: | python3 -m pip install -r requirements.txt + - name: Upgrade libc # An LLVM update broke this test, fix per is https://bugs.llvm.org/show_bug.cgi?id=27310. - - name: Upgrade glibc to pypass run: | - wget http://launchpadlibrarian.net/656214525/libc-bin_2.37-0ubuntu2_amd64.deb - sudo dpkg -i libc-bin_2.37-0ubuntu2_amd64.deb + apt-get upgrade libc-bin=2.31-0ubuntu9.9 - name: Run C++ tests run: | bazel test --config=avx --config=openmp \ diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index dbbe8d03..26c161c6 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -4,7 +4,7 @@ FROM qsim # Install additional requirements RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip -RUN apt-get remove python3-numpy --purge +RUN apt-get remove -y python3-numpy --purge # The --force flag is used mainly so that the old numpy installation from pybind # gets replaced with the one cirq requires From b437035dac1a6da47e6997075dde4624dcfc58ba Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Mon, 2 Oct 2023 13:43:52 -0700 Subject: [PATCH 22/39] try to fix CI --- .github/workflows/bazeltest.yml | 2 +- pybind_interface/Dockerfile | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/bazeltest.yml b/.github/workflows/bazeltest.yml index e76f6780..4bd227cf 100644 --- a/.github/workflows/bazeltest.yml +++ b/.github/workflows/bazeltest.yml @@ -63,7 +63,7 @@ jobs: - name: Upgrade libc # An LLVM update broke this test, fix per is https://bugs.llvm.org/show_bug.cgi?id=27310. run: | - apt-get upgrade libc-bin=2.31-0ubuntu9.9 + sudo apt-get upgrade libc-bin=2.31-0ubuntu9.9 - name: Run C++ tests run: | bazel test --config=avx --config=openmp \ diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index 26c161c6..64bf236f 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -2,13 +2,14 @@ FROM qsim # Install additional requirements -RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip +RUN apt-get install -y python3-dev python3-pytest python3-pip -RUN apt-get remove -y python3-numpy --purge +# Install pybind11 +RUN pip3 install --prefer-binary pybind11 # The --force flag is used mainly so that the old numpy installation from pybind # gets replaced with the one cirq requires -RUN pip3 install --prefer-binary cirq-core --force +RUN pip3 install --prefer-binary cirq-core # Copy relevant files COPY ./pybind_interface/ /qsim/pybind_interface/ From 3b7c8783121ca0a6cb038823de43fb72c788ef63 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Mon, 2 Oct 2023 13:52:39 -0700 Subject: [PATCH 23/39] try to fix CI --- pybind_interface/Dockerfile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index 64bf236f..3f8d82a0 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -2,14 +2,13 @@ FROM qsim # Install additional requirements -RUN apt-get install -y python3-dev python3-pytest python3-pip +RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip -# Install pybind11 -RUN pip3 install --prefer-binary pybind11 +# Create virtual environment to avoid collision between system packages and cirq deps. +RUN python3 -m venv test_env +RUN source test_env/bin/activate -# The --force flag is used mainly so that the old numpy installation from pybind -# gets replaced with the one cirq requires -RUN pip3 install --prefer-binary cirq-core +RUN pip3 install --prefer-binary cirq-core # Copy relevant files COPY ./pybind_interface/ /qsim/pybind_interface/ From 30441c8fdbfff5ee1420ae6aa4853f9f64620575 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Mon, 2 Oct 2023 14:00:11 -0700 Subject: [PATCH 24/39] try to fix CI --- .github/workflows/bazeltest.yml | 2 +- pybind_interface/Dockerfile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/bazeltest.yml b/.github/workflows/bazeltest.yml index 4bd227cf..b893362d 100644 --- a/.github/workflows/bazeltest.yml +++ b/.github/workflows/bazeltest.yml @@ -54,7 +54,7 @@ jobs: - name: Checkout submodules run: git submodule update --init --recursive - name: Install Bazel on CI - run: | + run: | wget https://github.com/bazelbuild/bazel/releases/download/5.3.0/bazel_5.3.0-linux-x86_64.deb sudo dpkg -i bazel_5.3.0-linux-x86_64.deb - name: Install requirements diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index 3f8d82a0..293a6970 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -2,9 +2,9 @@ FROM qsim # Install additional requirements -RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip +RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip python3.11-venv -# Create virtual environment to avoid collision between system packages and cirq deps. +# Create a virtual environment to avoid collision between system packages and cirq deps. RUN python3 -m venv test_env RUN source test_env/bin/activate From fe0090aef9ba0c878d16338754f507380acde5e8 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Mon, 2 Oct 2023 14:04:49 -0700 Subject: [PATCH 25/39] try to fix CI --- pybind_interface/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index 293a6970..411d243f 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -6,7 +6,7 @@ RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip p # Create a virtual environment to avoid collision between system packages and cirq deps. RUN python3 -m venv test_env -RUN source test_env/bin/activate +RUN . ./test_env/bin/activate RUN pip3 install --prefer-binary cirq-core From c1dfbd170c3ca3abc23cc80856e0c4afecb5fe34 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Mon, 2 Oct 2023 14:08:25 -0700 Subject: [PATCH 26/39] try to fix CI --- pybind_interface/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index 411d243f..2cfd04b0 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -2,7 +2,7 @@ FROM qsim # Install additional requirements -RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip python3.11-venv +RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip python3-venv # Create a virtual environment to avoid collision between system packages and cirq deps. RUN python3 -m venv test_env From 72bf54504745a5f449bf375cc45802b5b7789283 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Mon, 2 Oct 2023 14:12:10 -0700 Subject: [PATCH 27/39] try to fix CI --- pybind_interface/Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index 2cfd04b0..c3393e73 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -6,7 +6,9 @@ RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip p # Create a virtual environment to avoid collision between system packages and cirq deps. RUN python3 -m venv test_env -RUN . ./test_env/bin/activate + +# Activate venv. +RUN . test_env/bin/activate RUN pip3 install --prefer-binary cirq-core From 2600dacd9958a1c52072ae16c00d3156b04b3292 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Mon, 2 Oct 2023 14:16:11 -0700 Subject: [PATCH 28/39] try to fix CI --- pybind_interface/Dockerfile | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index c3393e73..0b345fab 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -2,15 +2,10 @@ FROM qsim # Install additional requirements -RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip python3-venv +RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip -# Create a virtual environment to avoid collision between system packages and cirq deps. -RUN python3 -m venv test_env - -# Activate venv. -RUN . test_env/bin/activate - -RUN pip3 install --prefer-binary cirq-core +# break-system-packages flag to override system packages (e.g. numpy) with Cirq's deps. +RUN pip3 install --break-system-packages --force-reinstall --prefer-binary cirq-core # Copy relevant files COPY ./pybind_interface/ /qsim/pybind_interface/ From 393a7a3e42eb6c62c5c83af1f133614443fead10 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Mon, 2 Oct 2023 14:43:14 -0700 Subject: [PATCH 29/39] try to fix CI --- pybind_interface/Dockerfile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index 0b345fab..550bd76a 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -2,10 +2,16 @@ FROM qsim # Install additional requirements -RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip +RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip python3-venv + +# Create venv to avoid collision between system packages (e.g. numpy) and Cirq's deps. +RUN python3 -m venv test_env + +# Activate venv. +ENV PATH="test_env/bin:$PATH" # break-system-packages flag to override system packages (e.g. numpy) with Cirq's deps. -RUN pip3 install --break-system-packages --force-reinstall --prefer-binary cirq-core +RUN pip3 install --prefer-binary cirq-core # Copy relevant files COPY ./pybind_interface/ /qsim/pybind_interface/ From 510e4f0495f4c6b3ddf1328b7d9646a4b3e9ef1a Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Mon, 2 Oct 2023 15:17:24 -0700 Subject: [PATCH 30/39] try to fix CI --- pybind_interface/Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index 550bd76a..ffadd4a2 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -2,7 +2,7 @@ FROM qsim # Install additional requirements -RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip python3-venv +RUN apt-get install -y python3-dev python3-pybind11 python3-pip python3-venv # Create venv to avoid collision between system packages (e.g. numpy) and Cirq's deps. RUN python3 -m venv test_env @@ -23,5 +23,8 @@ WORKDIR /qsim/ # Build pybind code early to cache the results RUN make -C /qsim/ pybind +# Install pytest +RUN pip3 install pytest + # Compile and run qsim tests ENTRYPOINT make -C /qsim/ run-py-tests From 1bd151cd80ea0590c56314d9d9e557d2f21ce790 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Mon, 2 Oct 2023 15:38:21 -0700 Subject: [PATCH 31/39] fix docker file --- install/tests/Dockerfile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/install/tests/Dockerfile b/install/tests/Dockerfile index 9998e654..f51eb8f9 100644 --- a/install/tests/Dockerfile +++ b/install/tests/Dockerfile @@ -3,9 +3,15 @@ FROM debian # Install requirements RUN apt-get update -RUN apt-get install -y python3-dev python3-pip +RUN apt-get install -y python3-dev python3-pip python3-venv RUN apt-get install -y cmake git +# Create venv to avoid collision between system packages (e.g. numpy) and Cirq's deps. +RUN python3 -m venv test_env + +# Activate venv. +ENV PATH="test_env/bin:$PATH" + COPY ./ /qsim/ RUN pip3 install /qsim/ From e8df883b4fc1b553f55a2ad7d1925985922c0a39 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Tue, 3 Oct 2023 13:47:16 -0700 Subject: [PATCH 32/39] upgrade bazel version --- .bazelversion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bazelversion b/.bazelversion index 03f488b0..f9da12e1 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -5.3.0 +6.3.2 \ No newline at end of file From cb32edbf143cdd8f447da395f3a902ffd6672fc2 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Tue, 3 Oct 2023 13:59:08 -0700 Subject: [PATCH 33/39] restore bazel version --- .bazelversion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bazelversion b/.bazelversion index f9da12e1..03f488b0 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -6.3.2 \ No newline at end of file +5.3.0 From 5fff1a5a7f7fe0f00b439de3b5167214c739a0bc Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Thu, 5 Oct 2023 11:58:21 -0700 Subject: [PATCH 34/39] fix Docker and Bazel CIs --- .github/workflows/bazeltest.yml | 4 ++++ install/tests/Dockerfile | 8 +++++++- pybind_interface/Dockerfile | 16 ++++++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/.github/workflows/bazeltest.yml b/.github/workflows/bazeltest.yml index 6eb6a261..b893362d 100644 --- a/.github/workflows/bazeltest.yml +++ b/.github/workflows/bazeltest.yml @@ -60,6 +60,10 @@ jobs: - name: Install requirements run: | python3 -m pip install -r requirements.txt + - name: Upgrade libc + # An LLVM update broke this test, fix per is https://bugs.llvm.org/show_bug.cgi?id=27310. + run: | + sudo apt-get upgrade libc-bin=2.31-0ubuntu9.9 - name: Run C++ tests run: | bazel test --config=avx --config=openmp \ diff --git a/install/tests/Dockerfile b/install/tests/Dockerfile index 9998e654..f51eb8f9 100644 --- a/install/tests/Dockerfile +++ b/install/tests/Dockerfile @@ -3,9 +3,15 @@ FROM debian # Install requirements RUN apt-get update -RUN apt-get install -y python3-dev python3-pip +RUN apt-get install -y python3-dev python3-pip python3-venv RUN apt-get install -y cmake git +# Create venv to avoid collision between system packages (e.g. numpy) and Cirq's deps. +RUN python3 -m venv test_env + +# Activate venv. +ENV PATH="test_env/bin:$PATH" + COPY ./ /qsim/ RUN pip3 install /qsim/ diff --git a/pybind_interface/Dockerfile b/pybind_interface/Dockerfile index b826d197..ffadd4a2 100644 --- a/pybind_interface/Dockerfile +++ b/pybind_interface/Dockerfile @@ -2,11 +2,16 @@ FROM qsim # Install additional requirements -RUN apt-get install -y python3-dev python3-pybind11 python3-pytest python3-pip +RUN apt-get install -y python3-dev python3-pybind11 python3-pip python3-venv -# The --force flag is used mainly so that the old numpy installation from pybind -# gets replaced with the one cirq requires -RUN pip3 install --prefer-binary cirq-core --force +# Create venv to avoid collision between system packages (e.g. numpy) and Cirq's deps. +RUN python3 -m venv test_env + +# Activate venv. +ENV PATH="test_env/bin:$PATH" + +# break-system-packages flag to override system packages (e.g. numpy) with Cirq's deps. +RUN pip3 install --prefer-binary cirq-core # Copy relevant files COPY ./pybind_interface/ /qsim/pybind_interface/ @@ -18,5 +23,8 @@ WORKDIR /qsim/ # Build pybind code early to cache the results RUN make -C /qsim/ pybind +# Install pytest +RUN pip3 install pytest + # Compile and run qsim tests ENTRYPOINT make -C /qsim/ run-py-tests From dddae7e0c2f67b57a54d2f32b2e02302bf08dc3b Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Thu, 5 Oct 2023 14:07:19 -0700 Subject: [PATCH 35/39] run kokoro From c0630c1ca1113913d6ca77878daebc660e89bd4d Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Tue, 17 Oct 2023 15:11:13 -0700 Subject: [PATCH 36/39] run kokoro From 2da05480a220a53ded3a1d009397d2447cb43290 Mon Sep 17 00:00:00 2001 From: Noureldin Date: Wed, 18 Oct 2023 16:09:50 +0000 Subject: [PATCH 37/39] rerun CI From 343895c9df983fdf36a1365a300309f3c2f8b2cf Mon Sep 17 00:00:00 2001 From: Noureldin Date: Wed, 18 Oct 2023 16:17:55 +0000 Subject: [PATCH 38/39] replace upgrade with satisfy --- .github/workflows/bazeltest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bazeltest.yml b/.github/workflows/bazeltest.yml index b893362d..f1d54fdf 100644 --- a/.github/workflows/bazeltest.yml +++ b/.github/workflows/bazeltest.yml @@ -63,7 +63,7 @@ jobs: - name: Upgrade libc # An LLVM update broke this test, fix per is https://bugs.llvm.org/show_bug.cgi?id=27310. run: | - sudo apt-get upgrade libc-bin=2.31-0ubuntu9.9 + sudo apt-get satisfy "libc-bin (>= 2.31-0ubuntu9.9)" - name: Run C++ tests run: | bazel test --config=avx --config=openmp \ From a1025aa2305d3ab9dec42a14a975a556b48d1148 Mon Sep 17 00:00:00 2001 From: Noureldin Date: Wed, 18 Oct 2023 16:25:50 +0000 Subject: [PATCH 39/39] upgrade libc to latests --- .github/workflows/bazeltest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bazeltest.yml b/.github/workflows/bazeltest.yml index f1d54fdf..bebbd613 100644 --- a/.github/workflows/bazeltest.yml +++ b/.github/workflows/bazeltest.yml @@ -63,7 +63,7 @@ jobs: - name: Upgrade libc # An LLVM update broke this test, fix per is https://bugs.llvm.org/show_bug.cgi?id=27310. run: | - sudo apt-get satisfy "libc-bin (>= 2.31-0ubuntu9.9)" + sudo apt-get upgrade libc-bin - name: Run C++ tests run: | bazel test --config=avx --config=openmp \