Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
doichanj committed May 28, 2024
2 parents 65bfb37 + 0320a14 commit 108ffaa
Show file tree
Hide file tree
Showing 26 changed files with 303 additions and 236 deletions.
31 changes: 16 additions & 15 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
- name: Build wheels
env:
AER_CMAKE_OPENMP_BUILD: 1
CIBW_SKIP: "pp* cp38-macosx_arm64 cp39-macosx_arm64"
run: python -m cibuildwheel --output-dir wheelhouse
- uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -133,30 +132,31 @@ jobs:
- name: Maximize build space
uses: easimon/maximize-build-space@master
with:
root-reserve-mb: 30000
root-reserve-mb: 32000
swap-size-mb: 1024
remove-dotnet: 'true'
remove-android: 'true'
remove-haskell: 'true'
remove-codeql: 'true'
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.10'
- name: Install cibuildwheel
run: |
python -m pip install cibuildwheel==2.17.0
python -m pip install cibuildwheel==2.16.2
- name: Build wheels
env:
CIBW_BEFORE_ALL: "yum install -y yum-utils wget && wget -q https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda-repo-rhel7-11-8-local-11.8.0_520.61.05-1.x86_64.rpm && rpm -i cuda-repo-rhel7-11-8-local-11.8.0_520.61.05-1.x86_64.rpm && yum clean all && yum -y install cuda && yum -y install openblas-devel && yum-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo && yum clean all"
CIBW_BEFORE_BUILD : "pip cache purge && pip install nvidia-cuda-runtime-cu11 nvidia-cublas-cu11 nvidia-cusolver-cu11 nvidia-cusparse-cu11 cuquantum-cu11"
CIBW_BEFORE_ALL: "pip cache purge && yum install -y yum-utils wget && wget -q https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda-repo-rhel7-11-8-local-11.8.0_520.61.05-1.x86_64.rpm && rpm -i cuda-repo-rhel7-11-8-local-11.8.0_520.61.05-1.x86_64.rpm && yum clean all && yum -y install cuda && yum -y install openblas-devel && yum-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo && yum clean all"
CIBW_BEFORE_BUILD : "pip install nvidia-cuda-runtime-cu11 nvidia-cublas-cu11 nvidia-cusolver-cu11 nvidia-cusparse-cu11 cuquantum-cu11"
CIBW_SKIP: "*-manylinux_i686 pp* cp36* cp37* *musllinux*"
CIBW_TEST_SKIP: "*"
CIBW_ENVIRONMENT: QISKIT_AER_PACKAGE_NAME=qiskit-aer-gpu-cu11 QISKIT_AER_CUDA_MAJOR=11 CMAKE_VERBOSE_MAKEFILE=true AER_THRUST_BACKEND=CUDA CUDACXX=/usr/local/cuda/bin/nvcc AER_CUDA_ARCH="7.0 7.2 7.5 8.0 8.6 8.7" AER_PYTHON_CUDA_ROOT=/opt/_internal AER_CIBUILD=true
CIBW_REPAIR_WHEEL_COMMAND: 'auditwheel repair --exclude libcudart.so.11.0 --exclude libcustatevec.so.1 --exclude libcutensornet.so.2 --exclude libcutensor.so.1 --exclude libcutensorMg.so.1 --exclude libcusolver.so.11 --exclude libcusolverMg.so.11 --exclude libcusparse.so.11 --exclude libcublas.so.11 --exclude libcublasLt.so.11 -w {dest_dir} {wheel}'
run: |
python -m cibuildwheel --output-dir wheelhouse
- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl
- name: Publish package distributions to PyPI
Expand All @@ -176,30 +176,31 @@ jobs:
- name: Maximize build space
uses: easimon/maximize-build-space@master
with:
root-reserve-mb: 30000
root-reserve-mb: 32000
swap-size-mb: 1024
remove-dotnet: 'true'
remove-android: 'true'
remove-haskell: 'true'
remove-codeql: 'true'
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.10'
- name: Install cibuildwheel
run: |
python -m pip install cibuildwheel==2.17.0
python -m pip install cibuildwheel==2.16.2
- name: Build wheels
env:
CIBW_BEFORE_ALL: "yum install -y yum-utils wget && wget -q https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda-repo-rhel7-12-4-local-12.4.0_550.54.14-1.x86_64.rpm && rpm -i cuda-repo-rhel7-12-4-local-12.4.0_550.54.14-1.x86_64.rpm && yum clean all && yum -y install nvidia-driver-latest-dkms && yum -y install cuda-toolkit-12-4 && yum -y install openblas-devel && yum clean all"
CIBW_BEFORE_BUILD : "pip cache purge && pip install nvidia-cuda-runtime-cu12 nvidia-nvjitlink-cu12 nvidia-cublas-cu12 nvidia-cusolver-cu12 nvidia-cusparse-cu12 cuquantum-cu12"
CIBW_BEFORE_ALL: "pip cache purge && yum install -y yum-utils wget && wget -q https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda-repo-rhel7-12-4-local-12.4.0_550.54.14-1.x86_64.rpm && rpm -i cuda-repo-rhel7-12-4-local-12.4.0_550.54.14-1.x86_64.rpm && yum clean all && yum -y install nvidia-driver-latest-dkms && yum -y install cuda-toolkit-12-4 && yum -y install openblas-devel && yum clean all"
CIBW_BEFORE_BUILD : "pip install nvidia-cuda-runtime-cu12 nvidia-nvjitlink-cu12 nvidia-cublas-cu12 nvidia-cusolver-cu12 nvidia-cusparse-cu12 cuquantum-cu12"
CIBW_SKIP: "*-manylinux_i686 pp* cp36* cp37* *musllinux*"
CIBW_TEST_SKIP: "*"
CIBW_ENVIRONMENT: QISKIT_AER_PACKAGE_NAME=qiskit-aer-gpu QISKIT_AER_CUDA_MAJOR=12 CMAKE_VERBOSE_MAKEFILE=true AER_THRUST_BACKEND=CUDA CUDACXX=/usr/local/cuda/bin/nvcc AER_CUDA_ARCH="7.0 7.2 7.5 8.0 8.6 8.7 9.0" AER_PYTHON_CUDA_ROOT=/opt/_internal AER_CIBUILD=true
CIBW_REPAIR_WHEEL_COMMAND: 'auditwheel repair --exclude libcudart.so.12 --exclude libcustatevec.so.1 --exclude libcutensornet.so.2 --exclude libcutensor.so.1 --exclude libcutensorMg.so.1 --exclude libcusolver.so.11 --exclude libcusolverMg.so.11 --exclude libcusolver.so.12 --exclude libcusolverMg.so.12 --exclude libcusparse.so.12 --exclude libcublas.so.12 --exclude libcublasLt.so.12 --exclude libnvJitLink.so.12 -w {dest_dir} {wheel}'
run: |
python -m cibuildwheel --output-dir wheelhouse
- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl
- name: Publish package distributions to PyPI
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ provider = QiskitRuntimeService(channel='ibm_quantum', token="set your own token
backend = provider.get_backend("ibm_kyoto")

# create sampler from the actual backend
sampler.from_backend(backend)
sampler = SamplerV2.from_backend(backend)

# run a sampler job on the parameterized circuits with noise model of the actual hardware
job3 = sampler.run([(pqc, theta1), (pqc2, theta2)])
bell_t = transpile(bell, AerSimulator(basis_gates=["ecr", "id", "rz", "sx"]), optimization_level=0)
job3 = sampler.run([bell_t], shots=128)
job_result = job3.result()
print(f"Parameterized for Bell circuit w/noise: {job_result[0].data.meas.get_counts()}")

print(f"counts for Bell circuit w/noise: {job_result[0].data.meas.get_counts()}")
```

## Contribution Guidelines
Expand Down
1 change: 1 addition & 0 deletions qiskit_aer/backends/aer_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ def _assemble_op(
"mcu", "mcu1", "mcu2", "mcu3", "mcx", "mcx_gray", "mcy", "mcz", "p", "r",
"rx", "rxx", "ry", "ryy", "rz", "rzx", "rzz", "s", "sdg", "swap", "sx", "sxdg",
"t", "tdg", "u", "x", "y", "z", "u1", "u2", "u3", "cu", "cu1", "cu2", "cu3",
"crx", "cry", "crz",
}:
aer_circ.gate(name, qubits, params, [], conditional_reg, aer_cond_expr,
label if label else name)
Expand Down
12 changes: 10 additions & 2 deletions qiskit_aer/backends/backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
"rzx",
"ccx",
"ccz",
"crx",
"cry",
"crz",
"cswap",
"mcx",
"mcy",
Expand Down Expand Up @@ -218,8 +221,6 @@
"delay",
"pauli",
"ecr",
"rx",
"ry",
"rz",
]
),
Expand Down Expand Up @@ -247,6 +248,7 @@
"delay",
"pauli",
"ecr",
"rz",
]
),
"unitary": sorted(
Expand Down Expand Up @@ -288,6 +290,9 @@
"ccx",
"ccz",
"cswap",
"crx",
"cry",
"crz",
"mcx",
"mcy",
"mcz",
Expand Down Expand Up @@ -389,6 +394,9 @@
"ccx",
"ccz",
"cswap",
"crx",
"cry",
"crz",
"mcx",
"mcy",
"mcz",
Expand Down
14 changes: 8 additions & 6 deletions qiskit_aer/primitives/estimator_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ def __init__(
the runtime options (``run_options``).
"""
self._options = Options(**options) if options else Options()
method = "density_matrix" if "noise_model" in self.options.backend_options else "automatic"
self._backend = AerSimulator(method=method, **self.options.backend_options)

def from_backend(self, backend, **options):
"""use external backend"""
self._backend.from_backend(backend, **options)
self._backend = AerSimulator(**self.options.backend_options)

@classmethod
def from_backend(cls, backend, **options):
"""make new sampler that uses external backend"""
estimator = cls(**options)
estimator._backend = AerSimulator.from_backend(backend)
return estimator

@property
def options(self) -> Options:
Expand Down
13 changes: 9 additions & 4 deletions qiskit_aer/primitives/sampler_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,12 @@ def __init__(
self._options = Options(**options) if options else Options()
self._backend = AerSimulator(**self.options.backend_options)

def from_backend(self, backend, **options):
"""use external backend"""
self._backend.from_backend(backend, **options)
@classmethod
def from_backend(cls, backend, **options):
"""make new sampler that uses external backend"""
sampler = cls(**options)
sampler._backend = AerSimulator.from_backend(backend)
return sampler

@property
def default_shots(self) -> int:
Expand Down Expand Up @@ -156,6 +159,7 @@ def _run_pub(self, pub: SamplerPub) -> PubResult:
for item in meas_info
}

metadata = {"shots": pub.shots}
if qargs:
circuit.measure_all()
result = self._backend.run(
Expand All @@ -181,6 +185,7 @@ def _run_pub(self, pub: SamplerPub) -> PubResult:
for item in meas_info:
ary = _samples_to_packed_array(samples_array, item.num_bits, item.qreg_indices)
arrays[item.creg_name][index] = ary
metadata["simulator_metadata"] = result.metadata
else:
for index in np.ndenumerate(parameter_values.shape):
samples = [""] * pub.shots
Expand All @@ -199,7 +204,7 @@ def _run_pub(self, pub: SamplerPub) -> PubResult:
item.creg_name: BitArray(arrays[item.creg_name], item.num_bits) for item in meas_info
}
data_bin = data_bin_cls(**meas)
return PubResult(data_bin, metadata={"shots": pub.shots})
return PubResult(data_bin, metadata=metadata)


def _preprocess_circuit(circuit: QuantumCircuit):
Expand Down
8 changes: 8 additions & 0 deletions releasenotes/notes/add_rotation_support-c0ef8155a761e560.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
features:
- |
Add `rz` gate with n*pi/2 cases to `extended_stabilizer` method
as well as `stabilizer` method.
Add `crx`, `cry` and `crz` gates to `statevector` and `tensor_netowork`
methods.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
This fix adds `simulator_metadata` in the `metadata` of `PubResults`
for SamplerV2 primitive as similar to EstimatorV2 primitive
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
The option `cuStateVec_enable=True` was not set correctly.
This fix set this option to statevector, unitary and density_matrix
simulator states classes before allocating their memory
5 changes: 5 additions & 0 deletions releasenotes/notes/fix_primitiveV2_init-afe7b331ddbef538.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
Fixed init function of EstimatorV2 and SamplerV2 to set `method` in
its option property if there is no `method` in input parameter
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
Fix of deterministic measure of stabilizer and change of OpenMP
parallelization of loop
44 changes: 23 additions & 21 deletions src/framework/operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,27 +724,29 @@ inline void check_duplicate_qubits(const Op &op) {
}

inline void check_gate_params(const Op &op) {
const stringmap_t<std::tuple<int_t, int_t>> param_tables(
{{"u1", {1, 1}}, {"u2", {1, 2}}, {"u3", {1, 3}},
{"u", {1, 3}}, {"U", {1, 3}}, {"CX", {2, 0}},
{"cx", {2, 0}}, {"cz", {2, 0}}, {"cy", {2, 0}},
{"cp", {2, 1}}, {"cu1", {2, 1}}, {"cu2", {2, 2}},
{"cu3", {2, 3}}, {"swap", {2, 0}}, {"id", {0, 0}},
{"p", {1, 1}}, {"x", {1, 0}}, {"y", {1, 0}},
{"z", {1, 0}}, {"h", {1, 0}}, {"s", {1, 0}},
{"sdg", {1, 0}}, {"t", {1, 0}}, {"tdg", {1, 0}},
{"r", {1, 2}}, {"rx", {1, 1}}, {"ry", {1, 1}},
{"rz", {1, 1}}, {"rxx", {2, 1}}, {"ryy", {2, 1}},
{"rzz", {2, 1}}, {"rzx", {2, 1}}, {"ccx", {3, 0}},
{"ccz", {3, 0}}, {"cswap", {3, 0}}, {"mcx", {1, 0}},
{"mcy", {1, 0}}, {"mcz", {1, 0}}, {"mcu1", {1, 1}},
{"mcu2", {1, 2}}, {"mcu3", {1, 3}}, {"mcswap", {2, 0}},
{"mcphase", {1, 1}}, {"mcr", {1, 1}}, {"mcrx", {1, 1}},
{"mcry", {1, 1}}, {"mcrz", {1, 1}}, {"sx", {1, 0}},
{"sxdg", {1, 0}}, {"csx", {2, 0}}, {"mcsx", {1, 0}},
{"csxdg", {2, 0}}, {"mcsxdg", {1, 0}}, {"delay", {1, 0}},
{"pauli", {1, 0}}, {"mcx_gray", {1, 0}}, {"cu", {2, 4}},
{"mcu", {1, 4}}, {"mcp", {1, 1}}, {"ecr", {2, 0}}});
const stringmap_t<std::tuple<int_t, int_t>> param_tables({
{"u1", {1, 1}}, {"u2", {1, 2}}, {"u3", {1, 3}},
{"u", {1, 3}}, {"U", {1, 3}}, {"CX", {2, 0}},
{"cx", {2, 0}}, {"cz", {2, 0}}, {"cy", {2, 0}},
{"cp", {2, 1}}, {"cu1", {2, 1}}, {"cu2", {2, 2}},
{"cu3", {2, 3}}, {"swap", {2, 0}}, {"id", {0, 0}},
{"p", {1, 1}}, {"x", {1, 0}}, {"y", {1, 0}},
{"z", {1, 0}}, {"h", {1, 0}}, {"s", {1, 0}},
{"sdg", {1, 0}}, {"t", {1, 0}}, {"tdg", {1, 0}},
{"r", {1, 2}}, {"rx", {1, 1}}, {"ry", {1, 1}},
{"rz", {1, 1}}, {"rxx", {2, 1}}, {"ryy", {2, 1}},
{"rzz", {2, 1}}, {"rzx", {2, 1}}, {"ccx", {3, 0}},
{"ccz", {3, 0}}, {"cswap", {3, 0}}, {"mcx", {1, 0}},
{"mcy", {1, 0}}, {"mcz", {1, 0}}, {"mcu1", {1, 1}},
{"mcu2", {1, 2}}, {"mcu3", {1, 3}}, {"mcswap", {2, 0}},
{"mcphase", {1, 1}}, {"mcr", {1, 1}}, {"mcrx", {1, 1}},
{"mcry", {1, 1}}, {"mcrz", {1, 1}}, {"sx", {1, 0}},
{"sxdg", {1, 0}}, {"csx", {2, 0}}, {"mcsx", {1, 0}},
{"csxdg", {2, 0}}, {"mcsxdg", {1, 0}}, {"delay", {1, 0}},
{"pauli", {1, 0}}, {"mcx_gray", {1, 0}}, {"cu", {2, 4}},
{"mcu", {1, 4}}, {"mcp", {1, 1}}, {"ecr", {2, 0}},
{"crx", {1, 1}}, {"cry", {1, 1}}, {"crz", {1, 1}},
});

auto it = param_tables.find(op.name);
if (it == param_tables.end()) {
Expand Down
3 changes: 3 additions & 0 deletions src/simulators/density_matrix/densitymatrix_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ bool State<densmat_t>::allocate(uint_t num_qubits, uint_t block_bits,
BaseState::qreg_.set_max_sampling_shots(BaseState::max_sampling_shots_);

BaseState::qreg_.set_target_gpus(BaseState::target_gpus_);
#ifdef AER_CUSTATEVEC
BaseState::qreg_.cuStateVec_enable(BaseState::cuStateVec_enable_);
#endif
BaseState::qreg_.chunk_setup(block_bits * 2, block_bits * 2, 0, 1);

return true;
Expand Down
37 changes: 36 additions & 1 deletion src/simulators/extended_stabilizer/extended_stabilizer_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const Operations::OpSet StateOpSet(
// Gates
{"CX", "u0", "u1", "p", "cx", "cz", "swap", "id",
"x", "y", "z", "h", "s", "sdg", "sx", "sxdg",
"t", "tdg", "ccx", "ccz", "delay", "pauli", "ecr"});
"t", "tdg", "ccx", "ccz", "delay", "pauli", "ecr", "rz"});

using chpauli_t = CHSimulator::pauli_t;
using chstate_t = CHSimulator::Runner;
Expand Down Expand Up @@ -89,6 +89,9 @@ class State : public QuantumState::State<chstate_t> {
std::vector<SampleVector> sample_measure(const reg_t &qubits, uint_t shots,
RngEngine &rng) override;

bool
validate_parameters(const std::vector<Operations::Op> &ops) const override;

protected:
// Alongside the sample measure optimisaiton, we can parallelise
// circuit applicaiton over the states. This reduces the threading overhead
Expand Down Expand Up @@ -211,6 +214,7 @@ const stringmap_t<Gates> State::gateset_({
{"sxdg", Gates::sxdg}, // Inverse sqrt(X) gate
{"t", Gates::t}, // T-gate (sqrt(S))
{"tdg", Gates::tdg}, // Conjguate-transpose of T gate
{"rz", Gates::rz}, // RZ gate (only support k * pi/2 cases)
// Waltz Gates
{"u0", Gates::u0}, // idle gate in multiples of X90
{"u1", Gates::u1}, // zero-X90 pulse waltz gate
Expand Down Expand Up @@ -337,6 +341,23 @@ bool State::check_measurement_opt(InputIterator first,
return true;
}

bool State::validate_parameters(const std::vector<Operations::Op> &ops) const {
for (uint_t i = 0; i < ops.size(); i++) {
if (ops[i].type == OpType::gate) {
// check parameter of RZ gates
if (ops[i].name == "rz") {
double pi2 = std::real(ops[i].params[0]) * 2.0 / M_PI;
double pi2_int = (double)std::round(pi2);

if (!AER::Linalg::almost_equal(pi2, pi2_int)) {
return false;
}
}
}
}
return true;
}

//-------------------------------------------------------------------------
// Implementation: Operations
//-------------------------------------------------------------------------
Expand Down Expand Up @@ -634,6 +655,7 @@ void State::apply_gate(const Operations::Op &op, RngEngine &rng) {
}

void State::apply_gate(const Operations::Op &op, RngEngine &rng, uint_t rank) {
int_t pi2;
auto it = gateset_.find(op.name);
if (it == gateset_.end()) {
throw std::invalid_argument("CH::State: Invalid gate operation \'" +
Expand Down Expand Up @@ -703,6 +725,19 @@ void State::apply_gate(const Operations::Op &op, RngEngine &rng, uint_t rank) {
BaseState::qreg_.apply_cx(op.qubits[0], op.qubits[1], rank);
BaseState::qreg_.apply_x(op.qubits[0], rank);
break;
case Gates::rz:
pi2 = (int_t)std::round(std::real(op.params[0]) * 2.0 / M_PI) & 3;
if (pi2 == 1) {
// S
BaseState::qreg_.apply_s(op.qubits[0], rank);
} else if (pi2 == 2) {
// Z
BaseState::qreg_.apply_z(op.qubits[0], rank);
} else if (pi2 == 3) {
// Sdg
BaseState::qreg_.apply_sdag(op.qubits[0], rank);
}
break;
default: // u0 or Identity
break;
}
Expand Down
Loading

0 comments on commit 108ffaa

Please sign in to comment.